Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate globalKey detected error #70

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions lib/image_editor_plus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ class _MultiImageEditorState extends State<MultiImageEditor> {
return Theme(
data: ImageEditor.theme,
child: Scaffold(
key: scaffoldGlobalKey,
appBar: AppBar(
automaticallyImplyLeading: false,
actions: [
Expand Down Expand Up @@ -479,12 +478,12 @@ class _SingleImageEditorState extends State<SingleImageEditor> {
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);
},
Expand Down Expand Up @@ -601,7 +600,6 @@ class _SingleImageEditorState extends State<SingleImageEditor> {
return Theme(
data: ImageEditor.theme,
child: Scaffold(
key: scaffoldGlobalKey,
body: Stack(children: [
GestureDetector(
onScaleUpdate: (details) {
Expand Down Expand Up @@ -745,9 +743,9 @@ class _SingleImageEditorState extends State<SingleImageEditor> {
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;

Expand Down Expand Up @@ -804,9 +802,9 @@ class _SingleImageEditorState extends State<SingleImageEditor> {
}
} else {
resetTransformation();
LoadingScreen(scaffoldGlobalKey).show();
LoadingScreen.show(context);
var mergedImage = await getMergedImage();
LoadingScreen(scaffoldGlobalKey).hide();
LoadingScreen.hide(context);

if (!mounted) return;

Expand Down Expand Up @@ -1081,9 +1079,9 @@ class _SingleImageEditorState extends State<SingleImageEditor> {
// }
// }

LoadingScreen(scaffoldGlobalKey).show();
LoadingScreen.show(context);
var mergedImage = await getMergedImage();
LoadingScreen(scaffoldGlobalKey).hide();
LoadingScreen.hide(context);

if (!mounted) return;

Expand Down Expand Up @@ -1503,9 +1501,9 @@ class _ImageFiltersState extends State<ImageFilters> {
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);
},
Expand Down Expand Up @@ -1851,9 +1849,9 @@ class _ImageEditorDrawingState extends State<ImageEditorDrawing> {
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;

Expand Down
21 changes: 4 additions & 17 deletions lib/loading_screen.dart
Original file line number Diff line number Diff line change
@@ -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<String>(
context: globalKey.currentContext!,
context: currentContext,
builder: (BuildContext context) => const Scaffold(
backgroundColor: Color.fromRGBO(0, 0, 0, 0),
body: Center(
Expand All @@ -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<ScaffoldState>();

@protected
var loadingScreen = LoadingScreen(scaffoldGlobalKey);