2022-04-24 04:08:45 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2023-11-29 06:20:00 +02:00
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
2022-04-24 04:08:45 +02:00
|
|
|
import 'package:immich_mobile/shared/ui/immich_loading_indicator.dart';
|
|
|
|
|
2023-11-29 06:20:00 +02:00
|
|
|
final _loadingEntry = OverlayEntry(
|
|
|
|
builder: (context) => SizedBox.square(
|
|
|
|
dimension: double.infinity,
|
|
|
|
child: DecoratedBox(
|
|
|
|
decoration:
|
|
|
|
BoxDecoration(color: context.colorScheme.surface.withAlpha(200)),
|
|
|
|
child: const Center(child: ImmichLoadingIndicator()),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
ValueNotifier<bool> useProcessingOverlay() {
|
|
|
|
return use(const _LoadingOverlay());
|
|
|
|
}
|
|
|
|
|
|
|
|
class _LoadingOverlay extends Hook<ValueNotifier<bool>> {
|
|
|
|
const _LoadingOverlay();
|
2022-04-24 04:08:45 +02:00
|
|
|
|
|
|
|
@override
|
2023-11-29 06:20:00 +02:00
|
|
|
_LoadingOverlayState createState() => _LoadingOverlayState();
|
2022-04-24 04:08:45 +02:00
|
|
|
}
|
|
|
|
|
2023-11-29 06:20:00 +02:00
|
|
|
class _LoadingOverlayState
|
|
|
|
extends HookState<ValueNotifier<bool>, _LoadingOverlay> {
|
|
|
|
late final _isProcessing = ValueNotifier(false)..addListener(_listener);
|
|
|
|
OverlayEntry? overlayEntry;
|
|
|
|
|
|
|
|
void _listener() {
|
|
|
|
setState(() {
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
if (_isProcessing.value) {
|
|
|
|
overlayEntry?.remove();
|
|
|
|
overlayEntry = _loadingEntry;
|
|
|
|
Overlay.of(context).insert(_loadingEntry);
|
|
|
|
} else {
|
|
|
|
overlayEntry?.remove();
|
|
|
|
overlayEntry = null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2022-04-24 04:08:45 +02:00
|
|
|
|
2023-11-29 06:20:00 +02:00
|
|
|
@override
|
|
|
|
ValueNotifier<bool> build(BuildContext context) {
|
|
|
|
return _isProcessing;
|
2022-04-24 04:08:45 +02:00
|
|
|
}
|
|
|
|
|
2023-11-29 06:20:00 +02:00
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_isProcessing.dispose();
|
|
|
|
super.dispose();
|
2022-04-24 04:08:45 +02:00
|
|
|
}
|
2023-11-29 06:20:00 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Object? get debugValue => _isProcessing.value;
|
|
|
|
|
|
|
|
@override
|
|
|
|
String get debugLabel => 'useProcessingOverlay<>';
|
2022-04-24 04:08:45 +02:00
|
|
|
}
|