Skip to content

Commit

Permalink
improved page layout
Browse files Browse the repository at this point in the history
  • Loading branch information
judemont committed Apr 23, 2024
1 parent bce48e1 commit 240f922
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions lib/screens/pages_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,47 @@ import 'package:reciper/screens/settings.dart';
import 'package:reciper/widgets/bottom_nav_bar.dart';

class PagesLayout extends StatefulWidget {
final Widget? child;
final Widget child;
final bool displayBottomNavBar;
final int currentSection;
final int? currentSection;

const PagesLayout(
{super.key,
this.child,
this.displayBottomNavBar = true,
this.currentSection = 0});
const PagesLayout({
Key? key,
required this.child,
this.displayBottomNavBar = true,
this.currentSection,
}) : super(key: key);

@override
State<PagesLayout> createState() => _PagesLayoutState();
}

class _PagesLayoutState extends State<PagesLayout> {
late int currentPageIndex;
late Widget currentChild;
List<Widget> pages = [
const HomePage(),
const RecipeEditorPage(),
const Settings()
];

@override
void initState() {
super.initState();
currentPageIndex = widget.currentSection ?? 0;
currentChild = widget.child;
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: widget.child,
body: currentChild,
bottomNavigationBar: widget.displayBottomNavBar
? BottomNavBar(
selectedIndex: widget.currentSection,
selectedIndex: currentPageIndex,
onDestinationSelected: (index) => setState(() {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => PagesLayout(
currentSection: index,
child: [
const HomePage(),
const RecipeEditorPage(),
const Settings(),
][index]),
));
currentPageIndex = index;
currentChild = pages[currentPageIndex];
}),
)
: null,
Expand Down

0 comments on commit 240f922

Please sign in to comment.