Created
May 28, 2021 16:01
-
-
Save siumhossain/6d9b49b6f07ccb205561b96f8ae4e96b to your computer and use it in GitHub Desktop.
controllerapp
This file contains hidden or 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:get/get.dart'; | |
| class MyController extends GetxController{ | |
| var count = 0.obs; | |
| void increment(){ | |
| count++; | |
| } | |
| } |
This file contains hidden or 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'; | |
| import 'package:controllerapp/controller.dart'; | |
| void main() { | |
| runApp(MyApp()); | |
| } | |
| class MyApp extends StatelessWidget { | |
| //MyController controller = Get.put(MyController()); | |
| @override | |
| Widget build(BuildContext context) { | |
| return GetMaterialApp( | |
| home: Scaffold( | |
| body: Center( | |
| child: Column( | |
| children: <Widget>[ | |
| GetX<MyController>( | |
| init: MyController(), | |
| builder: (controller){ | |
| return Text( | |
| 'value is ${controller.count}', | |
| style: TextStyle( | |
| fontSize: 32, | |
| color: Colors.black, | |
| ), | |
| ); | |
| }, | |
| ), | |
| ElevatedButton( | |
| onPressed: (){ | |
| //or you have to create on top | |
| //MyController controller = Get.put(MyController()); | |
| Get.find<MyController>().increment(); | |
| }, | |
| child: Text('click'), | |
| ) | |
| ], | |
| ), | |
| ), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment