back to home/ alert pop safety
This commit is contained in:
parent
2247147b7b
commit
5aba802c80
@ -39,8 +39,13 @@ void showLoading(String text) {
|
|||||||
EasyLoading.show(status: text, maskType: EasyLoadingMaskType.black);
|
EasyLoading.show(status: text, maskType: EasyLoadingMaskType.black);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
backToHome() {
|
||||||
|
// use [popUntil()] to make sure pop action can't close the current MaterialApp context
|
||||||
|
Navigator.popUntil(globalKey.currentContext!, ModalRoute.withName("/"));
|
||||||
|
}
|
||||||
|
|
||||||
typedef DialogBuilder = CustomAlertDialog Function(
|
typedef DialogBuilder = CustomAlertDialog Function(
|
||||||
BuildContext context, StateSetter setState);
|
StateSetter setState, VoidCallback close);
|
||||||
|
|
||||||
class DialogManager {
|
class DialogManager {
|
||||||
static BuildContext? _dialogContext;
|
static BuildContext? _dialogContext;
|
||||||
@ -70,7 +75,8 @@ class DialogManager {
|
|||||||
barrierDismissible: barrierDismissible,
|
barrierDismissible: barrierDismissible,
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
DialogManager.register(context);
|
DialogManager.register(context);
|
||||||
return StatefulBuilder(builder: builder);
|
return StatefulBuilder(
|
||||||
|
builder: (_, setState) => builder(setState, DialogManager.reset));
|
||||||
});
|
});
|
||||||
DialogManager.drop();
|
DialogManager.drop();
|
||||||
return res;
|
return res;
|
||||||
@ -121,12 +127,11 @@ void msgBox(String type, String title, String text, {bool? hasCancel}) {
|
|||||||
|
|
||||||
EasyLoading.dismiss();
|
EasyLoading.dismiss();
|
||||||
DialogManager.reset();
|
DialogManager.reset();
|
||||||
if (globalKey.currentContext == null) return;
|
|
||||||
final buttons = [
|
final buttons = [
|
||||||
Expanded(child: Container()),
|
Expanded(child: Container()),
|
||||||
wrap(Translator.call('OK'), () {
|
wrap(Translator.call('OK'), () {
|
||||||
EasyLoading.dismiss();
|
EasyLoading.dismiss();
|
||||||
Navigator.pop(globalKey.currentContext!);
|
backToHome();
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
if (hasCancel == null) {
|
if (hasCancel == null) {
|
||||||
|
@ -39,9 +39,6 @@ class App extends StatelessWidget {
|
|||||||
visualDensity: VisualDensity.adaptivePlatformDensity,
|
visualDensity: VisualDensity.adaptivePlatformDensity,
|
||||||
),
|
),
|
||||||
home: HomePage(),
|
home: HomePage(),
|
||||||
routes: {
|
|
||||||
"server_page": (context) => ServerPage(),
|
|
||||||
},
|
|
||||||
navigatorObservers: [
|
navigatorObservers: [
|
||||||
FirebaseAnalyticsObserver(analytics: analytics),
|
FirebaseAnalyticsObserver(analytics: analytics),
|
||||||
],
|
],
|
||||||
|
@ -104,7 +104,7 @@ class FileModel extends ChangeNotifier {
|
|||||||
} else {
|
} else {
|
||||||
_currentRemoteDir = fileDir;
|
_currentRemoteDir = fileDir;
|
||||||
}
|
}
|
||||||
notifyListeners();
|
notifyListeners(); // TODO use too early, error occur:setState() or markNeedsBuild() called during build.
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint("Failed to tryUpdateDir :$fd");
|
debugPrint("Failed to tryUpdateDir :$fd");
|
||||||
}
|
}
|
||||||
@ -156,7 +156,8 @@ class FileModel extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
items.items.forEach((entry) {
|
items.items.forEach((entry) {
|
||||||
_jobId++;
|
_jobId++;
|
||||||
if (entry.isFile) { // TODO dir
|
if (entry.isFile) {
|
||||||
|
// TODO dir
|
||||||
final msg = {
|
final msg = {
|
||||||
"id": _jobId.toString(),
|
"id": _jobId.toString(),
|
||||||
"path": entry.path,
|
"path": entry.path,
|
||||||
@ -170,9 +171,7 @@ class FileModel extends ChangeNotifier {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
createDir(String path){
|
createDir(String path) {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
changeSortStyle(SortBy sort) {
|
changeSortStyle(SortBy sort) {
|
||||||
_sortStyle = sort;
|
_sortStyle = sort;
|
||||||
|
@ -778,8 +778,6 @@ class ImagePainter extends CustomPainter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CheckboxListTile getToggle(
|
CheckboxListTile getToggle(
|
||||||
void Function(void Function()) setState, option, name) {
|
void Function(void Function()) setState, option, name) {
|
||||||
return CheckboxListTile(
|
return CheckboxListTile(
|
||||||
@ -848,7 +846,7 @@ void showOptions() {
|
|||||||
}
|
}
|
||||||
final perms = FFI.ffiModel.permissions;
|
final perms = FFI.ffiModel.permissions;
|
||||||
|
|
||||||
DialogManager.show((context, setState) {
|
DialogManager.show((setState, close) {
|
||||||
final more = <Widget>[];
|
final more = <Widget>[];
|
||||||
if (perms['audio'] != false) {
|
if (perms['audio'] != false) {
|
||||||
more.add(getToggle(setState, 'disable-audio', 'Mute'));
|
more.add(getToggle(setState, 'disable-audio', 'Mute'));
|
||||||
@ -885,8 +883,7 @@ void showOptions() {
|
|||||||
children: displays +
|
children: displays +
|
||||||
(isDesktop
|
(isDesktop
|
||||||
? <Widget>[
|
? <Widget>[
|
||||||
getRadio(
|
getRadio('Original', 'original', viewStyle, setViewStyle),
|
||||||
'Original', 'original', viewStyle, setViewStyle),
|
|
||||||
getRadio('Shrink', 'shrink', viewStyle, setViewStyle),
|
getRadio('Shrink', 'shrink', viewStyle, setViewStyle),
|
||||||
getRadio('Stretch', 'stretch', viewStyle, setViewStyle),
|
getRadio('Stretch', 'stretch', viewStyle, setViewStyle),
|
||||||
Divider(color: MyTheme.border),
|
Divider(color: MyTheme.border),
|
||||||
@ -895,11 +892,9 @@ void showOptions() {
|
|||||||
<Widget>[
|
<Widget>[
|
||||||
getRadio('Good image quality', 'best', quality, setQuality),
|
getRadio('Good image quality', 'best', quality, setQuality),
|
||||||
getRadio('Balanced', 'balanced', quality, setQuality),
|
getRadio('Balanced', 'balanced', quality, setQuality),
|
||||||
getRadio(
|
getRadio('Optimize reaction time', 'low', quality, setQuality),
|
||||||
'Optimize reaction time', 'low', quality, setQuality),
|
|
||||||
Divider(color: MyTheme.border),
|
Divider(color: MyTheme.border),
|
||||||
getToggle(
|
getToggle(setState, 'show-remote-cursor', 'Show remote cursor'),
|
||||||
setState, 'show-remote-cursor', 'Show remote cursor'),
|
|
||||||
] +
|
] +
|
||||||
more),
|
more),
|
||||||
actions: [],
|
actions: [],
|
||||||
@ -914,7 +909,7 @@ void showSetOSPassword(bool login) {
|
|||||||
var password = FFI.getByName('peer_option', "os-password");
|
var password = FFI.getByName('peer_option', "os-password");
|
||||||
var autoLogin = FFI.getByName('peer_option', "auto-login") != "";
|
var autoLogin = FFI.getByName('peer_option', "auto-login") != "";
|
||||||
controller.text = password;
|
controller.text = password;
|
||||||
DialogManager.show((context, setState) {
|
DialogManager.show((setState, close) {
|
||||||
return CustomAlertDialog(
|
return CustomAlertDialog(
|
||||||
title: Text(translate('OS Password')),
|
title: Text(translate('OS Password')),
|
||||||
content: Column(mainAxisSize: MainAxisSize.min, children: [
|
content: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||||
@ -937,7 +932,7 @@ void showSetOSPassword(bool login) {
|
|||||||
TextButton(
|
TextButton(
|
||||||
style: flatButtonStyle,
|
style: flatButtonStyle,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.pop(context);
|
close();
|
||||||
},
|
},
|
||||||
child: Text(translate('Cancel')),
|
child: Text(translate('Cancel')),
|
||||||
),
|
),
|
||||||
@ -952,7 +947,7 @@ void showSetOSPassword(bool login) {
|
|||||||
if (text != "" && login) {
|
if (text != "" && login) {
|
||||||
FFI.setByName('input_os_password', text);
|
FFI.setByName('input_os_password', text);
|
||||||
}
|
}
|
||||||
Navigator.pop(context);
|
close();
|
||||||
},
|
},
|
||||||
child: Text(translate('OK')),
|
child: Text(translate('OK')),
|
||||||
),
|
),
|
||||||
|
@ -69,7 +69,7 @@ void showServer() {
|
|||||||
var id = '';
|
var id = '';
|
||||||
var relay = '';
|
var relay = '';
|
||||||
var key = '';
|
var key = '';
|
||||||
DialogManager.show((context, setState) {
|
DialogManager.show((setState, close) {
|
||||||
return CustomAlertDialog(
|
return CustomAlertDialog(
|
||||||
title: Text(translate('ID Server')),
|
title: Text(translate('ID Server')),
|
||||||
content: Form(
|
content: Form(
|
||||||
@ -112,7 +112,7 @@ void showServer() {
|
|||||||
TextButton(
|
TextButton(
|
||||||
style: flatButtonStyle,
|
style: flatButtonStyle,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
DialogManager.reset();
|
close();
|
||||||
},
|
},
|
||||||
child: Text(translate('Cancel')),
|
child: Text(translate('Cancel')),
|
||||||
),
|
),
|
||||||
@ -130,7 +130,7 @@ void showServer() {
|
|||||||
'option', '{"name": "relay-server", "value": "$relay"}');
|
'option', '{"name": "relay-server", "value": "$relay"}');
|
||||||
if (key != key0)
|
if (key != key0)
|
||||||
FFI.setByName('option', '{"name": "key", "value": "$key"}');
|
FFI.setByName('option', '{"name": "key", "value": "$key"}');
|
||||||
DialogManager.reset();
|
close();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Text(translate('OK')),
|
child: Text(translate('OK')),
|
||||||
|
@ -9,7 +9,7 @@ void clientClose() {
|
|||||||
void enterPasswordDialog(String id) {
|
void enterPasswordDialog(String id) {
|
||||||
final controller = TextEditingController();
|
final controller = TextEditingController();
|
||||||
var remember = FFI.getByName('remember', id) == 'true';
|
var remember = FFI.getByName('remember', id) == 'true';
|
||||||
DialogManager.show((context, setState) {
|
DialogManager.show((setState, close) {
|
||||||
return CustomAlertDialog(
|
return CustomAlertDialog(
|
||||||
title: Text(translate('Password Required')),
|
title: Text(translate('Password Required')),
|
||||||
content: Column(mainAxisSize: MainAxisSize.min, children: [
|
content: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||||
@ -34,8 +34,8 @@ void enterPasswordDialog(String id) {
|
|||||||
TextButton(
|
TextButton(
|
||||||
style: flatButtonStyle,
|
style: flatButtonStyle,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
DialogManager.reset();
|
close();
|
||||||
Navigator.pop(globalKey.currentContext!);
|
backToHome();
|
||||||
},
|
},
|
||||||
child: Text(translate('Cancel')),
|
child: Text(translate('Cancel')),
|
||||||
),
|
),
|
||||||
@ -45,7 +45,7 @@ void enterPasswordDialog(String id) {
|
|||||||
var text = controller.text.trim();
|
var text = controller.text.trim();
|
||||||
if (text == '') return;
|
if (text == '') return;
|
||||||
FFI.login(text, remember);
|
FFI.login(text, remember);
|
||||||
DialogManager.reset();
|
close();
|
||||||
showLoading(translate('Logging in...'));
|
showLoading(translate('Logging in...'));
|
||||||
},
|
},
|
||||||
child: Text(translate('OK')),
|
child: Text(translate('OK')),
|
||||||
@ -56,15 +56,15 @@ void enterPasswordDialog(String id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void wrongPasswordDialog(String id) {
|
void wrongPasswordDialog(String id) {
|
||||||
DialogManager.show((context, setState) => CustomAlertDialog(
|
DialogManager.show((setState, close) => CustomAlertDialog(
|
||||||
title: Text(translate('Wrong Password')),
|
title: Text(translate('Wrong Password')),
|
||||||
content: Text(translate('Do you want to enter again?')),
|
content: Text(translate('Do you want to enter again?')),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
style: flatButtonStyle,
|
style: flatButtonStyle,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
DialogManager.reset();
|
close();
|
||||||
Navigator.pop(globalKey.currentContext!);
|
backToHome();
|
||||||
},
|
},
|
||||||
child: Text(translate('Cancel')),
|
child: Text(translate('Cancel')),
|
||||||
),
|
),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user