Flutter-Ernaehrungsapp/lib/views/navigation/navigation_screen.dart

62 lines
1.6 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
class NavigationScreen extends StatefulWidget {
const NavigationScreen({super.key});
@override
NavigationScreenState createState() => NavigationScreenState();
}
class NavigationScreenState extends State<NavigationScreen> {
int _selectedIndex = 0;
2023-04-19 19:56:35 +02:00
final _pages = ["Page 1", "Page 2", "Page 3"];
String _selectedPage = "Page 1";
final PageController _pageController = PageController(initialPage: 0);
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
2023-04-19 19:56:35 +02:00
_selectedPage = _pages[index];
_pageController.animateToPage(index,
duration: const Duration(milliseconds: 300), curve: Curves.easeInOut);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
2023-04-19 19:56:35 +02:00
appBar: AppBar(
title: Text(_selectedPage),
),
body: PageView(
controller: _pageController,
onPageChanged: (int index) {
setState(() {
2023-04-19 19:56:35 +02:00
_selectedPage = _pages[index];
_selectedIndex = index;
});
},
),
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Page 1',
),
BottomNavigationBarItem(
icon: Icon(Icons.work),
label: 'Page 2',
),
BottomNavigationBarItem(
icon: Icon(Icons.school),
label: 'Page 3',
),
],
currentIndex: _selectedIndex,
onTap: _onItemTapped,
),
);
}
}