Skip to content
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

Merged
merged 8 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 7 additions & 22 deletions flutter_app/.metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This file should be version controlled and should not be manually edited.

version:
revision: "761747bfc538b5af34aa0d3fac380f1bc331ec49"
revision: "2663184aa79047d0a33a14a3b607954f8fdd8730"
channel: "stable"

project_type: app
Expand All @@ -13,26 +13,11 @@ project_type: app
migration:
platforms:
- platform: root
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
- platform: android
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
- platform: ios
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
- platform: linux
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
- platform: macos
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
- platform: web
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
- platform: windows
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730

# User provided section

Expand All @@ -41,5 +26,5 @@ migration:
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- "lib/main.dart"
- "ios/Runner.xcodeproj/project.pbxproj"
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
7 changes: 7 additions & 0 deletions flutter_app/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:imacs/screens/home_screen.dart';
import 'package:imacs/widgets/nav_bar_widget.dart';

void main() async {
runApp(const App());
Expand All @@ -17,6 +18,12 @@ class App extends StatelessWidget {
),
routes: {
'/': (BuildContext context) => HomePage(title: 'WARG IMACS'),
'/logs': (BuildContext context) =>
const PlaceholderScreen(title: 'Logs'),
'/camera': (BuildContext context) =>
const PlaceholderScreen(title: 'Camera'),
'/sitl': (BuildContext context) =>
const PlaceholderScreen(title: 'SITL'),
},
);
}
Expand Down
23 changes: 12 additions & 11 deletions flutter_app/lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:imacs/modules/mavlink_communication.dart';
import 'package:imacs/modules/get_drone_information.dart';
import 'package:imacs/widgets/drone_information_widget.dart';
import 'package:imacs/widgets/nav_bar_widget.dart';

class HomePage extends StatelessWidget {
HomePage({Key? key, required this.title}) : super(key: key);
Expand All @@ -13,16 +14,16 @@ class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Column(
children: [
DroneInformation(
getDroneInformation: GetDroneInformation(comm: comm),
),
],
),
);
appBar: AppBar(
title: Text(title),
),
body: Column(
children: [
DroneInformation(
getDroneInformation: GetDroneInformation(comm: comm),
),
],
),
bottomNavigationBar: const NavBar());
}
}
74 changes: 74 additions & 0 deletions flutter_app/lib/widgets/nav_bar_widget.dart
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());
}
}
4 changes: 2 additions & 2 deletions flutter_app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
url: "https://pub.dev"
source: hosted
version: "14.2.4"
version: "14.2.5"
watcher:
dependency: transitive
description:
Expand Down
45 changes: 45 additions & 0 deletions flutter_app/test/widget/nav_bar_widget_test.dart
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);
});
});
}