|
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()); |
|
} |
|
} |