make appbar title change dynamically

main
Julian Gegner 2023-02-15 14:30:25 +01:00
parent fade190d08
commit 40018431dd
1 changed files with 8 additions and 1 deletions

View File

@ -14,6 +14,13 @@ class MyHomePage extends StatefulWidget {
class MyHomePageState extends State<MyHomePage> { class MyHomePageState extends State<MyHomePage> {
int _selectedIndex = 2; int _selectedIndex = 2;
final List<String> _titles = [
'Stimmung',
'Schlaf',
'Timer',
'Rückfall',
'Einstellungen'
];
static const List<Widget> _widgetOptions = <Widget>[ static const List<Widget> _widgetOptions = <Widget>[
MoodPage(), MoodPage(),
SleepPage(), SleepPage(),
@ -29,7 +36,7 @@ class MyHomePageState extends State<MyHomePage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar(title: const Text('ZI Rauchentwöhnung')), appBar: AppBar(title: Text(_titles[_selectedIndex])),
body: _widgetOptions.elementAt(_selectedIndex), body: _widgetOptions.elementAt(_selectedIndex),
bottomNavigationBar: NavigationBar( bottomNavigationBar: NavigationBar(
onDestinationSelected: _onItemTapped, onDestinationSelected: _onItemTapped,