Instantly share code, notes, and snippets.
Created
February 22, 2022 20:00
-
Star
(1)
1
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save romanejaquez/d769e6e766fbacb2f5c166dd3bceab51 to your computer and use it in GitHub Desktop.
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
import 'package:flutter/material.dart'; | |
const Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
navigatorKey: Utils.app1Nav, | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Center( | |
child: App1(), | |
), | |
), | |
); | |
} | |
} | |
class App1 extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
const Text( | |
'Hello, World!' | |
), | |
TextButton( | |
onPressed: () { | |
showDialog(context: context, | |
builder: (BuildContext cxt) { | |
return AlertDialog( | |
content: App2() | |
); | |
} | |
); | |
}, | |
child: const Text('Click me to show dialog') | |
) | |
] | |
); | |
} | |
} | |
class App2 extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Column( | |
children: [ | |
Expanded( | |
child: Navigator( | |
key: Utils.app2Nav, | |
initialRoute: '/app2page1', | |
onGenerateRoute: (RouteSettings settings) { | |
Widget page; | |
switch(settings.name) { | |
case '/app2page1': | |
page = App2Page1(); | |
break; | |
case '/app2page2': | |
page = App2Page2(); | |
break; | |
case '/app2page3': | |
page = App2Page3(); | |
break; | |
default: | |
page = App2Page1(); | |
break; | |
} | |
return PageRouteBuilder( | |
pageBuilder: (_, __, ___) => page, | |
transitionDuration: const Duration(seconds: 0) | |
); | |
} | |
) | |
), | |
Row( | |
mainAxisAlignment: MainAxisAlignment.spaceBetween, | |
children: [ | |
TextButton( | |
onPressed: () { | |
Utils.app2Nav.currentState!.pushReplacementNamed('/app2page1'); | |
}, | |
child: const Text('Go To App2Page1') | |
), | |
TextButton( | |
onPressed: () { | |
Utils.app2Nav.currentState!.pushReplacementNamed('/app2page2'); | |
}, | |
child: const Text('Go To App2Page2') | |
), | |
TextButton( | |
onPressed: () { | |
Utils.app2Nav.currentState!.pushReplacementNamed('/app2page3'); | |
}, | |
child: const Text('Go To App2Page3') | |
) | |
] | |
) | |
] | |
); | |
} | |
} | |
class App2Page1 extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return const Text('App 2 Page 1', style: TextStyle(fontSize: 30)); | |
} | |
} | |
class App2Page2 extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return const Text('App 2 Page 2', style: TextStyle(fontSize: 30)); | |
} | |
} | |
class App2Page3 extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return const Text('App 2 Page 3', style: TextStyle(fontSize: 30)); | |
} | |
} | |
class Utils { | |
static GlobalKey<NavigatorState> app1Nav = GlobalKey(); | |
static GlobalKey<NavigatorState> app2Nav = GlobalKey(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment