Instantly share code, notes, and snippets.
-
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 RodBr/76c7c01494c4ed9591e57586547e1f9d to your computer and use it in GitHub Desktop.
Navigation
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'; | |
import 'package:get/get.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return GetMaterialApp( | |
theme: ThemeData( | |
primaryColor: Colors.purple, | |
buttonTheme: ButtonThemeData( | |
textTheme: ButtonTextTheme.primary, | |
buttonColor: Colors.green, | |
), | |
textTheme: TextTheme(bodyText2: TextStyle(fontSize: 24))), | |
home: Page1(), | |
); | |
} | |
} | |
class Page1 extends StatelessWidget { | |
const Page1({Key key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: Text('Page 1')), | |
backgroundColor: Colors.blue[100], | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Text('Parameters demo'), | |
RaisedButton( | |
onPressed: () async { | |
var result = await Get.to( | |
Page2(message: 'Hi from Page 1', status: true), | |
transition: Transition.rotate, | |
duration: Duration(milliseconds: 500)); | |
if (result is String) { | |
Get.snackbar('Returned', result, | |
backgroundColor: Colors.orange); | |
} | |
}, | |
child: Text('Page 2'), | |
), | |
SizedBox(height: 20), | |
Text('Controller demo'), | |
RaisedButton( | |
onPressed: () => Get.to(Page3(), arguments: 'Hi Page 3'), | |
child: Text('Page 3'), | |
), | |
], | |
), | |
), | |
); | |
} | |
} | |
class Page2 extends StatelessWidget { | |
final String message; | |
final bool status; | |
const Page2({this.message, this.status}); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: Text('Page 2')), | |
backgroundColor: Colors.pink[100], | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Text('Parameters demo'), | |
SizedBox(height: 20), | |
Text('$message - $status', style: TextStyle(color: Colors.red)), | |
SizedBox(height: 20), | |
RaisedButton( | |
onPressed: () => Get.back(result: 'Hi back'), | |
child: Text('Get back')), | |
], | |
))); | |
} | |
} | |
class Page3 extends StatelessWidget { | |
const Page3({Key key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
String message = Get.arguments; | |
return GetBuilder<Page3Controller>( | |
init: Page3Controller(), | |
builder: (controller) => Scaffold( | |
appBar: AppBar(title: Text('Page 3')), | |
backgroundColor: Colors.purple[100], | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Text('Agruments demo'), | |
SizedBox(height: 20), | |
Text('Page: $message', style: TextStyle(color: Colors.red)), | |
SizedBox(height: 20), | |
Text(controller.getArgs(), style: TextStyle(color: Colors.blue)), | |
SizedBox(height: 20), | |
RaisedButton( | |
onPressed: () => controller.getOff(), child: Text('Return')), | |
], | |
))), | |
); | |
} | |
} | |
class Page3Controller extends GetController { | |
onInit() { | |
print(Get.arguments); | |
} | |
getArgs() { | |
return 'Controller: ${Get.arguments}'; | |
} | |
getOff() { | |
Get.offAll(Page1()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment