Skip to content

Instantly share code, notes, and snippets.

@eduardoflorence
Created December 16, 2020 20:54
Show Gist options
  • Save eduardoflorence/69277755dd4947f751fe7aac58e157ef to your computer and use it in GitHub Desktop.
Save eduardoflorence/69277755dd4947f751fe7aac58e157ef to your computer and use it in GitHub Desktop.
GetX - Sample Hook
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