From 715d837f5424b99a21ef1866ec3d764f7f4de693 Mon Sep 17 00:00:00 2001 From: csf Date: Sun, 9 Oct 2022 19:57:38 +0900 Subject: [PATCH] logOut show loading --- flutter/lib/common.dart | 26 +++++++++++++++----------- flutter/lib/models/user_model.dart | 5 ++--- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index 2ff3d4477..ce341d160 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -383,22 +383,23 @@ class OverlayDialogManager { "[OverlayDialogManager] Failed to show dialog, _overlayState is null, call [setOverlayState] first"); } - final _tag; + final String dialogTag; if (tag != null) { - _tag = tag; + dialogTag = tag; } else { - _tag = _tagCount.toString(); + dialogTag = _tagCount.toString(); _tagCount++; } final dialog = Dialog(); - _dialogs[_tag] = dialog; + _dialogs[dialogTag] = dialog; - final close = ([res]) { - _dialogs.remove(_tag); + close([res]) { + _dialogs.remove(dialogTag); dialog.complete(res); - BackButtonInterceptor.removeByName(_tag); - }; + BackButtonInterceptor.removeByName(dialogTag); + } + dialog.entry = OverlayEntry(builder: (_) { bool innerClicked = false; return Listener( @@ -423,14 +424,16 @@ class OverlayDialogManager { close(); } return true; - }, name: _tag); + }, name: dialogTag); return dialog.completer.future; } - void showLoading(String text, + String showLoading(String text, {bool clickMaskDismiss = false, bool showCancel = true, VoidCallback? onCancel}) { + final tag = _tagCount.toString(); + _tagCount++; show((setState, close) { cancel() { dismissAll(); @@ -465,7 +468,8 @@ class OverlayDialogManager { ])), onCancel: showCancel ? cancel : null, ); - }); + }, tag: tag); + return tag; } void resetMobileActionsOverlay({FFI? ffi}) { diff --git a/flutter/lib/models/user_model.dart b/flutter/lib/models/user_model.dart index e9990efa9..163efaebc 100644 --- a/flutter/lib/models/user_model.dart +++ b/flutter/lib/models/user_model.dart @@ -1,7 +1,6 @@ import 'dart:async'; import 'dart:convert'; -import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:http/http.dart' as http; @@ -83,8 +82,7 @@ class UserModel { } Future logOut() async { - // TODO show toast - debugPrint("start logout"); + final tag = gFFI.dialogManager.showLoading(translate('Waiting')); final url = await bind.mainGetApiServer(); final _ = await http.post(Uri.parse("$url/api/logout"), body: { @@ -99,6 +97,7 @@ class UserModel { ]); parent.target?.abModel.clear(); userName.value = ""; + gFFI.dialogManager.dismissByTag(tag); } Future> login(String userName, String pass) async {