class MyScreen extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return MyScreenState();
}
}
class MyScreenState extends State<StatefulWidget> {
MyDataSource dataSource = MyDataSource();
@override
void initState() {
super.initState();
dataSource.addListener(callback);
}
@override
void dispose() {
dataSource.removeListener(callback);
dataSource.dispose();
super.dispose();
}
void callback() {
print("Do Something with dataSource's state");
}
@override
Widget build(BuildContext context) {
return null;
}
}
class MyDataSource extends ChangeNotifier {
void performFetch(http.Client client) {
expensiveOperation();
notifyListeners();
}
void expensiveOperation() async {
await Future.delayed(Duration(seconds: 30));
}
}
```
--
You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Ian Hickson
😸
@override
void dispose() {
_disposed = true;
super.dispose();
}
@override
void notifyListeners() {
if (!_disposed) {
super.notifyListeners();
}
}