-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Created navigation bar #30
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class NavBar extends StatefulWidget { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add some documentation in the form of comments, check the other widgets for examples |
||
const NavBar({super.key}); | ||
|
||
@override | ||
NavBarState createState() => NavBarState(); | ||
} | ||
|
||
class NavBarState extends State<NavBar> { | ||
int _index = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If your going with this implementation, I would actually recommend getting rid of the router and replacing it with a list or map of screen widgets. You'd essentially be replacing the router and making a single screen app with interchangeable screens. Since we are using a router there is some weirdness with the index. |
||
|
||
void _onItemClicked(int index) { | ||
setState(() { | ||
_index = index; | ||
}); | ||
|
||
switch (index) { | ||
case 0: | ||
Navigator.of(context).popUntil((route) => route.isFirst); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really a fan of routing like this, use |
||
break; | ||
case 1: | ||
Navigator.pushNamed(context, '/logs'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
break; | ||
case 2: | ||
Navigator.pushNamed(context, '/camera'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
break; | ||
default: | ||
Navigator.pushNamed(context, '/sitl'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
break; | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return BottomNavigationBar( | ||
currentIndex: _index, | ||
onTap: _onItemClicked, | ||
items: const <BottomNavigationBarItem>[ | ||
BottomNavigationBarItem( | ||
icon: Icon(Icons.home), | ||
label: 'Home', | ||
backgroundColor: Colors.black, | ||
), | ||
BottomNavigationBarItem( | ||
icon: Icon(Icons.format_list_bulleted_sharp), | ||
label: 'Logs', | ||
backgroundColor: Colors.black, | ||
), | ||
BottomNavigationBarItem( | ||
icon: Icon(Icons.camera_sharp), | ||
label: 'Camera', | ||
backgroundColor: Colors.black, | ||
), | ||
BottomNavigationBarItem( | ||
icon: Icon(Icons.check_box_sharp), | ||
label: 'SITL', | ||
backgroundColor: Colors.black, | ||
) | ||
], | ||
showUnselectedLabels: true, | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not exactly a requirement, but you can make the placeholders look a lot nicer