Added functionality for switching between pages

This commit is contained in:
Benjamin Ramhorst 2022-02-09 16:06:37 +00:00
parent fd156f31e8
commit 3363d514a0
5 changed files with 59 additions and 7 deletions

10
lib/data.dart Normal file
View 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");
}
}

View file

@ -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
View 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
View 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
View 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");
}
}