Flutter Webって書いたけど別にスマホでも動く
こういうやつ
ソース
概要としては
・bottomNavigationBarに普通に3つ並べて真ん中を透明ボタンにする
・floatingActionButtonの領域を広げてFloatingActionButtonを好きな位置に貼る
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _selectedIndex = 0;
static const TextStyle optionStyle =
TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
static const List<Widget> _widgetOptions = <Widget>[
Text(
'Index 0: Business',
style: optionStyle,
),
Text(
'Index 1: Home',
style: optionStyle,
),
Text(
'Index 2: School',
style: optionStyle,
),
];
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: SafeArea(
child: Container(
color: Colors.white,
child: Center(
child: _widgetOptions.elementAt(_selectedIndex),
),
),
),
bottomNavigationBar: BottomNavigationBar(
items: [
BottomNavigationBarItem(
icon: Icon(Icons.business),
title: Text('Business'),
),
BottomNavigationBarItem(
icon: Opacity(
opacity: 0,
child: Icon(Icons.home),
),
title: Text(""),
),
BottomNavigationBarItem(
icon: Icon(Icons.school),
title: Text('School'),
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.amber[800],
onTap: _onItemTapped,
),
floatingActionButton: Container(
width: 90,
height: 100,
child: FittedBox(
alignment: Alignment.topCenter,
child: FloatingActionButton(
elevation: 0,
hoverElevation: 0,
highlightElevation: 0,
child: Icon(Icons.home),
backgroundColor: Colors.redAccent,
onPressed: () {
_onItemTapped(1);
},
),
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
);
}
}