Skip to content

Instantly share code, notes, and snippets.

@ProZhar
Forked from eduardoflorence/main.dart
Created February 18, 2023 13:16
Show Gist options
  • Save ProZhar/335c4b724396622766f58552be52cc75 to your computer and use it in GitHub Desktop.
Save ProZhar/335c4b724396622766f58552be52cc75 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