Make Disposable less confusing

This commit is contained in:
Ming Ming 2021-09-15 04:37:59 +08:00
parent 1f4b43459c
commit 88ba985a1a
2 changed files with 22 additions and 12 deletions

View file

@ -9,18 +9,24 @@ mixin DisposableManagerMixin<T extends StatefulWidget> on State<T> {
@override
initState() {
super.initState();
for (final d in disposables) {
for (final d in _disposables) {
d.init(this);
}
}
@override
dispose() {
for (final d in disposables) {
for (final d in _disposables) {
d.dispose(this);
}
super.dispose();
}
List<Disposable> get disposables;
/// Return a list of [Disposable] to be managed
@mustCallSuper
List<Disposable> initDisposables() {
return [];
}
late final _disposables = initDisposables();
}

View file

@ -86,6 +86,19 @@ class Viewer extends StatefulWidget {
}
class _ViewerState extends State<Viewer> with DisposableManagerMixin<Viewer> {
@override
initDisposables() {
return [
...super.initDisposables(),
if (platform_k.isMobile) _ViewerBrightnessController(),
_ViewerSystemUiResetter(),
if (platform_k.isMobile && Pref.inst().isViewerForceRotationOr(false))
_ViewerOrientationController(
onChanged: _onOrientationChanged,
),
];
}
@override
build(BuildContext context) {
return AppTheme(
@ -644,15 +657,6 @@ class _ViewerState extends State<Viewer> with DisposableManagerMixin<Viewer> {
bool _canOpenDetailPane() => !_isZoomed;
bool _canZoom() => !_isDetailPaneActive;
late final disposables = [
if (platform_k.isMobile) _ViewerBrightnessController(),
_ViewerSystemUiResetter(),
if (platform_k.isMobile && Pref.inst().isViewerForceRotationOr(false))
_ViewerOrientationController(
onChanged: _onOrientationChanged,
),
];
var _isShowAppBar = true;
var _isShowDetailPane = false;