I have a data cache. It is expensive to fetch some of the data.. other data is quite disposable. The data can be quite large and could conceivably cause the OS to ask apps to free memory.
Android has onTrimMemory() and IOS has applicationDidReceiveMemoryWarning(). Is there a flutter equivalent?
The widget must implement the WidgetsBindingObserver and override didHaveMemoryPressure, like in the following example:
class _HomePageState extends BaseState<HomePage> with WidgetsBindingObserver {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}
@override
void dispose() {
super.dispose();
WidgetsBinding.instance.removeObserver(this);
}
@override
void didHaveMemoryPressure() {
print('didHaveMemoryPressure');
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With