Skip to content

Instantly share code, notes, and snippets.

@fer-ri
Last active July 31, 2020 19:28
Show Gist options
  • Save fer-ri/b6959da15106fbbb14588fbc41e3afaf to your computer and use it in GitHub Desktop.
Save fer-ri/b6959da15106fbbb14588fbc41e3afaf to your computer and use it in GitHub Desktop.
GetX Debug Template
import 'package:flutter/material.dart';
import 'package:get/get.dart';
void main() => runApp(App());
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GetMaterialApp(
initialRoute: '/',
getPages: [
GetPage(name: '/', page: () => FirstScreen(), binding: FirstBinding()),
GetPage(
name: '/second',
page: () => SecondScreen(),
binding: SecondBinding()),
],
);
}
}
class FirstBinding implements Bindings {
@override
void dependencies() {
Get.lazyPut<FirstController>(() => FirstController());
}
}
class SecondBinding implements Bindings {
@override
void dependencies() {
Get.lazyPut<SecondController>(() => SecondController());
}
}
class FirstController extends GetxController {
}
class SecondController extends GetxController {
}
class FirstScreen extends GetView<FirstController> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FlatButton(
onPressed: () {
Get.toNamed('/second');
},
child: Text('Go to second'),
),
],
),
),
);
}
}
class SecondScreen extends GetView<SecondController> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FlatButton(
onPressed: () {
Get.back();
},
child: Text('Go back to first'),
),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment