From 0ba74ef7ecc95049b3cebaf0ec3ac8bfa1c08f2e Mon Sep 17 00:00:00 2001 From: open-trade Date: Wed, 18 Nov 2020 12:49:43 +0800 Subject: [PATCH] fix on login and config --- flutter_hbb/lib/common.dart | 52 +++++++++++++++++++++++++++------- flutter_hbb/lib/home_page.dart | 7 +---- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/flutter_hbb/lib/common.dart b/flutter_hbb/lib/common.dart index 24f391794..faa62fe64 100644 --- a/flutter_hbb/lib/common.dart +++ b/flutter_hbb/lib/common.dart @@ -165,6 +165,7 @@ class Peer { // https://github.com/huangjianke/flutter_easyloading void showLoading(String text) { + dismissLoading(); EasyLoading.show(status: text); } @@ -173,17 +174,24 @@ void dismissLoading() { } void showSuccess(String text) { + dismissLoading(); EasyLoading.showSuccess(text); } +bool _hasDialog = false; + // https://material.io/develop/flutter/components/dialogs -void enterPasswordDialog(String id, BuildContext context) { +Future enterPasswordDialog(String id, BuildContext context) async { dismissLoading(); + if (_hasDialog) { + Navigator.pop(context); + } + _hasDialog = true; final controller = TextEditingController(); var remember = FFI.getByName('remember', arg: id) == 'true'; var dialog = AlertDialog( title: Text('Please enter your password'), - contentPadding: EdgeInsets.zero, + contentPadding: const EdgeInsets.all(20.0), content: Column( mainAxisSize: MainAxisSize.min, children: [ @@ -230,19 +238,30 @@ void enterPasswordDialog(String id, BuildContext context) { ), ], ); - showDialog(context: context, builder: (context) => dialog); + await showDialog( + context: context, + barrierDismissible: false, + builder: (context) => dialog); + _hasDialog = false; } -void wrongPasswordDialog(String id, BuildContext context) { +Future wrongPasswordDialog(String id, BuildContext context) async { dismissLoading(); + if (_hasDialog) { + Navigator.pop(context); + } + _hasDialog = true; var dialog = AlertDialog( title: Text('Wrong Password'), - contentPadding: EdgeInsets.zero, + contentPadding: const EdgeInsets.all(20.0), content: Text('Do you want to enter again?'), actions: [ FlatButton( textColor: MyTheme.accent, - onPressed: () => Navigator.pop(context), + onPressed: () { + Navigator.pop(context); + Navigator.pop(context); + }, child: Text('Cancel'), ), FlatButton( @@ -255,14 +274,23 @@ void wrongPasswordDialog(String id, BuildContext context) { ), ], ); - showDialog(context: context, builder: (context) => dialog); + await showDialog( + context: context, + barrierDismissible: false, + builder: (context) => dialog); + _hasDialog = false; } -void msgbox(String type, String title, String text, BuildContext context) { +Future msgbox( + String type, String title, String text, BuildContext context) async { dismissLoading(); + if (_hasDialog) { + Navigator.pop(context); + } + _hasDialog = true; var dialog = AlertDialog( title: Text(title), - contentPadding: EdgeInsets.zero, + contentPadding: const EdgeInsets.all(20.0), content: Text(text), actions: [ FlatButton( @@ -275,5 +303,9 @@ void msgbox(String type, String title, String text, BuildContext context) { ), ], ); - showDialog(context: context, builder: (context) => dialog); + await showDialog( + context: context, + barrierDismissible: false, + builder: (context) => dialog); + _hasDialog = false; } diff --git a/flutter_hbb/lib/home_page.dart b/flutter_hbb/lib/home_page.dart index d6a36b5a4..a04198e15 100644 --- a/flutter_hbb/lib/home_page.dart +++ b/flutter_hbb/lib/home_page.dart @@ -15,15 +15,10 @@ class HomePage extends StatefulWidget { class _HomePageState extends State { final _idController = TextEditingController(); - @override - void initState() { - super.initState(); - _idController.text = FFI.getId(); - } - @override Widget build(BuildContext context) { Provider.of(context); + if (_idController.text.isEmpty) _idController.text = FFI.getId(); // This method is rerun every time setState is called return Scaffold( appBar: AppBar(