mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-23 01:06:21 +01:00
Make Disposable less confusing
This commit is contained in:
parent
1f4b43459c
commit
88ba985a1a
2 changed files with 22 additions and 12 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue