Skip to content

Instantly share code, notes, and snippets.

@ghprod
Last active Jul 31, 2020
Embed
What would you like to do?
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