diff --git a/lib/screens/pages_layout.dart b/lib/screens/pages_layout.dart index a690f0e..a667d1f 100644 --- a/lib/screens/pages_layout.dart +++ b/lib/screens/pages_layout.dart @@ -7,31 +7,36 @@ import 'package:reciper/widgets/bottom_nav_bar.dart'; class PagesLayout extends StatefulWidget { final Widget? child; final bool displayBottomNavBar; + final int currentSection; - const PagesLayout({super.key, this.child, this.displayBottomNavBar = true}); + const PagesLayout( + {super.key, + this.child, + this.displayBottomNavBar = true, + this.currentSection = 0}); @override State createState() => _PagesLayoutState(); } class _PagesLayoutState extends State { - int? currentPageIndex; - @override Widget build(BuildContext context) { return Scaffold( - body: currentPageIndex == null - ? widget.child - : [ - const HomePage(), - const RecipeEditorPage(), - const Settings() - ][currentPageIndex!], + body: widget.child, bottomNavigationBar: widget.displayBottomNavBar ? BottomNavBar( - selectedIndex: currentPageIndex ?? 0, + selectedIndex: widget.currentSection, onDestinationSelected: (index) => setState(() { - currentPageIndex = index; + Navigator.of(context).push(MaterialPageRoute( + builder: (context) => PagesLayout( + currentSection: index, + child: [ + const HomePage(), + const RecipeEditorPage(), + const Settings(), + ][index]), + )); }), ) : null, diff --git a/lib/screens/recipe_view.dart b/lib/screens/recipe_view.dart index 44dff71..e2b0bd6 100644 --- a/lib/screens/recipe_view.dart +++ b/lib/screens/recipe_view.dart @@ -43,6 +43,7 @@ class _RecipeViewPageState extends State { Navigator.of(context) .push(MaterialPageRoute( builder: (context) => PagesLayout( + currentSection: 1, displayBottomNavBar: false, child: RecipeEditorPage( initialRecipe: widget.recipe, diff --git a/lib/screens/settings.dart b/lib/screens/settings.dart index 712164a..ffd4f8b 100644 --- a/lib/screens/settings.dart +++ b/lib/screens/settings.dart @@ -2,25 +2,8 @@ import 'package:flutter/material.dart'; import 'package:reciper/utilities/utils.dart'; import 'package:url_launcher/url_launcher.dart'; -class Settings extends StatefulWidget { - const Settings({super.key}); - - @override - State createState() => _SettingsState(); -} - -class _SettingsState extends State { - int _displayedTabIndex = 0; - - void setDisplayedTab(int index) { - setState(() { - if (_displayedTabIndex == index) { - _displayedTabIndex = 0; - } else { - _displayedTabIndex = index; - } - }); - } +class Settings extends StatelessWidget { + const Settings({Key? key}) : super(key: key); @override Widget build(BuildContext context) { @@ -31,80 +14,55 @@ class _SettingsState extends State { centerTitle: true, ), body: SingleChildScrollView( + padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10), child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - ListTile( - selected: _displayedTabIndex == 1, - onTap: () { - setDisplayedTab(1); - }, - title: const Text("Import"), - ), - Visibility( - visible: _displayedTabIndex == 1, - child: Container( - margin: const EdgeInsets.only(left: 20), - child: Column( - children: [ - ListTile( - title: const Text("Import recipes"), - onTap: () { - Utils.import(); - Navigator.pop(context); - }), - ], - ), - ), + const Text( + "Import", + style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), ), - ListTile( - selected: _displayedTabIndex == 2, - onTap: () { - setDisplayedTab(2); + const SizedBox(height: 20), + ElevatedButton( + onPressed: () { + Utils.import(); + Navigator.pop(context); }, - title: const Text("Export"), + child: const Text("Import recipes"), ), - Visibility( - visible: _displayedTabIndex == 2, - child: Container( - margin: const EdgeInsets.only(left: 20), - child: Column( - children: [ - ListTile( - title: const Text("Export recipes"), - onTap: () => Utils.export(), - ), - ], - ), - ), + const SizedBox(height: 20), + const Text( + "Export", + style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), ), - ListTile( - selected: _displayedTabIndex == 3, - onTap: () { - setDisplayedTab(3); + const SizedBox(height: 20), + ElevatedButton( + onPressed: () { + Utils.export(); }, - title: const Text("About"), + child: const Text("Export recipes"), + ), + const SizedBox(height: 20), + const Text( + "About", + style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), ), - Visibility( - visible: _displayedTabIndex == 3, - child: Container( - margin: const EdgeInsets.only(left: 20), - child: Column( - children: [ - const ListTile( - title: Text( - "Reciper has been developed with ❤️ by Judemont and Rdemont"), - ), - ListTile( - title: const Text( - "Source code (GitHub)", - style: TextStyle(color: Colors.blue), - ), - onTap: () => launchUrl( - Uri.parse('https://github.com/judemont/reciper')), - ) - ], + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + "Reciper has been developed with ❤️ by Judemont", + style: TextStyle(fontSize: 16), + ), + const SizedBox(height: 20), + ElevatedButton.icon( + onPressed: () => launchUrl( + Uri.parse('https://github.com/judemont/reciper'), + ), + icon: const Icon(Icons.link), + label: const Text("Source code (GitHub)"), ), - ), + ], ), ], ), diff --git a/lib/widgets/extract_recipe_dialog.dart b/lib/widgets/extract_recipe_dialog.dart index 77ec6b5..c5498df 100644 --- a/lib/widgets/extract_recipe_dialog.dart +++ b/lib/widgets/extract_recipe_dialog.dart @@ -53,6 +53,7 @@ class _ExtractRecipeDialogState extends State { context, MaterialPageRoute( builder: (context) => PagesLayout( + currentSection: 1, child: RecipeEditorPage( initialRecipe: Recipe( title: recipeData.name ?? "",