ELEC60013-ES-CW1/lib/home.dart

75 lines
2.1 KiB
Dart
Raw Normal View History

2022-02-09 15:50:52 +00:00
import 'package:flutter/material.dart';
2022-02-11 18:14:40 +00:00
import 'package:firebase_auth/firebase_auth.dart';
2022-02-10 11:06:37 +00:00
import 'package:leg_barkr_app/view/metrics/metrics_page.dart';
2022-02-09 17:52:00 +00:00
import 'package:leg_barkr_app/view/steps/steps_page.dart';
import 'package:leg_barkr_app/view/map/map_page.dart';
2022-02-09 17:07:59 +00:00
import 'package:leg_barkr_app/view/settings_page.dart';
2022-02-09 15:50:52 +00:00
class HomeScreen extends StatefulWidget {
const HomeScreen({Key? key}) : super(key: key);
@override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
int _page = 0;
PageController _pageController = PageController();
2022-02-09 15:50:52 +00:00
2022-02-11 18:14:40 +00:00
_HomeScreenState(){
FirebaseAuth.instance
.authStateChanges()
.listen((User? user) {
if (user == null) {
Navigator.pushNamed(context, "/login");
}
});
}
void onBottomBarPressed(int page) {
2022-02-09 15:50:52 +00:00
setState(() {
_page = page;
2022-02-09 15:50:52 +00:00
});
_pageController.jumpToPage(page);
2022-02-09 15:50:52 +00:00
}
@override
Widget build(BuildContext context) {
return Scaffold(
2022-02-09 18:29:27 +00:00
backgroundColor: Colors.white,
2022-02-09 15:50:52 +00:00
body: PageView(
controller: _pageController,
children: const <Widget>[
2022-02-11 18:14:40 +00:00
MetricsPage(),
StepsPage(),
MapPage(),
SettingsPage()
],
2022-02-10 11:06:37 +00:00
onPageChanged: (page) {
setState(() {
_page = page;
});
},
2022-02-09 15:50:52 +00:00
),
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(icon: Icon(Icons.data_usage), label: 'Home'),
2022-02-10 11:06:37 +00:00
BottomNavigationBarItem(icon: Icon(Icons.pets), label: 'Steps'),
2022-02-09 15:50:52 +00:00
BottomNavigationBarItem(icon: Icon(Icons.location_on_outlined), label: 'Location'),
BottomNavigationBarItem(icon: Icon(Icons.settings), label: 'Settings'),
],
currentIndex: _page,
2022-02-09 15:50:52 +00:00
selectedItemColor: Colors.green,
unselectedItemColor: Colors.black,
showSelectedLabels: true,
showUnselectedLabels: false,
2022-02-09 15:50:52 +00:00
backgroundColor: Colors.white,
onTap: onBottomBarPressed,
type: BottomNavigationBarType.fixed,
)
);
}
}