-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into ui-change-port-and-protocol
- Loading branch information
Showing
5 changed files
with
139 additions
and
11 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
/// Widget for navigating between different screens | ||
/// | ||
/// This widget displays the different sceeens in tabs along a bar at | ||
/// the bottom of the screen. When clicked, each tab will navigate to | ||
/// the corresponding screen. | ||
class NavBar extends StatelessWidget { | ||
/// @brief Constructs a NavBar widget. | ||
const NavBar({Key? key}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return BottomNavigationBar( | ||
onTap: (int index) { | ||
switch (index) { | ||
case 0: | ||
Navigator.pushReplacementNamed(context, '/'); | ||
break; | ||
case 1: | ||
Navigator.popAndPushNamed(context, '/logs'); | ||
break; | ||
case 2: | ||
Navigator.popAndPushNamed(context, '/camera'); | ||
break; | ||
default: | ||
Navigator.popAndPushNamed(context, '/sitl'); | ||
break; | ||
} | ||
}, | ||
items: const <BottomNavigationBarItem>[ | ||
BottomNavigationBarItem( | ||
icon: Icon(Icons.home_sharp), | ||
label: 'Home', | ||
), | ||
BottomNavigationBarItem( | ||
icon: Icon(Icons.format_list_bulleted_sharp), | ||
label: 'Logs', | ||
), | ||
BottomNavigationBarItem( | ||
icon: Icon(Icons.camera_sharp), | ||
label: 'Camera', | ||
), | ||
BottomNavigationBarItem( | ||
icon: Icon(Icons.check_box_sharp), | ||
label: 'SITL', | ||
) | ||
], | ||
unselectedItemColor: Colors.black, | ||
selectedItemColor: Colors.black, | ||
showUnselectedLabels: true, | ||
); | ||
} | ||
} | ||
|
||
/// A placeholder screen with title text and the navigation bar | ||
/// | ||
/// This widget is a placeholder screen containing a title, | ||
/// placeholder body, and the navigation bar. | ||
class PlaceholderScreen extends StatelessWidget { | ||
/// @brief Constructs a PlaceholderScreen widget. | ||
const PlaceholderScreen({Key? key, required this.title}) : super(key: key); | ||
|
||
final String title; | ||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text(title), | ||
), | ||
body: const Placeholder(), | ||
bottomNavigationBar: const NavBar()); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:imacs/widgets/nav_bar_widget.dart'; | ||
|
||
void main() { | ||
group('Navbar widget', () { | ||
testWidgets('NavBar navigates to correct route', | ||
(WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
MaterialApp( | ||
initialRoute: '/', | ||
routes: { | ||
'/': (context) => const Scaffold( | ||
body: Text('Home Page'), bottomNavigationBar: NavBar()), | ||
'/logs': (context) => const Scaffold( | ||
body: Text('Logs Page'), bottomNavigationBar: NavBar()), | ||
'/camera': (context) => const Scaffold( | ||
body: Text('Camera Page'), bottomNavigationBar: NavBar()), | ||
'/sitl': (context) => const Scaffold( | ||
body: Text('SITL Page'), bottomNavigationBar: NavBar()), | ||
}, | ||
), | ||
); | ||
|
||
expect(find.byType(BottomNavigationBar), findsOneWidget); | ||
|
||
// Test home icon tap | ||
await tester.tap(find.text('Home')); | ||
await tester.pumpAndSettle(); | ||
expect(find.text('Home Page'), findsOneWidget); | ||
|
||
await tester.tap(find.text('Logs')); | ||
await tester.pumpAndSettle(); | ||
expect(find.text('Logs Page'), findsOneWidget); | ||
|
||
await tester.tap(find.text('Camera')); | ||
await tester.pumpAndSettle(); | ||
expect(find.text('Camera Page'), findsOneWidget); | ||
|
||
await tester.tap(find.text('SITL')); | ||
await tester.pumpAndSettle(); | ||
expect(find.text('SITL Page'), findsOneWidget); | ||
}); | ||
}); | ||
} |