refactor dialog;refactor dir structure
This commit is contained in:
parent
3318fb0471
commit
2247147b7b
160
lib/common.dart
160
lib/common.dart
@ -1,7 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
|
||||||
|
|
||||||
final globalKey = GlobalKey<NavigatorState>();
|
final globalKey = GlobalKey<NavigatorState>();
|
||||||
|
|
||||||
@ -40,61 +39,73 @@ void showLoading(String text) {
|
|||||||
EasyLoading.show(status: text, maskType: EasyLoadingMaskType.black);
|
EasyLoading.show(status: text, maskType: EasyLoadingMaskType.black);
|
||||||
}
|
}
|
||||||
|
|
||||||
class DialogManager{
|
typedef DialogBuilder = CustomAlertDialog Function(
|
||||||
|
BuildContext context, StateSetter setState);
|
||||||
|
|
||||||
|
class DialogManager {
|
||||||
static BuildContext? _dialogContext;
|
static BuildContext? _dialogContext;
|
||||||
|
|
||||||
static void reset(){
|
static void reset() {
|
||||||
if(_dialogContext!=null){
|
if (_dialogContext != null) {
|
||||||
Navigator.pop(_dialogContext!);
|
Navigator.pop(_dialogContext!);
|
||||||
}
|
}
|
||||||
_dialogContext = null;
|
_dialogContext = null;
|
||||||
}
|
}
|
||||||
static void register(BuildContext dialogContext){
|
|
||||||
|
static void register(BuildContext dialogContext) {
|
||||||
_dialogContext = dialogContext;
|
_dialogContext = dialogContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void drop(){
|
static void drop() {
|
||||||
_dialogContext = null;
|
_dialogContext = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<T?> show<T>(DialogBuilder builder,
|
||||||
|
{bool barrierDismissible = false}) async {
|
||||||
|
if (globalKey.currentContext == null) return null;
|
||||||
|
EasyLoading.dismiss();
|
||||||
|
DialogManager.reset();
|
||||||
|
final res = await showDialog<T>(
|
||||||
|
context: globalKey.currentContext!,
|
||||||
|
barrierDismissible: barrierDismissible,
|
||||||
|
builder: (context) {
|
||||||
|
DialogManager.register(context);
|
||||||
|
return StatefulBuilder(builder: builder);
|
||||||
|
});
|
||||||
|
DialogManager.drop();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef BuildAlertDialog = Tuple3<Widget, Widget, List<Widget>> Function(
|
class CustomAlertDialog extends StatelessWidget {
|
||||||
void Function(void Function()));
|
CustomAlertDialog(
|
||||||
|
{required this.title,
|
||||||
|
required this.content,
|
||||||
|
required this.actions,
|
||||||
|
this.onWillPop,
|
||||||
|
this.contentPadding});
|
||||||
|
|
||||||
// flutter Dialog
|
final Widget title;
|
||||||
Future<T?> showAlertDialog<T>(BuildAlertDialog build,
|
final Widget content;
|
||||||
[WillPopCallback? onWillPop,
|
final List<Widget> actions;
|
||||||
bool barrierDismissible = false,
|
final WillPopCallback? onWillPop;
|
||||||
double contentPadding = 20]) async {
|
final double? contentPadding;
|
||||||
EasyLoading.dismiss();
|
|
||||||
DialogManager.reset();
|
@override
|
||||||
var dialog = StatefulBuilder(builder: (context, setState) {
|
Widget build(BuildContext context) {
|
||||||
var widgets = build(setState);
|
|
||||||
if (onWillPop == null) onWillPop = () async => false;
|
|
||||||
return WillPopScope(
|
return WillPopScope(
|
||||||
onWillPop: onWillPop,
|
onWillPop: onWillPop ?? () async => false,
|
||||||
child: AlertDialog(
|
child: AlertDialog(
|
||||||
title: widgets.item1,
|
title: title,
|
||||||
contentPadding: EdgeInsets.all(contentPadding),
|
contentPadding: EdgeInsets.all(contentPadding ?? 20),
|
||||||
content: widgets.item2,
|
content: content,
|
||||||
actions: widgets.item3,
|
actions: actions,
|
||||||
));
|
));
|
||||||
});
|
}
|
||||||
if(globalKey.currentContext == null) return null;
|
|
||||||
var res = await showDialog<T>(
|
|
||||||
context: globalKey.currentContext!,
|
|
||||||
barrierDismissible: barrierDismissible,
|
|
||||||
builder: (context) {
|
|
||||||
DialogManager.register(context);
|
|
||||||
return dialog;
|
|
||||||
});
|
|
||||||
DialogManager.drop();
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// EasyLoading
|
// EasyLoading
|
||||||
void msgBox(String type, String title, String text,
|
void msgBox(String type, String title, String text, {bool? hasCancel}) {
|
||||||
{bool? hasCancel}) {
|
|
||||||
var wrap = (String text, void Function() onPressed) => ButtonTheme(
|
var wrap = (String text, void Function() onPressed) => ButtonTheme(
|
||||||
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
||||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||||
@ -110,7 +121,7 @@ void msgBox(String type, String title, String text,
|
|||||||
|
|
||||||
EasyLoading.dismiss();
|
EasyLoading.dismiss();
|
||||||
DialogManager.reset();
|
DialogManager.reset();
|
||||||
if(globalKey.currentContext == null) return;
|
if (globalKey.currentContext == null) return;
|
||||||
final buttons = [
|
final buttons = [
|
||||||
Expanded(child: Container()),
|
Expanded(child: Container()),
|
||||||
wrap(Translator.call('OK'), () {
|
wrap(Translator.call('OK'), () {
|
||||||
@ -129,65 +140,22 @@ void msgBox(String type, String title, String text,
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
EasyLoading.show(
|
EasyLoading.show(
|
||||||
status: "",
|
status: "",
|
||||||
maskType: EasyLoadingMaskType.black,
|
maskType: EasyLoadingMaskType.black,
|
||||||
indicator: Container(
|
indicator: Container(
|
||||||
constraints: BoxConstraints(maxWidth: 300),
|
constraints: BoxConstraints(maxWidth: 300),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(Translator.call(title), style: TextStyle(fontSize: 21)),
|
Text(Translator.call(title), style: TextStyle(fontSize: 21)),
|
||||||
SizedBox(height: 20),
|
SizedBox(height: 20),
|
||||||
Text(Translator.call(text), style: TextStyle(fontSize: 15)),
|
Text(Translator.call(text), style: TextStyle(fontSize: 15)),
|
||||||
SizedBox(height: 20),
|
SizedBox(height: 20),
|
||||||
Row(
|
Row(
|
||||||
children: buttons,
|
children: buttons,
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
))
|
)));
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Color str2color(String str, [alpha = 0xFF]) {
|
Color str2color(String str, [alpha = 0xFF]) {
|
||||||
|
@ -54,12 +54,6 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
getSearchBarUI(),
|
getSearchBarUI(),
|
||||||
Container(height: 12),
|
Container(height: 12),
|
||||||
getPeers(),
|
getPeers(),
|
||||||
ElevatedButton(
|
|
||||||
onPressed: () {
|
|
||||||
final res = FFI.getByName("read_dir");
|
|
||||||
debugPrint("read_dir : $res");
|
|
||||||
},
|
|
||||||
child: Text("Local File Debug"))
|
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -69,7 +63,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
connect(id);
|
connect(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void connect(String id,{bool isFileTransfer = false}) {
|
void connect(String id, {bool isFileTransfer = false}) {
|
||||||
if (id == '') return;
|
if (id == '') return;
|
||||||
id = id.replaceAll(' ', '');
|
id = id.replaceAll(' ', '');
|
||||||
if (isFileTransfer) {
|
if (isFileTransfer) {
|
||||||
@ -79,7 +73,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
builder: (BuildContext context) => FileManagerPage(id: id),
|
builder: (BuildContext context) => FileManagerPage(id: id),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}else{
|
} else {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
@ -271,8 +265,8 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
() async {
|
() async {
|
||||||
removePreference(id);
|
removePreference(id);
|
||||||
}();
|
}();
|
||||||
}else if (value == 'file') {
|
} else if (value == 'file') {
|
||||||
connect(id,isFileTransfer: true);
|
connect(id, isFileTransfer: true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,9 @@ import 'package:provider/provider.dart';
|
|||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'dart:ui' as ui;
|
import 'dart:ui' as ui;
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:tuple/tuple.dart';
|
|
||||||
import 'package:wakelock/wakelock.dart';
|
import 'package:wakelock/wakelock.dart';
|
||||||
import '../common.dart';
|
import '../common.dart';
|
||||||
import '../gestures.dart';
|
import '../widgets/gestures.dart';
|
||||||
import '../models/model.dart';
|
import '../models/model.dart';
|
||||||
import '../widgets/dialog.dart';
|
import '../widgets/dialog.dart';
|
||||||
import 'chat_page.dart';
|
import 'chat_page.dart';
|
||||||
@ -289,7 +288,7 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
icon: Icon(Icons.tv),
|
icon: Icon(Icons.tv),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
setState(() => _showEdit = false);
|
setState(() => _showEdit = false);
|
||||||
showOptions(context);
|
showOptions();
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
] +
|
] +
|
||||||
@ -318,7 +317,7 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
icon: Icon(Icons.more_vert),
|
icon: Icon(Icons.more_vert),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
setState(() => _showEdit = false);
|
setState(() => _showEdit = false);
|
||||||
showActions(context);
|
showActions();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
@ -475,7 +474,7 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
color: MyTheme.canvasColor, child: Stack(children: paints)));
|
color: MyTheme.canvasColor, child: Stack(children: paints)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void showActions(BuildContext context) {
|
void showActions() {
|
||||||
final size = MediaQuery.of(context).size;
|
final size = MediaQuery.of(context).size;
|
||||||
final x = 120.0;
|
final x = 120.0;
|
||||||
final y = size.height;
|
final y = size.height;
|
||||||
@ -494,7 +493,7 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
style: flatButtonStyle,
|
style: flatButtonStyle,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
showSetOSPassword(context, false);
|
showSetOSPassword(false);
|
||||||
},
|
},
|
||||||
child: Icon(Icons.edit, color: MyTheme.accent),
|
child: Icon(Icons.edit, color: MyTheme.accent),
|
||||||
)
|
)
|
||||||
@ -553,7 +552,7 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
if (password != "") {
|
if (password != "") {
|
||||||
FFI.setByName('input_os_password', password);
|
FFI.setByName('input_os_password', password);
|
||||||
} else {
|
} else {
|
||||||
showSetOSPassword(context, true);
|
showSetOSPassword(true);
|
||||||
}
|
}
|
||||||
} else if (value == 'reset_canvas') {
|
} else if (value == 'reset_canvas') {
|
||||||
FFI.cursorModel.reset();
|
FFI.cursorModel.reset();
|
||||||
@ -806,7 +805,7 @@ RadioListTile<String> getRadio(String name, String toValue, String curValue,
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void showOptions(BuildContext context) {
|
void showOptions() {
|
||||||
String quality = FFI.getByName('image_quality');
|
String quality = FFI.getByName('image_quality');
|
||||||
if (quality == '') quality = 'balanced';
|
if (quality == '') quality = 'balanced';
|
||||||
String viewStyle = FFI.getByName('peer_option', 'view-style');
|
String viewStyle = FFI.getByName('peer_option', 'view-style');
|
||||||
@ -824,7 +823,7 @@ void showOptions(BuildContext context) {
|
|||||||
onTap: () {
|
onTap: () {
|
||||||
if (i == cur) return;
|
if (i == cur) return;
|
||||||
FFI.setByName('switch_display', i.toString());
|
FFI.setByName('switch_display', i.toString());
|
||||||
Navigator.pop(context);
|
DialogManager.reset();
|
||||||
},
|
},
|
||||||
child: Ink(
|
child: Ink(
|
||||||
width: 40,
|
width: 40,
|
||||||
@ -848,7 +847,8 @@ void showOptions(BuildContext context) {
|
|||||||
displays.add(Divider(color: MyTheme.border));
|
displays.add(Divider(color: MyTheme.border));
|
||||||
}
|
}
|
||||||
final perms = FFI.ffiModel.permissions;
|
final perms = FFI.ffiModel.permissions;
|
||||||
showAlertDialog((setState) {
|
|
||||||
|
DialogManager.show((context, setState) {
|
||||||
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'));
|
||||||
@ -878,19 +878,19 @@ void showOptions(BuildContext context) {
|
|||||||
FFI.canvasModel.updateViewStyle();
|
FFI.canvasModel.updateViewStyle();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
return Tuple3(
|
return CustomAlertDialog(
|
||||||
SizedBox.shrink(),
|
title: SizedBox.shrink(),
|
||||||
Column(
|
content: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
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),
|
||||||
]
|
]
|
||||||
: []) +
|
: []) +
|
||||||
<Widget>[
|
<Widget>[
|
||||||
getRadio('Good image quality', 'best', quality, setQuality),
|
getRadio('Good image quality', 'best', quality, setQuality),
|
||||||
@ -902,18 +902,22 @@ void showOptions(BuildContext context) {
|
|||||||
setState, 'show-remote-cursor', 'Show remote cursor'),
|
setState, 'show-remote-cursor', 'Show remote cursor'),
|
||||||
] +
|
] +
|
||||||
more),
|
more),
|
||||||
[]);
|
actions: [],
|
||||||
}, () async => true, true, 0);
|
onWillPop: () async => true,
|
||||||
|
contentPadding: 0,
|
||||||
|
);
|
||||||
|
},barrierDismissible: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void showSetOSPassword(BuildContext context, bool login) {
|
void showSetOSPassword(bool login) {
|
||||||
final controller = TextEditingController();
|
final controller = TextEditingController();
|
||||||
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;
|
||||||
showAlertDialog((setState) => Tuple3(
|
DialogManager.show((context, setState) {
|
||||||
Text(translate('OS Password')),
|
return CustomAlertDialog(
|
||||||
Column(mainAxisSize: MainAxisSize.min, children: [
|
title: Text(translate('OS Password')),
|
||||||
|
content: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||||
PasswordWidget(controller: controller),
|
PasswordWidget(controller: controller),
|
||||||
CheckboxListTile(
|
CheckboxListTile(
|
||||||
contentPadding: const EdgeInsets.all(0),
|
contentPadding: const EdgeInsets.all(0),
|
||||||
@ -929,7 +933,7 @@ void showSetOSPassword(BuildContext context, bool login) {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
[
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
style: flatButtonStyle,
|
style: flatButtonStyle,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
@ -952,8 +956,8 @@ void showSetOSPassword(BuildContext context, bool login) {
|
|||||||
},
|
},
|
||||||
child: Text(translate('OK')),
|
child: Text(translate('OK')),
|
||||||
),
|
),
|
||||||
],
|
]);
|
||||||
));
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendPrompt(bool isMac, String key) {
|
void sendPrompt(bool isMac, String key) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import 'package:settings_ui/settings_ui.dart';
|
import 'package:settings_ui/settings_ui.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
import '../common.dart';
|
import '../common.dart';
|
||||||
import '../models/model.dart';
|
import '../models/model.dart';
|
||||||
@ -38,7 +37,7 @@ class SettingsPage extends StatelessWidget implements PageShape {
|
|||||||
title: Text("About"),
|
title: Text("About"),
|
||||||
tiles: [
|
tiles: [
|
||||||
SettingsTile.navigation(
|
SettingsTile.navigation(
|
||||||
title: Text("Version: "+version),
|
title: Text("Version: " + version),
|
||||||
value: InkWell(
|
value: InkWell(
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
const url = 'https://rustdesk.com/';
|
const url = 'https://rustdesk.com/';
|
||||||
@ -70,9 +69,10 @@ void showServer() {
|
|||||||
var id = '';
|
var id = '';
|
||||||
var relay = '';
|
var relay = '';
|
||||||
var key = '';
|
var key = '';
|
||||||
showAlertDialog((setState) => Tuple3(
|
DialogManager.show((context, setState) {
|
||||||
Text(translate('ID Server')),
|
return CustomAlertDialog(
|
||||||
Form(
|
title: Text(translate('ID Server')),
|
||||||
|
content: Form(
|
||||||
key: formKey,
|
key: formKey,
|
||||||
child: Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
|
child: Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
|
||||||
TextFormField(
|
TextFormField(
|
||||||
@ -108,7 +108,7 @@ void showServer() {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
])),
|
])),
|
||||||
[
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
style: flatButtonStyle,
|
style: flatButtonStyle,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
@ -135,8 +135,8 @@ void showServer() {
|
|||||||
},
|
},
|
||||||
child: Text(translate('OK')),
|
child: Text(translate('OK')),
|
||||||
),
|
),
|
||||||
],
|
]);
|
||||||
));
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
String? validate(value) {
|
String? validate(value) {
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
|
||||||
import '../common.dart';
|
import '../common.dart';
|
||||||
import '../models/model.dart';
|
import '../models/model.dart';
|
||||||
|
|
||||||
@ -10,54 +9,28 @@ 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';
|
||||||
if (globalKey.currentContext == null) return;
|
DialogManager.show((context, setState) {
|
||||||
showAlertDialog((setState) => Tuple3(
|
return CustomAlertDialog(
|
||||||
Text(translate('Password Required')),
|
title: Text(translate('Password Required')),
|
||||||
Column(mainAxisSize: MainAxisSize.min, children: [
|
content: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||||
PasswordWidget(controller: controller),
|
PasswordWidget(controller: controller),
|
||||||
CheckboxListTile(
|
CheckboxListTile(
|
||||||
contentPadding: const EdgeInsets.all(0),
|
contentPadding: const EdgeInsets.all(0),
|
||||||
dense: true,
|
dense: true,
|
||||||
controlAffinity: ListTileControlAffinity.leading,
|
controlAffinity: ListTileControlAffinity.leading,
|
||||||
title: Text(
|
title: Text(
|
||||||
translate('Remember password'),
|
translate('Remember password'),
|
||||||
|
),
|
||||||
|
value: remember,
|
||||||
|
onChanged: (v) {
|
||||||
|
debugPrint("onChanged");
|
||||||
|
if (v != null) {
|
||||||
|
setState(() => remember = v);
|
||||||
|
}
|
||||||
|
},
|
||||||
),
|
),
|
||||||
value: remember,
|
]),
|
||||||
onChanged: (v) {
|
actions: [
|
||||||
if (v != null) {
|
|
||||||
setState(() => remember = v);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]),
|
|
||||||
[
|
|
||||||
TextButton(
|
|
||||||
style: flatButtonStyle,
|
|
||||||
onPressed: () {
|
|
||||||
DialogManager.reset();
|
|
||||||
Navigator.pop(globalKey.currentContext!);
|
|
||||||
},
|
|
||||||
child: Text(translate('Cancel')),
|
|
||||||
),
|
|
||||||
TextButton(
|
|
||||||
style: flatButtonStyle,
|
|
||||||
onPressed: () {
|
|
||||||
var text = controller.text.trim();
|
|
||||||
if (text == '') return;
|
|
||||||
FFI.login(text, remember);
|
|
||||||
DialogManager.reset();
|
|
||||||
showLoading(translate('Logging in...'));
|
|
||||||
},
|
|
||||||
child: Text(translate('OK')),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
void wrongPasswordDialog(String id) {
|
|
||||||
if (globalKey.currentContext == null) return;
|
|
||||||
showAlertDialog((_) => Tuple3(Text(translate('Wrong Password')),
|
|
||||||
Text(translate('Do you want to enter again?')), [
|
|
||||||
TextButton(
|
TextButton(
|
||||||
style: flatButtonStyle,
|
style: flatButtonStyle,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
@ -69,9 +42,80 @@ void wrongPasswordDialog(String id) {
|
|||||||
TextButton(
|
TextButton(
|
||||||
style: flatButtonStyle,
|
style: flatButtonStyle,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
enterPasswordDialog(id);
|
var text = controller.text.trim();
|
||||||
|
if (text == '') return;
|
||||||
|
FFI.login(text, remember);
|
||||||
|
DialogManager.reset();
|
||||||
|
showLoading(translate('Logging in...'));
|
||||||
},
|
},
|
||||||
child: Text(translate('Retry')),
|
child: Text(translate('OK')),
|
||||||
),
|
),
|
||||||
]));
|
],
|
||||||
}
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void wrongPasswordDialog(String id) {
|
||||||
|
DialogManager.show((context, setState) => CustomAlertDialog(
|
||||||
|
title: Text(translate('Wrong Password')),
|
||||||
|
content: Text(translate('Do you want to enter again?')),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
style: flatButtonStyle,
|
||||||
|
onPressed: () {
|
||||||
|
DialogManager.reset();
|
||||||
|
Navigator.pop(globalKey.currentContext!);
|
||||||
|
},
|
||||||
|
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;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user