From 9dadd76a8d1a5e5ee686c1ded521843d1203e443 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Thu, 24 Mar 2022 21:23:22 +0800 Subject: [PATCH] barrierDismissible and onWillPop --- lib/common.dart | 4 +- lib/pages/settings_page.dart | 120 +++++++++++++++++------------------ 2 files changed, 60 insertions(+), 64 deletions(-) diff --git a/lib/common.dart b/lib/common.dart index ae2694cd6..cf8c455a9 100644 --- a/lib/common.dart +++ b/lib/common.dart @@ -59,7 +59,7 @@ class DialogManager { static void reset([result]) { if (_dialogContext != null) { - Navigator.pop(_dialogContext!,result); + Navigator.pop(_dialogContext!, result); } _dialogContext = null; } @@ -83,7 +83,7 @@ class DialogManager { builder: (context) { DialogManager.register(context); return StatefulBuilder( - builder: (_, setState) => builder(setState,DialogManager.reset)); + builder: (_, setState) => builder(setState, DialogManager.reset)); }); DialogManager.drop(); return res; diff --git a/lib/pages/settings_page.dart b/lib/pages/settings_page.dart index 0e369c1d1..8773726df 100644 --- a/lib/pages/settings_page.dart +++ b/lib/pages/settings_page.dart @@ -71,21 +71,21 @@ void showServer() { var key = ''; DialogManager.show((setState, close) { return CustomAlertDialog( - title: Text(translate('ID Server')), - content: Form( - key: formKey, - child: Column(mainAxisSize: MainAxisSize.min, children: [ - TextFormField( - initialValue: id0, - decoration: InputDecoration( - labelText: translate('ID Server'), - ), - validator: validate, - onSaved: (String? value) { - if (value != null) id = value.trim(); - }, + title: Text(translate('ID Server')), + content: Form( + key: formKey, + child: Column(mainAxisSize: MainAxisSize.min, children: [ + TextFormField( + initialValue: id0, + decoration: InputDecoration( + labelText: translate('ID Server'), ), - /* + validator: validate, + onSaved: (String? value) { + if (value != null) id = value.trim(); + }, + ), + /* TextFormField( initialValue: relay0, decoration: InputDecoration( @@ -97,46 +97,50 @@ void showServer() { }, ), */ - TextFormField( - initialValue: key0, - decoration: InputDecoration( - labelText: 'Key', - ), - validator: null, - onSaved: (String? value) { - if (value != null) key = value.trim(); - }, + TextFormField( + initialValue: key0, + decoration: InputDecoration( + labelText: 'Key', ), - ])), - actions: [ - TextButton( - style: flatButtonStyle, - onPressed: () { + validator: null, + onSaved: (String? value) { + if (value != null) key = value.trim(); + }, + ), + ])), + actions: [ + TextButton( + style: flatButtonStyle, + onPressed: () { + close(); + }, + child: Text(translate('Cancel')), + ), + TextButton( + style: flatButtonStyle, + onPressed: () { + if (formKey.currentState != null && + formKey.currentState!.validate()) { + formKey.currentState!.save(); + if (id != id0) + FFI.setByName('option', + '{"name": "custom-rendezvous-server", "value": "$id"}'); + if (relay != relay0) + FFI.setByName( + 'option', '{"name": "relay-server", "value": "$relay"}'); + if (key != key0) + FFI.setByName('option', '{"name": "key", "value": "$key"}'); close(); - }, - child: Text(translate('Cancel')), - ), - TextButton( - style: flatButtonStyle, - onPressed: () { - if (formKey.currentState != null && - formKey.currentState!.validate()) { - formKey.currentState!.save(); - if (id != id0) - FFI.setByName('option', - '{"name": "custom-rendezvous-server", "value": "$id"}'); - if (relay != relay0) - FFI.setByName( - 'option', '{"name": "relay-server", "value": "$relay"}'); - if (key != key0) - FFI.setByName('option', '{"name": "key", "value": "$key"}'); - close(); - } - }, - child: Text(translate('OK')), - ), - ]); - }); + } + }, + child: Text(translate('OK')), + ), + ], + onWillPop: () async { + return true; + }, + ); + }, barrierDismissible: true); } String? validate(value) { @@ -169,18 +173,10 @@ void showAbout() { )), )), ]), - actions: [ - TextButton( - style: flatButtonStyle, - onPressed: () { - close(); - }, - child: Text(translate('OK')), - ) - ], + actions: [], onWillPop: () async { return true; }, ); - }); + }, barrierDismissible: true); }