From 9f720bdf752f99e4394edd24ffd1212175edc800 Mon Sep 17 00:00:00 2001 From: Sergey Elpashev Date: Sun, 12 May 2024 14:43:16 +0300 Subject: [PATCH] Fix providers --- lib/mobile_example.dart | 68 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/lib/mobile_example.dart b/lib/mobile_example.dart index a74fee9..ca05736 100644 --- a/lib/mobile_example.dart +++ b/lib/mobile_example.dart @@ -17,13 +17,8 @@ class MyExampleApp extends StatelessWidget { return MaterialApp( title: 'GymLink Example App', debugShowCheckedModeBanner: false, - home: ChangeNotifierProvider( - create: (_) => GymLinkProvider(), - child: Consumer( - builder: (context, provider, __) => const ExamplePage(), - ), - ), - theme: ThemeData.dark(), + home: const ExampleMainPage(), + theme: ThemeData.dark(useMaterial3: true), ); } } @@ -35,6 +30,43 @@ class ExamplePage extends StatefulWidget { State createState() => _ExamplePageState(); } +Widget getDrawer(BuildContext context) => Drawer( + child: Column( + children: [ + const DrawerHeader(child: Text('Drawer Header')), + ListTile( + leading: const Icon(Icons.home), + title: const Text('Home'), + onTap: () => Navigator.of(context).push( + MaterialPageRoute( + builder: (context) => const ExampleMainPage(), + ), + ), + ), + ListTile( + leading: const Icon(Icons.search), + title: const Text('Example page'), + onTap: () => Navigator.of(context).push(MaterialPageRoute( + builder: (context) => const ExampleSecondPage(), + )), + ), + ], + ), + ); + +class ExampleMainPage extends StatelessWidget { + const ExampleMainPage({super.key}); + + @override + Widget build(BuildContext context) { + return ChangeNotifierProvider( + create: (_) => GymLinkProvider(), + child: Consumer( + builder: (_, value, __) => const ExamplePage(), + )); + } +} + class _ExamplePageState extends State { @override void initState() { @@ -46,7 +78,10 @@ class _ExamplePageState extends State { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar(title: const Text('GymLink Example App')), + appBar: AppBar( + title: const Text('GymLink Example App'), + ), + drawer: getDrawer(context), body: Column( children: [ const Text('test'), @@ -77,3 +112,20 @@ class _ExamplePageState extends State { ); } } + +class ExampleSecondPage extends StatelessWidget { + const ExampleSecondPage({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('GymLink Example App'), + ), + drawer: getDrawer(context), + body: const Center( + child: Text('Example page'), + ), + ); + } +}