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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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'
4 changes: 4 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,9 @@ class App extends StatelessWidget {
),
routes: {
'/': (BuildContext context) => HomePage(title: 'WARG IMACS'),
'/logs': (BuildContext context) => const Placeholder(child: NavBar()),
Copy link
Contributor

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

class PlaceholderScreen extends StatelessWidget {
  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());
  }
}

'/camera': (BuildContext context) => const Placeholder(child: NavBar()),
'/sitl': (BuildContext context) => const Placeholder(child: NavBar()),
},
);
}
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());
}
}
64 changes: 64 additions & 0 deletions flutter_app/lib/widgets/nav_bar_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import 'package:flutter/material.dart';

class NavBar extends StatefulWidget {
Copy link
Contributor

Choose a reason for hiding this comment

The 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;
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really a fan of routing like this, use pushReplacementNamed and popAndPushNamed when possible or replace the router as suggested above.

break;
case 1:
Navigator.pushNamed(context, '/logs');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use pushReplacementNamed or popAndPushNamed or replace the router as suggested above.

break;
case 2:
Navigator.pushNamed(context, '/camera');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use pushReplacementNamed or popAndPushNamed or replace the router as suggested above.

break;
default:
Navigator.pushNamed(context, '/sitl');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use pushReplacementNamed or popAndPushNamed or replace the router as suggested above.

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,
);
}
}
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