rustdesk/lib/widgets/dialog.dart

122 lines
3.5 KiB
Dart
Raw Normal View History

2022-03-07 22:54:34 +08:00
import 'package:flutter/material.dart';
import '../common.dart';
import '../models/model.dart';
void clientClose() {
msgBox('', 'Close', 'Are you sure to close the connection?');
}
void enterPasswordDialog(String id) {
final controller = TextEditingController();
var remember = FFI.getByName('remember', id) == 'true';
2022-03-13 23:07:52 +08:00
DialogManager.show((setState, close) {
2022-03-13 00:32:44 +08:00
return CustomAlertDialog(
title: Text(translate('Password Required')),
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) {
debugPrint("onChanged");
if (v != null) {
setState(() => remember = v);
}
},
2022-03-07 22:54:34 +08:00
),
2022-03-13 00:32:44 +08:00
]),
actions: [
2022-03-07 22:54:34 +08:00
TextButton(
style: flatButtonStyle,
onPressed: () {
2022-03-13 23:07:52 +08:00
close();
backToHome();
2022-03-07 22:54:34 +08:00
},
child: Text(translate('Cancel')),
),
TextButton(
style: flatButtonStyle,
onPressed: () {
2022-03-13 00:32:44 +08:00
var text = controller.text.trim();
if (text == '') return;
FFI.login(text, remember);
2022-03-13 23:07:52 +08:00
close();
2022-03-13 00:32:44 +08:00
showLoading(translate('Logging in...'));
2022-03-07 22:54:34 +08:00
},
2022-03-13 00:32:44 +08:00
child: Text(translate('OK')),
2022-03-07 22:54:34 +08:00
),
2022-03-13 00:32:44 +08:00
],
);
});
}
void wrongPasswordDialog(String id) {
2022-03-13 23:07:52 +08:00
DialogManager.show((setState, close) => CustomAlertDialog(
2022-03-13 00:32:44 +08:00
title: Text(translate('Wrong Password')),
content: Text(translate('Do you want to enter again?')),
actions: [
TextButton(
style: flatButtonStyle,
onPressed: () {
2022-03-13 23:07:52 +08:00
close();
backToHome();
2022-03-13 00:32:44 +08:00
},
child: Text(translate('Cancel')),
),
TextButton(
style: flatButtonStyle,
onPressed: () {
enterPasswordDialog(id);
},
child: Text(translate('Retry')),
),
]));
}
class PasswordWidget extends StatefulWidget {
PasswordWidget({Key? key, required this.controller}) : super(key: key);
final TextEditingController controller;
@override
_PasswordWidgetState createState() => _PasswordWidgetState();
}
class _PasswordWidgetState extends State<PasswordWidget> {
bool _passwordVisible = false;
@override
Widget build(BuildContext context) {
return TextField(
autofocus: true,
controller: widget.controller,
obscureText: !_passwordVisible,
//This will obscure text dynamically
keyboardType: TextInputType.visiblePassword,
decoration: InputDecoration(
labelText: Translator.call('Password'),
hintText: Translator.call('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: Theme.of(context).primaryColorDark,
),
onPressed: () {
// Update the state i.e. toogle the state of passwordVisible variable
setState(() {
_passwordVisible = !_passwordVisible;
});
},
),
),
);
}
}