RafiLutfansyah

Test Getx

Jul 24th, 2021 (edited)
490
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.71 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3.  
  4. void main() => runApp(GetMaterialApp(home: Home()));
  5.  
  6. class Home extends StatelessWidget {
  7.   final c = Get.put(Controller());
  8.  
  9.   @override
  10.   Widget build(context) {
  11.     ever(c.count, (_) {
  12.       Get.defaultDialog(title: 'Show Dialog', middleText: 'Dialog ke ${c.count}', textCancel: 'Tutup');
  13.     });
  14.  
  15.     return Scaffold(
  16.       body: Center(child: Obx(() => Text("Clicks: ${c.count}", style: TextStyle(fontSize: 24)))),
  17.       floatingActionButton: FloatingActionButton(child: Icon(Icons.add), onPressed: c.increment),
  18.     );
  19.   }
  20. }
  21.  
  22. class Controller extends GetxController {
  23.   var count = 0.obs;
  24.  
  25.   void increment() => count++;
  26. }
  27.  
Add Comment
Please, Sign In to add comment