Created
April 8, 2021 15:18
-
-
Save RipplesCode/9fb8abde70fc166fb7b7ec73bdd6afdb to your computer and use it in GitHub Desktop.
Workers
This file contains 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:flutter_getx/my_controller.dart'; | |
import 'package:flutter_getx/next_screen.dart'; | |
import 'package:flutter_getx/student.dart'; | |
import 'package:flutter_getx/unknown_route.dart'; | |
import 'package:get/get.dart'; | |
import 'home.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
MyController myController = Get.put(MyController()); | |
@override | |
Widget build(BuildContext context) { | |
// TODO: implement build | |
return GetMaterialApp( | |
title: "Workers", | |
home: Scaffold( | |
appBar: AppBar(title: Text("Workers")), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
crossAxisAlignment: CrossAxisAlignment.center, | |
children: [ | |
RaisedButton( | |
child: Text("Increment"), | |
onPressed: () => myController.increment(), | |
), | |
Padding( | |
padding: EdgeInsets.all(16), | |
child: TextField( | |
onChanged: (val) { | |
myController.increment(); | |
}, | |
), | |
) | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
This file contains 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_getx/student.dart'; | |
import 'package:get/get.dart'; | |
import 'home.dart'; | |
//Workers trigger specific callbacks when an event occurs. | |
class MyController extends GetxController { | |
var count = 0.obs; | |
void increment() | |
{ | |
count++; | |
} | |
@override | |
void onInit() { | |
//called every time when the value of count variable changes | |
//ever(count,(_)=>print(count)); | |
// Called every time when the value of any variable from the list changes | |
//everAll([count], (_)=>print(count)); | |
// Called only once when the variable value changes | |
//once(count, (_)=>print(count)); | |
//Called every time the user stops typing for 1 second | |
//debounce(count, (_) => print("When the user stop typing for 1 sec the value of count will be $count"), time: Duration(seconds: 1)); | |
//Ignore all changes within 1 second. | |
//imagine that the user can earn coins by clicking on something, | |
// if he clicked 300 times in the same minute, | |
// he would have 300 coins, using interval, | |
// you you can set a time frame for 3 seconds, | |
// and even then clicking 300 or a thousand times, | |
// the maximum he would get in 1 minute would be 20 coins, | |
// clicking 300 or 1 million times | |
interval(count, (_) => print("Ignore all changes"), time: Duration(seconds: 1)); | |
super.onInit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment