diff --git a/lib/image_editor_plus.dart b/lib/image_editor_plus.dart index 3fcd3c4..110be34 100644 --- a/lib/image_editor_plus.dart +++ b/lib/image_editor_plus.dart @@ -193,7 +193,6 @@ class _MultiImageEditorState extends State { return Theme( data: ImageEditor.theme, child: Scaffold( - key: scaffoldGlobalKey, appBar: AppBar( automaticallyImplyLeading: false, actions: [ @@ -479,12 +478,12 @@ class _SingleImageEditorState extends State { resetTransformation(); setState(() {}); - loadingScreen.show(); + LoadingScreen.show(context); var binaryIntList = await screenshotController.capture(pixelRatio: pixelRatio); - loadingScreen.hide(); + LoadingScreen.hide(context); if (mounted) Navigator.pop(context, binaryIntList); }, @@ -601,7 +600,6 @@ class _SingleImageEditorState extends State { return Theme( data: ImageEditor.theme, child: Scaffold( - key: scaffoldGlobalKey, body: Stack(children: [ GestureDetector( onScaleUpdate: (details) { @@ -745,9 +743,9 @@ class _SingleImageEditorState extends State { text: i18n('Crop'), onTap: () async { resetTransformation(); - LoadingScreen(scaffoldGlobalKey).show(); + LoadingScreen.show(context); var mergedImage = await getMergedImage(); - LoadingScreen(scaffoldGlobalKey).hide(); + LoadingScreen.hide(context); if (!mounted) return; @@ -804,9 +802,9 @@ class _SingleImageEditorState extends State { } } else { resetTransformation(); - LoadingScreen(scaffoldGlobalKey).show(); + LoadingScreen.show(context); var mergedImage = await getMergedImage(); - LoadingScreen(scaffoldGlobalKey).hide(); + LoadingScreen.hide(context); if (!mounted) return; @@ -1081,9 +1079,9 @@ class _SingleImageEditorState extends State { // } // } - LoadingScreen(scaffoldGlobalKey).show(); + LoadingScreen.show(context); var mergedImage = await getMergedImage(); - LoadingScreen(scaffoldGlobalKey).hide(); + LoadingScreen.hide(context); if (!mounted) return; @@ -1503,9 +1501,9 @@ class _ImageFiltersState extends State { padding: const EdgeInsets.symmetric(horizontal: 8), icon: const Icon(Icons.check), onPressed: () async { - loadingScreen.show(); + LoadingScreen.show(context); var data = await screenshotController.capture(); - loadingScreen.hide(); + LoadingScreen.hide(context); if (mounted) Navigator.pop(context, data); }, @@ -1851,9 +1849,9 @@ class _ImageEditorDrawingState extends State { return Navigator.pop(context, data!.buffer.asUint8List()); } - loadingScreen.show(); + LoadingScreen.show(context); var image = await screenshotController.capture(); - loadingScreen.hide(); + LoadingScreen.hide(context); if (!mounted) return; diff --git a/lib/loading_screen.dart b/lib/loading_screen.dart index caf63e5..ab120a8 100644 --- a/lib/loading_screen.dart +++ b/lib/loading_screen.dart @@ -1,15 +1,10 @@ import 'package:flutter/material.dart'; class LoadingScreen { - final GlobalKey globalKey; - - LoadingScreen(this.globalKey); - - show([String? text]) { - if (globalKey.currentContext == null) return; + static show(BuildContext currentContext, [String? text]) { showDialog( - context: globalKey.currentContext!, + context: currentContext, builder: (BuildContext context) => const Scaffold( backgroundColor: Color.fromRGBO(0, 0, 0, 0), body: Center( @@ -27,15 +22,7 @@ class LoadingScreen { ); } - hide() { - if (globalKey.currentContext == null) return; - - Navigator.pop(globalKey.currentContext!); + static hide(BuildContext currentContext) { + Navigator.pop(currentContext); } } - -@protected -final scaffoldGlobalKey = GlobalKey(); - -@protected -var loadingScreen = LoadingScreen(scaffoldGlobalKey);