2021-08-23 19:28:25 +02:00
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
|
|
|
|
abstract class Disposable {
|
|
|
|
void init(State state);
|
|
|
|
void dispose(State state);
|
|
|
|
}
|
|
|
|
|
|
|
|
mixin DisposableManagerMixin<T extends StatefulWidget> on State<T> {
|
|
|
|
@override
|
|
|
|
initState() {
|
|
|
|
super.initState();
|
2021-09-14 22:37:59 +02:00
|
|
|
for (final d in _disposables) {
|
2021-08-23 19:28:25 +02:00
|
|
|
d.init(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
dispose() {
|
2021-09-14 22:37:59 +02:00
|
|
|
for (final d in _disposables) {
|
2021-08-23 19:28:25 +02:00
|
|
|
d.dispose(this);
|
|
|
|
}
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
2021-09-14 22:37:59 +02:00
|
|
|
/// Return a list of [Disposable] to be managed
|
|
|
|
@mustCallSuper
|
|
|
|
List<Disposable> initDisposables() {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
late final _disposables = initDisposables();
|
2021-08-23 19:28:25 +02:00
|
|
|
}
|