Created
December 18, 2019 23:38
-
-
Save Andrious/216562beef8843b6bd68fc0926debd22 to your computer and use it in GitHub Desktop.
Better Bottom Bar Example #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import './NavBottomBar.dart'; | |
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
/// This Widget is the main application widget. | |
class MyApp extends StatelessWidget { | |
static const String _title = 'Flutter Code Sample'; | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: _title, | |
home: MyStatefulWidget(), | |
); | |
} | |
} | |
class MyStatefulWidget extends StatefulWidget { | |
MyStatefulWidget({Key key}) : super(key: key); | |
@override | |
_MyStatefulWidgetState createState() => _MyStatefulWidgetState(); | |
} | |
class _MyStatefulWidgetState extends State<MyStatefulWidget> { | |
int _selectedIndex = 0; | |
static const TextStyle optionStyle = | |
TextStyle(fontSize: 30, fontWeight: FontWeight.bold); | |
static const List<Widget> _widgetOptions = <Widget>[ | |
Text( | |
'Index 0: Home', | |
style: optionStyle, | |
), | |
Text( | |
'Index 1: Business', | |
style: optionStyle, | |
), | |
Text( | |
'Index 2: School', | |
style: optionStyle, | |
), | |
]; | |
Example bottom; | |
@override | |
void initState() { | |
super.initState(); | |
bottom = Example(); | |
bottom.onTap = (int index) { | |
setState(() { | |
_selectedIndex = index; | |
}); | |
}; | |
bottom.selectedItemColor = Colors.amber[800]; | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: const Text('BottomNavigationBar Sample'), | |
), | |
body: Center( | |
child: GestureDetector( | |
onTap: () { | |
// bottom.hide = !bottom.hide; | |
bottom.selectedItemColor = | |
bottom.selectedItemColor == Colors.amber[800] | |
? Colors.red[900] | |
: Colors.amber[800]; | |
setState(() {}); | |
}, | |
child: _widgetOptions.elementAt(_selectedIndex)), | |
), | |
bottomNavigationBar: bottom.show(currentIndex: _selectedIndex), | |
); | |
} | |
} | |
class Example extends NavBottomBar { | |
get items => const <BottomNavigationBarItem>[ | |
BottomNavigationBarItem( | |
icon: Icon(Icons.home), | |
title: Text('Home'), | |
), | |
BottomNavigationBarItem( | |
icon: Icon(Icons.business), | |
title: Text('Business'), | |
), | |
BottomNavigationBarItem( | |
icon: Icon(Icons.school), | |
title: Text('School'), | |
), | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment