refactor dialog

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-03-24 15:21:14 +08:00
parent 308d336b20
commit 8ebfd3f628
42 changed files with 671 additions and 476 deletions

View File

@ -1,10 +1,18 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import '../../common.dart';
import '../../models/model.dart';
import '../../models/platform_model.dart';
void clientClose(String id, OverlayDialogManager dialogManager) {
msgBox(id, 'info', 'Close', 'Are you sure to close the connection?', '',
dialogManager);
}
abstract class ValidationRule {
String get name;
bool validate(String value);
@ -290,3 +298,541 @@ Future<String> changeDirectAccessPort(
});
return controller.text;
}
class DialogTextField extends StatelessWidget {
final String title;
final String? hintText;
final bool obscureText;
final String? errorText;
final String? helperText;
final Widget? prefixIcon;
final Widget? suffixIcon;
final TextEditingController controller;
final FocusNode? focusNode;
static const kUsernameTitle = 'Username';
static const kUsernameIcon = Icon(Icons.account_circle_outlined);
static const kPasswordTitle = 'Password';
static const kPasswordIcon = Icon(Icons.lock_outline);
DialogTextField(
{Key? key,
this.focusNode,
this.obscureText = false,
this.errorText,
this.helperText,
this.prefixIcon,
this.suffixIcon,
this.hintText,
required this.title,
required this.controller})
: super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
child: TextField(
decoration: InputDecoration(
labelText: title,
hintText: hintText,
prefixIcon: prefixIcon,
suffixIcon: suffixIcon,
helperText: helperText,
helperMaxLines: 8,
errorText: errorText,
),
controller: controller,
focusNode: focusNode,
autofocus: true,
obscureText: obscureText,
),
),
],
).paddingSymmetric(vertical: 4.0);
}
}
class PasswordWidget extends StatefulWidget {
PasswordWidget({
Key? key,
required this.controller,
this.autoFocus = true,
this.hintText,
this.errorText,
}) : super(key: key);
final TextEditingController controller;
final bool autoFocus;
final String? hintText;
final String? errorText;
@override
State<PasswordWidget> createState() => _PasswordWidgetState();
}
class _PasswordWidgetState extends State<PasswordWidget> {
bool _passwordVisible = false;
final _focusNode = FocusNode();
Timer? _timer;
@override
void initState() {
super.initState();
if (widget.autoFocus) {
_timer =
Timer(Duration(milliseconds: 50), () => _focusNode.requestFocus());
}
}
@override
void dispose() {
_timer?.cancel();
_focusNode.unfocus();
_focusNode.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return DialogTextField(
title: translate(DialogTextField.kPasswordTitle),
hintText: translate(widget.hintText ?? 'Enter your password'),
controller: widget.controller,
prefixIcon: DialogTextField.kPasswordIcon,
suffixIcon: IconButton(
icon: Icon(
// Based on passwordVisible state choose the icon
_passwordVisible ? Icons.visibility : Icons.visibility_off,
color: MyTheme.lightTheme.primaryColor),
onPressed: () {
// Update the state i.e. toggle the state of passwordVisible variable
setState(() {
_passwordVisible = !_passwordVisible;
});
},
),
obscureText: !_passwordVisible,
errorText: widget.errorText,
focusNode: _focusNode,
);
}
}
void wrongPasswordDialog(
String id, OverlayDialogManager dialogManager, type, title, text) {
dialogManager.dismissAll();
dialogManager.show((setState, close) {
cancel() {
close();
closeConnection();
}
submit() {
enterPasswordDialog(id, dialogManager);
}
return CustomAlertDialog(
title: null,
content: msgboxContent(type, title, text),
onSubmit: submit,
onCancel: cancel,
actions: [
dialogButton(
'Cancel',
onPressed: cancel,
isOutline: true,
),
dialogButton(
'Retry',
onPressed: submit,
),
]);
});
}
void enterPasswordDialog(String id, OverlayDialogManager dialogManager) async {
await _connectDialog(
id,
dialogManager,
peerPasswordController: TextEditingController(),
);
}
void enterUserLoginDialog(String id, OverlayDialogManager dialogManager) async {
await _connectDialog(
id,
dialogManager,
usernameController: TextEditingController(),
passwordController: TextEditingController(),
);
}
void enterUserLoginAndPasswordDialog(
String id, OverlayDialogManager dialogManager) async {
await _connectDialog(
id,
dialogManager,
usernameController: TextEditingController(),
passwordController: TextEditingController(),
peerPasswordController: TextEditingController(),
);
}
_connectDialog(
String id,
OverlayDialogManager dialogManager, {
TextEditingController? usernameController,
TextEditingController? passwordController,
TextEditingController? peerPasswordController,
}) async {
var remember = await bind.sessionGetRemember(id: id) ?? false;
dialogManager.dismissAll();
dialogManager.show((setState, close) {
cancel() {
close();
closeConnection();
}
submit() {
final username = usernameController?.text.trim() ?? '';
final password = passwordController?.text.trim() ?? '';
final peerPassword = peerPasswordController?.text.trim() ?? '';
if (peerPasswordController != null && peerPassword.isEmpty) return;
gFFI.login(
// username,
// password,
id,
peerPassword,
remember,
);
close();
dialogManager.showLoading(translate('Logging in...'),
onCancel: closeConnection);
}
return CustomAlertDialog(
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.password_rounded, color: MyTheme.accent),
Text(translate(usernameController == null
? 'Password Required'
: 'Login Required'))
.paddingOnly(left: 10),
],
),
content: Column(mainAxisSize: MainAxisSize.min, children: [
usernameController == null
? Offstage()
: DialogTextField(
title: translate(DialogTextField.kUsernameTitle),
controller: usernameController,
prefixIcon: DialogTextField.kUsernameIcon,
errorText: null,
),
passwordController == null
? Offstage()
: PasswordWidget(
controller: passwordController,
autoFocus: false,
),
peerPasswordController == null
? Offstage()
: PasswordWidget(
controller: peerPasswordController,
autoFocus: usernameController == null,
hintText: 'Enter RustDesk password',
),
peerPasswordController == null
? Offstage()
: CheckboxListTile(
contentPadding: const EdgeInsets.all(0),
dense: true,
controlAffinity: ListTileControlAffinity.leading,
title: Text(
translate('Remember RustDesk password'),
),
value: remember,
onChanged: (v) {
if (v != null) {
setState(() => remember = v);
}
},
),
]),
actions: [
dialogButton(
'Cancel',
icon: Icon(Icons.close_rounded),
onPressed: cancel,
isOutline: true,
),
dialogButton(
'OK',
icon: Icon(Icons.done_rounded),
onPressed: submit,
),
],
onSubmit: submit,
onCancel: cancel,
);
});
}
void showWaitUacDialog(
String id, OverlayDialogManager dialogManager, String type) {
dialogManager.dismissAll();
dialogManager.show(
tag: '$id-wait-uac',
(setState, close) => CustomAlertDialog(
title: null,
content: msgboxContent(type, 'Wait', 'wait_accept_uac_tip'),
));
}
// Another username && password dialog?
void showRequestElevationDialog(String id, OverlayDialogManager dialogManager) {
RxString groupValue = ''.obs;
RxString errUser = ''.obs;
RxString errPwd = ''.obs;
TextEditingController userController = TextEditingController();
TextEditingController pwdController = TextEditingController();
void onRadioChanged(String? value) {
if (value != null) {
groupValue.value = value;
}
}
const minTextStyle = TextStyle(fontSize: 14);
var content = Obx(() => Column(children: [
Row(
children: [
Radio(
value: '',
groupValue: groupValue.value,
onChanged: onRadioChanged),
Expanded(
child:
Text(translate('Ask the remote user for authentication'))),
],
),
Align(
alignment: Alignment.centerLeft,
child: Text(
translate(
'Choose this if the remote account is administrator'),
style: TextStyle(fontSize: 13))
.marginOnly(left: 40),
).marginOnly(bottom: 15),
Row(
children: [
Radio(
value: 'logon',
groupValue: groupValue.value,
onChanged: onRadioChanged),
Expanded(
child: Text(translate(
'Transmit the username and password of administrator')),
)
],
),
Row(
children: [
Expanded(
flex: 1,
child: Text(
'${translate('Username')}:',
style: minTextStyle,
).marginOnly(right: 10)),
Expanded(
flex: 3,
child: TextField(
controller: userController,
style: minTextStyle,
decoration: InputDecoration(
isDense: true,
contentPadding: EdgeInsets.symmetric(vertical: 15),
hintText: translate('eg: admin'),
errorText: errUser.isEmpty ? null : errUser.value),
onChanged: (s) {
if (s.isNotEmpty) {
errUser.value = '';
}
},
),
)
],
).marginOnly(left: 40),
Row(
children: [
Expanded(
flex: 1,
child: Text(
'${translate('Password')}:',
style: minTextStyle,
).marginOnly(right: 10)),
Expanded(
flex: 3,
child: TextField(
controller: pwdController,
obscureText: true,
style: minTextStyle,
decoration: InputDecoration(
isDense: true,
contentPadding: EdgeInsets.symmetric(vertical: 15),
errorText: errPwd.isEmpty ? null : errPwd.value),
onChanged: (s) {
if (s.isNotEmpty) {
errPwd.value = '';
}
},
),
),
],
).marginOnly(left: 40),
Align(
alignment: Alignment.centerLeft,
child: Text(translate('still_click_uac_tip'),
style: TextStyle(fontSize: 13, fontWeight: FontWeight.bold))
.marginOnly(top: 20)),
]));
dialogManager.dismissAll();
dialogManager.show(tag: '$id-request-elevation', (setState, close) {
void submit() {
if (groupValue.value == 'logon') {
if (userController.text.isEmpty) {
errUser.value = translate('Empty Username');
return;
}
if (pwdController.text.isEmpty) {
errPwd.value = translate('Empty Password');
return;
}
bind.sessionElevateWithLogon(
id: id,
username: userController.text,
password: pwdController.text);
} else {
bind.sessionElevateDirect(id: id);
}
}
return CustomAlertDialog(
title: Text(translate('Request Elevation')),
content: content,
actions: [
dialogButton('Cancel', onPressed: close, isOutline: true),
dialogButton('OK', onPressed: submit),
],
onSubmit: submit,
onCancel: close,
);
});
}
void showOnBlockDialog(
String id,
String type,
String title,
String text,
OverlayDialogManager dialogManager,
) {
if (dialogManager.existing('$id-wait-uac') ||
dialogManager.existing('$id-request-elevation')) {
return;
}
dialogManager.show(tag: '$id-$type', (setState, close) {
void submit() {
close();
showRequestElevationDialog(id, dialogManager);
}
return CustomAlertDialog(
title: null,
content: msgboxContent(type, title,
"${translate(text)}${type.contains('uac') ? '\n' : '\n\n'}${translate('request_elevation_tip')}"),
actions: [
dialogButton('Wait', onPressed: close, isOutline: true),
dialogButton('Request Elevation', onPressed: submit),
],
onSubmit: submit,
onCancel: close,
);
});
}
void showElevationError(String id, String type, String title, String text,
OverlayDialogManager dialogManager) {
dialogManager.show(tag: '$id-$type', (setState, close) {
void submit() {
close();
showRequestElevationDialog(id, dialogManager);
}
return CustomAlertDialog(
title: null,
content: msgboxContent(type, title, text),
actions: [
dialogButton('Cancel', onPressed: () {
close();
}, isOutline: true),
dialogButton('Retry', onPressed: submit),
],
onSubmit: submit,
onCancel: close,
);
});
}
void showWaitAcceptDialog(String id, String type, String title, String text,
OverlayDialogManager dialogManager) {
dialogManager.dismissAll();
dialogManager.show((setState, close) {
onCancel() {
closeConnection();
}
return CustomAlertDialog(
title: null,
content: msgboxContent(type, title, text),
actions: [
dialogButton('Cancel', onPressed: onCancel, isOutline: true),
],
onCancel: onCancel,
);
});
}
void showRestartRemoteDevice(
PeerInfo pi, String id, OverlayDialogManager dialogManager) async {
final res =
await dialogManager.show<bool>((setState, close) => CustomAlertDialog(
title: Row(children: [
Icon(Icons.warning_rounded, color: Colors.redAccent, size: 28),
Text(translate("Restart Remote Device")).paddingOnly(left: 10),
]),
content: Text(
"${translate('Are you sure you want to restart')} \n${pi.username}@${pi.hostname}($id) ?"),
actions: [
dialogButton(
"Cancel",
icon: Icon(Icons.close_rounded),
onPressed: close,
isOutline: true,
),
dialogButton(
"OK",
icon: Icon(Icons.done_rounded),
onPressed: () => close(true),
),
],
onCancel: close,
onSubmit: () => close(true),
));
if (res == true) bind.sessionRestartRemoteDevice(id: id);
}

View File

@ -9,6 +9,7 @@ import 'package:flutter_svg/flutter_svg.dart';
import 'package:url_launcher/url_launcher.dart';
import '../../common.dart';
import './dialog.dart';
class _IconOP extends StatelessWidget {
final String icon;
@ -324,17 +325,16 @@ class LoginWidgetUserPass extends StatelessWidget {
children: [
const SizedBox(height: 8.0),
DialogTextField(
title: translate("Username"),
title: translate(DialogTextField.kUsernameTitle),
controller: username,
focusNode: userFocusNode,
prefixIcon: Icon(Icons.account_circle_outlined),
prefixIcon: DialogTextField.kUsernameIcon,
errorText: usernameMsg),
DialogTextField(
title: translate("Password"),
obscureText: true,
controller: pass,
prefixIcon: Icon(Icons.lock_outline),
errorText: passMsg),
PasswordWidget(
controller: pass,
autoFocus: false,
errorText: passMsg,
),
Obx(() => CheckboxListTile(
contentPadding: const EdgeInsets.all(0),
dense: true,
@ -377,49 +377,6 @@ class LoginWidgetUserPass extends StatelessWidget {
}
}
class DialogTextField extends StatelessWidget {
final String title;
final bool obscureText;
final String? errorText;
final String? helperText;
final Widget? prefixIcon;
final TextEditingController controller;
final FocusNode? focusNode;
DialogTextField(
{Key? key,
this.focusNode,
this.obscureText = false,
this.errorText,
this.helperText,
this.prefixIcon,
required this.title,
required this.controller})
: super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
child: TextField(
decoration: InputDecoration(
labelText: title,
prefixIcon: prefixIcon,
helperText: helperText,
helperMaxLines: 8,
errorText: errorText),
controller: controller,
focusNode: focusNode,
autofocus: true,
obscureText: obscureText,
),
),
],
).paddingSymmetric(vertical: 4.0);
}
}
/// common login dialog for desktop
/// call this directly
Future<bool?> loginDialog() async {

View File

@ -19,6 +19,8 @@ import '../../common/widgets/peer_tab_page.dart';
import '../../models/platform_model.dart';
import '../widgets/button.dart';
import 'package:flutter_hbb/common/widgets/dialog.dart';
/// Connection page for connecting to a remote peer.
class ConnectionPage extends StatefulWidget {
const ConnectionPage({Key? key}) : super(key: key);

View File

@ -17,7 +17,7 @@ import '../../consts.dart';
import '../../common/widgets/overlay.dart';
import '../../common/widgets/remote_input.dart';
import '../../common.dart';
import '../../mobile/widgets/dialog.dart';
import '../../common/widgets/dialog.dart';
import '../../models/model.dart';
import '../../models/platform_model.dart';
import '../../common/shared_state.dart';

View File

@ -16,7 +16,7 @@ import 'package:desktop_multi_window/desktop_multi_window.dart';
import 'package:window_size/window_size.dart' as window_size;
import '../../common.dart';
import '../../mobile/widgets/dialog.dart';
import '../../common/widgets/dialog.dart';
import '../../models/model.dart';
import '../../models/platform_model.dart';
import '../../common/shared_state.dart';

View File

@ -8,7 +8,7 @@ import 'package:toggle_switch/toggle_switch.dart';
import 'package:wakelock/wakelock.dart';
import '../../common.dart';
import '../widgets/dialog.dart';
import '../../common/widgets/dialog.dart';
class FileManagerPage extends StatefulWidget {
FileManagerPage({Key? key, required this.id}) : super(key: key);

View File

@ -14,6 +14,7 @@ import 'package:wakelock/wakelock.dart';
import '../../common.dart';
import '../../common/widgets/overlay.dart';
import '../../common/widgets/dialog.dart';
import '../../common/widgets/remote_input.dart';
import '../../models/input_model.dart';
import '../../models/model.dart';

View File

@ -4,51 +4,16 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../common.dart';
import '../../models/model.dart';
import '../../models/platform_model.dart';
void clientClose(String id, OverlayDialogManager dialogManager) {
msgBox(id, 'info', 'Close', 'Are you sure to close the connection?', '',
dialogManager);
}
void showSuccess() {
void _showSuccess() {
showToast(translate("Successful"));
}
void showError() {
void _showError() {
showToast(translate("Error"));
}
void showRestartRemoteDevice(
PeerInfo pi, String id, OverlayDialogManager dialogManager) async {
final res =
await dialogManager.show<bool>((setState, close) => CustomAlertDialog(
title: Row(children: [
Icon(Icons.warning_rounded, color: Colors.redAccent, size: 28),
Text(translate("Restart Remote Device")).paddingOnly(left: 10),
]),
content: Text(
"${translate('Are you sure you want to restart')} \n${pi.username}@${pi.hostname}($id) ?"),
actions: [
dialogButton(
"Cancel",
icon: Icon(Icons.close_rounded),
onPressed: close,
isOutline: true,
),
dialogButton(
"OK",
icon: Icon(Icons.done_rounded),
onPressed: () => close(true),
),
],
onCancel: close,
onSubmit: () => close(true),
));
if (res == true) bind.sessionRestartRemoteDevice(id: id);
}
void setPermanentPasswordDialog(OverlayDialogManager dialogManager) async {
final pw = await bind.mainGetPermanentPassword();
final p0 = TextEditingController(text: pw);
@ -61,10 +26,10 @@ void setPermanentPasswordDialog(OverlayDialogManager dialogManager) async {
dialogManager.showLoading(translate("Waiting"));
if (await gFFI.serverModel.setPermanentPassword(p0.text)) {
dialogManager.dismissAll();
showSuccess();
_showSuccess();
} else {
dialogManager.dismissAll();
showError();
_showError();
}
}
@ -157,7 +122,7 @@ void setTemporaryPasswordLengthDialog(
bind.mainUpdateTemporaryPassword();
Future.delayed(Duration(milliseconds: 200), () {
close();
showSuccess();
_showSuccess();
});
}
@ -173,101 +138,6 @@ void setTemporaryPasswordLengthDialog(
}, backDismiss: true, clickMaskDismiss: true);
}
void enterPasswordDialog(String id, OverlayDialogManager dialogManager) async {
final controller = TextEditingController();
var remember = await bind.sessionGetRemember(id: id) ?? false;
dialogManager.dismissAll();
dialogManager.show((setState, close) {
cancel() {
close();
closeConnection();
}
submit() {
var text = controller.text.trim();
if (text == '') return;
gFFI.login(id, text, remember);
close();
dialogManager.showLoading(translate('Logging in...'),
onCancel: closeConnection);
}
return CustomAlertDialog(
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.password_rounded, color: MyTheme.accent),
Text(translate('Password Required')).paddingOnly(left: 10),
],
),
content: Column(mainAxisSize: MainAxisSize.min, children: [
PasswordWidget(controller: controller),
CheckboxListTile(
contentPadding: const EdgeInsets.all(0),
dense: true,
controlAffinity: ListTileControlAffinity.leading,
title: Text(
translate('Remember password'),
),
value: remember,
onChanged: (v) {
if (v != null) {
setState(() => remember = v);
}
},
),
]),
actions: [
dialogButton(
'Cancel',
icon: Icon(Icons.close_rounded),
onPressed: cancel,
isOutline: true,
),
dialogButton(
'OK',
icon: Icon(Icons.done_rounded),
onPressed: submit,
),
],
onSubmit: submit,
onCancel: cancel,
);
});
}
void wrongPasswordDialog(
String id, OverlayDialogManager dialogManager, type, title, text) {
dialogManager.dismissAll();
dialogManager.show((setState, close) {
cancel() {
close();
closeConnection();
}
submit() {
enterPasswordDialog(id, dialogManager);
}
return CustomAlertDialog(
title: null,
content: msgboxContent(type, title, text),
onSubmit: submit,
onCancel: cancel,
actions: [
dialogButton(
'Cancel',
onPressed: cancel,
isOutline: true,
),
dialogButton(
'Retry',
onPressed: submit,
),
]);
});
}
void showServerSettingsWithValue(
ServerConfig serverConfig, OverlayDialogManager dialogManager) async {
Map<String, dynamic> oldOptions = jsonDecode(await bind.mainGetOptions());
@ -393,232 +263,6 @@ void showServerSettingsWithValue(
});
}
void showWaitUacDialog(
String id, OverlayDialogManager dialogManager, String type) {
dialogManager.dismissAll();
dialogManager.show(
tag: '$id-wait-uac',
(setState, close) => CustomAlertDialog(
title: null,
content: msgboxContent(type, 'Wait', 'wait_accept_uac_tip'),
));
}
void showRequestElevationDialog(String id, OverlayDialogManager dialogManager) {
RxString groupValue = ''.obs;
RxString errUser = ''.obs;
RxString errPwd = ''.obs;
TextEditingController userController = TextEditingController();
TextEditingController pwdController = TextEditingController();
void onRadioChanged(String? value) {
if (value != null) {
groupValue.value = value;
}
}
const minTextStyle = TextStyle(fontSize: 14);
var content = Obx(() => Column(children: [
Row(
children: [
Radio(
value: '',
groupValue: groupValue.value,
onChanged: onRadioChanged),
Expanded(
child:
Text(translate('Ask the remote user for authentication'))),
],
),
Align(
alignment: Alignment.centerLeft,
child: Text(
translate(
'Choose this if the remote account is administrator'),
style: TextStyle(fontSize: 13))
.marginOnly(left: 40),
).marginOnly(bottom: 15),
Row(
children: [
Radio(
value: 'logon',
groupValue: groupValue.value,
onChanged: onRadioChanged),
Expanded(
child: Text(translate(
'Transmit the username and password of administrator')),
)
],
),
Row(
children: [
Expanded(
flex: 1,
child: Text(
'${translate('Username')}:',
style: minTextStyle,
).marginOnly(right: 10)),
Expanded(
flex: 3,
child: TextField(
controller: userController,
style: minTextStyle,
decoration: InputDecoration(
isDense: true,
contentPadding: EdgeInsets.symmetric(vertical: 15),
hintText: translate('eg: admin'),
errorText: errUser.isEmpty ? null : errUser.value),
onChanged: (s) {
if (s.isNotEmpty) {
errUser.value = '';
}
},
),
)
],
).marginOnly(left: 40),
Row(
children: [
Expanded(
flex: 1,
child: Text(
'${translate('Password')}:',
style: minTextStyle,
).marginOnly(right: 10)),
Expanded(
flex: 3,
child: TextField(
controller: pwdController,
obscureText: true,
style: minTextStyle,
decoration: InputDecoration(
isDense: true,
contentPadding: EdgeInsets.symmetric(vertical: 15),
errorText: errPwd.isEmpty ? null : errPwd.value),
onChanged: (s) {
if (s.isNotEmpty) {
errPwd.value = '';
}
},
),
),
],
).marginOnly(left: 40),
Align(
alignment: Alignment.centerLeft,
child: Text(translate('still_click_uac_tip'),
style: TextStyle(fontSize: 13, fontWeight: FontWeight.bold))
.marginOnly(top: 20)),
]));
dialogManager.dismissAll();
dialogManager.show(tag: '$id-request-elevation', (setState, close) {
void submit() {
if (groupValue.value == 'logon') {
if (userController.text.isEmpty) {
errUser.value = translate('Empty Username');
return;
}
if (pwdController.text.isEmpty) {
errPwd.value = translate('Empty Password');
return;
}
bind.sessionElevateWithLogon(
id: id,
username: userController.text,
password: pwdController.text);
} else {
bind.sessionElevateDirect(id: id);
}
}
return CustomAlertDialog(
title: Text(translate('Request Elevation')),
content: content,
actions: [
dialogButton('Cancel', onPressed: close, isOutline: true),
dialogButton('OK', onPressed: submit),
],
onSubmit: submit,
onCancel: close,
);
});
}
void showOnBlockDialog(
String id,
String type,
String title,
String text,
OverlayDialogManager dialogManager,
) {
if (dialogManager.existing('$id-wait-uac') ||
dialogManager.existing('$id-request-elevation')) {
return;
}
dialogManager.show(tag: '$id-$type', (setState, close) {
void submit() {
close();
showRequestElevationDialog(id, dialogManager);
}
return CustomAlertDialog(
title: null,
content: msgboxContent(type, title,
"${translate(text)}${type.contains('uac') ? '\n' : '\n\n'}${translate('request_elevation_tip')}"),
actions: [
dialogButton('Wait', onPressed: close, isOutline: true),
dialogButton('Request Elevation', onPressed: submit),
],
onSubmit: submit,
onCancel: close,
);
});
}
void showElevationError(String id, String type, String title, String text,
OverlayDialogManager dialogManager) {
dialogManager.show(tag: '$id-$type', (setState, close) {
void submit() {
close();
showRequestElevationDialog(id, dialogManager);
}
return CustomAlertDialog(
title: null,
content: msgboxContent(type, title, text),
actions: [
dialogButton('Cancel', onPressed: () {
close();
}, isOutline: true),
dialogButton('Retry', onPressed: submit),
],
onSubmit: submit,
onCancel: close,
);
});
}
void showWaitAcceptDialog(String id, String type, String title, String text,
OverlayDialogManager dialogManager) {
dialogManager.dismissAll();
dialogManager.show((setState, close) {
onCancel() {
closeConnection();
}
return CustomAlertDialog(
title: null,
content: msgboxContent(type, title, text),
actions: [
dialogButton('Cancel', onPressed: onCancel, isOutline: true),
],
onCancel: onCancel,
);
});
}
Future<String?> validateAsync(String value) async {
value = value.trim();
if (value.isEmpty) {
@ -627,62 +271,3 @@ Future<String?> validateAsync(String value) async {
final res = await bind.mainTestIfValidServer(server: value);
return res.isEmpty ? null : res;
}
class PasswordWidget extends StatefulWidget {
PasswordWidget({Key? key, required this.controller, this.autoFocus = true})
: super(key: key);
final TextEditingController controller;
final bool autoFocus;
@override
State<PasswordWidget> createState() => _PasswordWidgetState();
}
class _PasswordWidgetState extends State<PasswordWidget> {
bool _passwordVisible = false;
final _focusNode = FocusNode();
@override
void initState() {
super.initState();
if (widget.autoFocus) {
Timer(Duration(milliseconds: 50), () => _focusNode.requestFocus());
}
}
@override
void dispose() {
_focusNode.unfocus();
_focusNode.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return TextField(
focusNode: _focusNode,
controller: widget.controller,
obscureText: !_passwordVisible,
//This will obscure text dynamically
keyboardType: TextInputType.visiblePassword,
decoration: InputDecoration(
labelText: translate('Password'),
hintText: translate('Enter your password'),
// Here is key idea
suffixIcon: IconButton(
icon: Icon(
// Based on passwordVisible state choose the icon
_passwordVisible ? Icons.visibility : Icons.visibility_off,
color: MyTheme.lightTheme.primaryColor),
onPressed: () {
// Update the state i.e. toggle the state of passwordVisible variable
setState(() {
_passwordVisible = !_passwordVisible;
});
},
),
),
);
}
}

View File

@ -25,7 +25,7 @@ import 'package:get/get.dart';
import '../common.dart';
import '../utils/image.dart' as img;
import '../mobile/widgets/dialog.dart';
import '../common/widgets/dialog.dart';
import 'input_model.dart';
import 'platform_model.dart';
@ -293,6 +293,11 @@ class FfiModel with ChangeNotifier {
wrongPasswordDialog(id, dialogManager, type, title, text);
} else if (type == 'input-password') {
enterPasswordDialog(id, dialogManager);
} else if (type == 'xsession-login' || type == 'xsession-re-login') {
// to-do
} else if (type == 'xsession-login-password' ||
type == 'xsession-login-password') {
// to-do
} else if (type == 'restarting') {
showMsgBox(id, type, title, text, link, false, dialogManager,
hasCancel: false);

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", ""),
("show_monitors_tip", ""),
("View Mode", ""),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", "此文件与对方的一致"),
("show_monitors_tip", ""),
("View Mode", "浏览模式"),
("Enter RustDesk password", "请输入RustDesk密码"),
("Remember RustDesk password", "记住RustDesk密码"),
("Login Required", "需要登陆"),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", ""),
("show_monitors_tip", ""),
("View Mode", ""),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", ""),
("show_monitors_tip", ""),
("View Mode", ""),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", "Diese Datei ist identisch mit der Datei der Gegenstelle."),
("show_monitors_tip", "Monitore in der Symbolleiste anzeigen"),
("View Mode", "Ansichtsmodus"),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", "Το αρχείο είναι πανομοιότυπο με αυτό του άλλου υπολογιστή."),
("show_monitors_tip", "Εμφάνιση οθονών στη γραμμή εργαλείων"),
("View Mode", "Λειτουργία προβολής"),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", ""),
("show_monitors_tip", ""),
("View Mode", ""),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", "Este archivo es idéntico al del par."),
("show_monitors_tip", "Mostrar monitores en la barra de herramientas"),
("View Mode", "Modo Vista"),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", "این فایل با فایل همتا یکسان است."),
("show_monitors_tip", "نمایش مانیتورها در نوار ابزار"),
("View Mode", ""),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", ""),
("show_monitors_tip", ""),
("View Mode", ""),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", ""),
("show_monitors_tip", ""),
("View Mode", ""),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", ""),
("show_monitors_tip", ""),
("View Mode", ""),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", "Questo file è identico a quello del peer."),
("show_monitors_tip", "Mostra schermi nella barra degli strumenti"),
("View Mode", "Modalità di visualizzazione"),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", ""),
("show_monitors_tip", ""),
("View Mode", ""),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", ""),
("show_monitors_tip", ""),
("View Mode", ""),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", ""),
("show_monitors_tip", ""),
("View Mode", ""),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", ""),
("show_monitors_tip", ""),
("View Mode", ""),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", ""),
("show_monitors_tip", ""),
("View Mode", ""),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", ""),
("show_monitors_tip", ""),
("View Mode", ""),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", ""),
("show_monitors_tip", ""),
("View Mode", ""),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", ""),
("show_monitors_tip", ""),
("View Mode", ""),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", "Файл идентичен файлу на удалённом узле."),
("show_monitors_tip", "Показывать мониторы на панели инструментов"),
("View Mode", "Режим просмотра"),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", ""),
("show_monitors_tip", ""),
("View Mode", ""),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", ""),
("show_monitors_tip", ""),
("View Mode", ""),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", ""),
("show_monitors_tip", ""),
("View Mode", ""),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", ""),
("show_monitors_tip", ""),
("View Mode", ""),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", ""),
("show_monitors_tip", ""),
("View Mode", ""),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", ""),
("show_monitors_tip", ""),
("View Mode", ""),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", ""),
("show_monitors_tip", ""),
("View Mode", ""),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", ""),
("show_monitors_tip", ""),
("View Mode", ""),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", "此檔案與對方的檔案一致"),
("show_monitors_tip", "在工具列中顯示顯示器"),
("View Mode", "瀏覽模式"),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", ""),
("show_monitors_tip", ""),
("View Mode", ""),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}

View File

@ -480,5 +480,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("identical_file_tip", ""),
("show_monitors_tip", ""),
("View Mode", ""),
("Enter RustDesk password", ""),
("Remember RustDesk password", ""),
("Login Required", ""),
].iter().cloned().collect();
}