forked from bitsdojo/bitsdojo_window
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added simple router using onGenerateRoute
create three simple screens
- Loading branch information
Showing
4 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
bitsdojo_window/example/lib/example_with_simple_onGenerateRoute/routes.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import 'package:animations/animations.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'screen_one.dart'; | ||
import 'screen_three.dart'; | ||
import 'screen_two.dart'; | ||
|
||
class Routes { | ||
// | ||
static const String screenOne = 'splash'; | ||
static const String screenTwo = 'loader'; | ||
static const String screenThree = 'login'; | ||
// | ||
static Route<T> fadeThrough<T>(RouteSettings settings, WidgetBuilder page, | ||
{int duration = 500}) { | ||
return PageRouteBuilder<T>( | ||
settings: settings, | ||
transitionDuration: Duration(milliseconds: duration), | ||
pageBuilder: (context, animation, secondaryAnimation) => page(context), | ||
transitionsBuilder: (context, animation, secondaryAnimation, child) { | ||
return FadeScaleTransition(animation: animation, child: child); | ||
}, | ||
); | ||
} | ||
// | ||
} | ||
|
||
class AppRouter { | ||
// | ||
Route onGenerateRoute(RouteSettings settings) { | ||
// | ||
return Routes.fadeThrough(settings, (context) { | ||
// | ||
switch (settings.name) { | ||
case Routes.screenOne: | ||
return const ScreenOne(); | ||
|
||
case Routes.screenTwo: | ||
return const ScreenTwo(); | ||
|
||
case Routes.screenThree: | ||
return const ScreenThree(); | ||
|
||
default: | ||
return const SizedBox.shrink(); | ||
} | ||
// | ||
}); | ||
// | ||
} | ||
// | ||
} |
38 changes: 38 additions & 0 deletions
38
bitsdojo_window/example/lib/example_with_simple_onGenerateRoute/screen_one.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'routes.dart'; | ||
|
||
class ScreenOne extends StatefulWidget { | ||
const ScreenOne({Key? key}) : super(key: key); | ||
|
||
@override | ||
State<ScreenOne> createState() => _ScreenOneState(); | ||
} | ||
|
||
class _ScreenOneState extends State<ScreenOne> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
body: Center( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
// | ||
Text( | ||
"This is screen one", | ||
style: Theme.of(context).textTheme.headlineMedium, | ||
), | ||
|
||
const SizedBox(height: 20), | ||
|
||
ElevatedButton( | ||
onPressed: () => Navigator.pushNamed(context, Routes.screenTwo), | ||
child: const Text("Go To Screen Two"), | ||
) | ||
// | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
bitsdojo_window/example/lib/example_with_simple_onGenerateRoute/screen_three.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'routes.dart'; | ||
|
||
class ScreenThree extends StatefulWidget { | ||
const ScreenThree({Key? key}) : super(key: key); | ||
|
||
@override | ||
State<ScreenThree> createState() => _ScreenThreeState(); | ||
} | ||
|
||
class _ScreenThreeState extends State<ScreenThree> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
body: Center( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
// | ||
Text( | ||
"This is screen three", | ||
style: Theme.of(context).textTheme.headlineMedium, | ||
), | ||
|
||
const SizedBox(height: 20), | ||
|
||
ElevatedButton( | ||
onPressed: () => Navigator.pushNamed(context, Routes.screenOne), | ||
child: const Text("Go Back To Screen One"), | ||
) | ||
// | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
bitsdojo_window/example/lib/example_with_simple_onGenerateRoute/screen_two.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'routes.dart'; | ||
|
||
class ScreenTwo extends StatefulWidget { | ||
const ScreenTwo({Key? key}) : super(key: key); | ||
|
||
@override | ||
State<ScreenTwo> createState() => _ScreenTwoState(); | ||
} | ||
|
||
class _ScreenTwoState extends State<ScreenTwo> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
body: Center( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
// | ||
Text( | ||
"This is screen two", | ||
style: Theme.of(context).textTheme.headlineMedium, | ||
), | ||
|
||
const SizedBox(height: 20), | ||
|
||
ElevatedButton( | ||
onPressed: () => Navigator.pushNamed(context, Routes.screenThree), | ||
child: const Text("Go To Screen Three"), | ||
) | ||
// | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |