added image cache managing

This commit is contained in:
Mehul Ahal 2022-12-21 23:40:39 +01:00
parent b7045fc242
commit 2ff4d44d25
14 changed files with 188 additions and 80 deletions

View file

@ -0,0 +1,11 @@
import 'package:flutter/widgets.dart';
import 'const_colors.dart';
abstract class ConstText {
static const _imageOverlayTextStyle = TextStyle(
color: ConstColours.white,
fontSize: 28,
);
static TextStyle imageOverlayTextStyle(BuildContext context) => _imageOverlayTextStyle;
}

View file

@ -11,16 +11,13 @@ class OverlayService {
final LoggingService _loggingService;
final Map<int, AnimationController> _animationControllerMap = const {};
final Map<int, OverlayEntry> _overlayEntryMap = const {};
Future<void> playOverlayEntry({
required BuildContext context,
required AnimationController animationController,
required OverlayEntry overlayEntry,
}) async {
try {
_animationControllerMap[animationController.hashCode] = animationController;
_overlayEntryMap[overlayEntry.hashCode] = overlayEntry;
Overlay.of(
context,
@ -28,12 +25,9 @@ class OverlayService {
)!
.insert(overlayEntry);
await animationController.forward();
if (overlayEntry.mounted) overlayEntry.remove();
_overlayEntryMap.remove(overlayEntry.hashCode);
animationController.dispose();
_animationControllerMap.remove(animationController.hashCode);
} catch (error, stackTrace) {
_loggingService.handle(error, stackTrace);
}
@ -46,12 +40,6 @@ class OverlayService {
}
}
_overlayEntryMap.clear();
for (final animationController in _animationControllerMap.values) {
if (animationController.isAnimating) {
animationController.dispose();
}
}
_animationControllerMap.clear();
}
static OverlayService get locate => Locator.locate();