toggle option

This commit is contained in:
open-trade 2020-11-20 02:12:48 +08:00
parent 090f56b9f5
commit d9cbd4230a
3 changed files with 90 additions and 53 deletions

View File

@ -43,8 +43,10 @@ typedef BuildAlertDailog = Tuple3<Widget, Widget, List<Widget>> Function(
void Function(void Function()));
// https://material.io/develop/flutter/components/dialogs
Future<Null> showAlertDialog(BuildContext context, BuildAlertDailog build,
{WillPopCallback onWillPop}) async {
Future<T> showAlertDialog<T>(BuildContext context, BuildAlertDailog build,
[WillPopCallback onWillPop,
bool barrierDismissible,
double contentPadding = 20]) async {
dismissLoading();
if (_hasDialog) {
Navigator.pop(context);
@ -57,16 +59,17 @@ Future<Null> showAlertDialog(BuildContext context, BuildAlertDailog build,
onWillPop: onWillPop,
child: AlertDialog(
title: widgets.item1,
contentPadding: const EdgeInsets.all(20.0),
contentPadding: EdgeInsets.all(contentPadding),
content: widgets.item2,
actions: widgets.item3,
));
});
await showDialog<void>(
var res = await showDialog<T>(
context: context,
barrierDismissible: false,
barrierDismissible: barrierDismissible,
builder: (context) => dialog);
_hasDialog = false;
return res;
}
void msgbox(String type, String title, String text, BuildContext context) {

View File

@ -271,7 +271,7 @@ class FFI {
_setByName(Utf8.toUtf8(name), Utf8.toUtf8(value));
}
static String getByName(String name, {String arg = ''}) {
static String getByName(String name, [String arg = '']) {
var p = _getByName(Utf8.toUtf8(name), Utf8.toUtf8(arg));
assert(p != nullptr && p != null);
var res = Utf8.fromUtf8(p);

View File

@ -105,7 +105,9 @@ class _RemotePageState extends State<RemotePage> {
IconButton(
color: Colors.white,
icon: Icon(Icons.tv),
onPressed: () {},
onPressed: () {
showOptions(widget.id, context);
},
),
IconButton(
color: Colors.white,
@ -130,7 +132,7 @@ class _RemotePageState extends State<RemotePage> {
constrained: false,
panEnabled: true,
onInteractionUpdate: (details) {
print("$details");
print('$details');
},
child: Stack(children: [
ImagePaint(),
@ -186,57 +188,54 @@ class ImagePainter extends CustomPainter {
void enterPasswordDialog(String id, BuildContext context) {
final controller = TextEditingController();
var remember = FFI.getByName('remember', arg: id) == 'true';
var remember = FFI.getByName('remember', id) == 'true';
showAlertDialog(
context,
(setState) => Tuple3(
Text('Please enter your password'),
Column(mainAxisSize: MainAxisSize.min, children: [
TextField(
autofocus: true,
obscureText: true,
controller: controller,
decoration: const InputDecoration(
labelText: 'Password',
),
Text('Please enter your password'),
Column(mainAxisSize: MainAxisSize.min, children: [
TextField(
autofocus: true,
obscureText: true,
controller: controller,
decoration: const InputDecoration(
labelText: 'Password',
),
ListTile(
title: Text(
'Remember the password',
),
leading: Checkbox(
value: remember,
onChanged: (v) {
setState(() {
remember = v;
});
},
),
),
ListTile(
title: Text(
'Remember the password',
),
]),
[
TextField(
autofocus: true,
obscureText: true,
controller: controller,
decoration: const InputDecoration(
labelText: 'Password',
),
leading: Checkbox(
value: remember,
onChanged: (v) {
setState(() => remember = v);
},
),
ListTile(
title: Text(
'Remember the password',
),
leading: Checkbox(
value: remember,
onChanged: (v) {
setState(() {
remember = v;
});
},
),
),
]));
),
]),
[
FlatButton(
textColor: MyTheme.accent,
onPressed: () {
Navigator.pop(context);
Navigator.pop(context);
},
child: Text('Cancel'),
),
FlatButton(
textColor: MyTheme.accent,
onPressed: () {
var text = controller.text.trim();
if (text == '') return;
FFI.login(text, remember);
showLoading('Logging in...');
Navigator.pop(context);
},
child: Text('OK'),
),
],
));
}
void wrongPasswordDialog(String id, BuildContext context) {
@ -262,3 +261,38 @@ void wrongPasswordDialog(String id, BuildContext context) {
),
]));
}
void showOptions(String id, BuildContext context) {
var showRemoteCursor =
FFI.getByName('toggle_option', 'show-remote-cursor') == 'true';
var lockAfterSessionEnd =
FFI.getByName('toggle_option', 'lock-after-session-end') == 'true';
showAlertDialog(
context,
(setState) => Tuple3(
null,
Column(mainAxisSize: MainAxisSize.min, children: [
CheckboxListTile(
value: showRemoteCursor,
onChanged: (v) {
setState(() {
showRemoteCursor = v;
FFI.setByName('toggle_option', 'show-remote-cursor');
});
},
title: Text('Show remote cursor')),
CheckboxListTile(
value: lockAfterSessionEnd,
onChanged: (v) {
setState(() {
lockAfterSessionEnd = v;
FFI.setByName('toggle_option', 'lock-after-session-end');
});
},
title: Text('Lock after session end'))
]),
null),
() async => true,
true,
10);
}