Created
December 16, 2020 20:54
-
-
Save eduardoflorence/69277755dd4947f751fe7aac58e157ef to your computer and use it in GitHub Desktop.
GetX - Sample Hook
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(GetMaterialApp(home: HomePage())); | |
} | |
class HomePage extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: Text('HOME')), | |
body: Container( | |
child: RaisedButton( | |
child: Text('Go to page 2'), | |
onPressed: () => Get.to(Page2()), | |
), | |
), | |
); | |
} | |
} | |
class Page2 extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
final controller = Get.put(Page2Controller()); | |
return Scaffold( | |
appBar: AppBar(title: Text('Page2')), | |
body: Container( | |
child: Text(controller.number.toString()), | |
), | |
); | |
} | |
} | |
class Page2Controller extends GetxController { | |
RxInt number = RxInt(0); | |
@override | |
void onInit() { | |
print('onInit'); | |
super.onInit(); | |
} | |
@override | |
void onReady() { | |
print('onReady'); | |
super.onReady(); | |
} | |
@override | |
void onClose() { | |
print('onClose'); | |
super.onClose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment