Skip to content

Commit

Permalink
examples/bottom_navigation: improve readability of nested Beamer
Browse files Browse the repository at this point in the history
  • Loading branch information
slovnicki committed Feb 26, 2022
1 parent 7a1556e commit 013da3c
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions examples/bottom_navigation/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,43 +215,48 @@ class _BottomNavigationBarWidgetState extends State<BottomNavigationBarWidget> {
}
}

class HomeScreen extends StatelessWidget {
HomeScreen({Key? key}) : super(key: key);

final _beamerKey = GlobalKey<BeamerState>();
final _routerDelegate = BeamerDelegate(
locationBuilder: BeamerLocationBuilder(
beamLocations: [
BooksLocation(),
ArticlesLocation(),
],
),
);

@override
Widget build(BuildContext context) {
return Scaffold(
body: Beamer(
key: _beamerKey,
routerDelegate: _routerDelegate,
),
bottomNavigationBar: BottomNavigationBarWidget(
beamerKey: _beamerKey,
),
);
}
}

class MyApp extends StatelessWidget {
final routerDelegate = BeamerDelegate(
initialPath: '/books',
locationBuilder: RoutesLocationBuilder(
routes: {
'*': (context, state, data) {
final beamerKey = GlobalKey<BeamerState>();
return Scaffold(
body: Beamer(
key: beamerKey,
routerDelegate: BeamerDelegate(
locationBuilder: BeamerLocationBuilder(
beamLocations: [
BooksLocation(),
ArticlesLocation(),
],
),
),
),
bottomNavigationBar: BottomNavigationBarWidget(
beamerKey: beamerKey,
),
);
}
'*': (context, state, data) => HomeScreen(),
},
),
);

@override
Widget build(BuildContext context) {
return MaterialApp.router(
debugShowCheckedModeBanner: false,
routerDelegate: routerDelegate,
routeInformationParser: BeamerParser(),
backButtonDispatcher: BeamerBackButtonDispatcher(
delegate: routerDelegate,
),
);
}
}
Expand Down

0 comments on commit 013da3c

Please sign in to comment.