mirror of
https://github.com/supleed2/ELEC60013-ES-CW1.git
synced 2024-12-22 21:45:48 +00:00
Added functionality for switching between pages
This commit is contained in:
parent
fd156f31e8
commit
3363d514a0
10
lib/data.dart
Normal file
10
lib/data.dart
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class DataPage extends StatelessWidget {
|
||||||
|
const DataPage({ Key? key }) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Text("Data Page");
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,8 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:leg_barkr_app/data.dart';
|
||||||
|
import 'package:leg_barkr_app/steps.dart';
|
||||||
|
import 'package:leg_barkr_app/map.dart';
|
||||||
|
import 'package:leg_barkr_app/settings.dart';
|
||||||
|
|
||||||
class HomeScreen extends StatefulWidget {
|
class HomeScreen extends StatefulWidget {
|
||||||
const HomeScreen({Key? key}) : super(key: key);
|
const HomeScreen({Key? key}) : super(key: key);
|
||||||
|
@ -8,21 +12,27 @@ class HomeScreen extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _HomeScreenState extends State<HomeScreen> {
|
class _HomeScreenState extends State<HomeScreen> {
|
||||||
int page = 0;
|
int _page = 0;
|
||||||
PageController pageController = PageController();
|
PageController _pageController = PageController();
|
||||||
|
|
||||||
void onBottomBarPressed(int newPage) {
|
void onBottomBarPressed(int page) {
|
||||||
setState(() {
|
setState(() {
|
||||||
page = newPage;
|
_page = page;
|
||||||
});
|
});
|
||||||
pageController.jumpToPage(newPage);
|
_pageController.jumpToPage(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: PageView(
|
body: PageView(
|
||||||
controller: pageController,
|
controller: _pageController,
|
||||||
|
children: const <Widget>[
|
||||||
|
DataPage(),
|
||||||
|
StepsPage(),
|
||||||
|
MapPage(),
|
||||||
|
SettingsPage()
|
||||||
|
],
|
||||||
),
|
),
|
||||||
bottomNavigationBar: BottomNavigationBar(
|
bottomNavigationBar: BottomNavigationBar(
|
||||||
items: const <BottomNavigationBarItem>[
|
items: const <BottomNavigationBarItem>[
|
||||||
|
@ -31,9 +41,11 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||||
BottomNavigationBarItem(icon: Icon(Icons.location_on_outlined), label: 'Location'),
|
BottomNavigationBarItem(icon: Icon(Icons.location_on_outlined), label: 'Location'),
|
||||||
BottomNavigationBarItem(icon: Icon(Icons.settings), label: 'Settings'),
|
BottomNavigationBarItem(icon: Icon(Icons.settings), label: 'Settings'),
|
||||||
],
|
],
|
||||||
currentIndex: page,
|
currentIndex: _page,
|
||||||
selectedItemColor: Colors.green,
|
selectedItemColor: Colors.green,
|
||||||
unselectedItemColor: Colors.black,
|
unselectedItemColor: Colors.black,
|
||||||
|
showSelectedLabels: true,
|
||||||
|
showUnselectedLabels: false,
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
onTap: onBottomBarPressed,
|
onTap: onBottomBarPressed,
|
||||||
type: BottomNavigationBarType.fixed,
|
type: BottomNavigationBarType.fixed,
|
||||||
|
|
10
lib/map.dart
Normal file
10
lib/map.dart
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class MapPage extends StatelessWidget {
|
||||||
|
const MapPage({ Key? key }) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Text("Map Page");
|
||||||
|
}
|
||||||
|
}
|
10
lib/settings.dart
Normal file
10
lib/settings.dart
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class SettingsPage extends StatelessWidget {
|
||||||
|
const SettingsPage({ Key? key }) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Text("Settings Page");
|
||||||
|
}
|
||||||
|
}
|
10
lib/steps.dart
Normal file
10
lib/steps.dart
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class StepsPage extends StatelessWidget {
|
||||||
|
const StepsPage({ Key? key }) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Text("Data Page");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue