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())); void Function(void Function()));
// https://material.io/develop/flutter/components/dialogs // https://material.io/develop/flutter/components/dialogs
Future<Null> showAlertDialog(BuildContext context, BuildAlertDailog build, Future<T> showAlertDialog<T>(BuildContext context, BuildAlertDailog build,
{WillPopCallback onWillPop}) async { [WillPopCallback onWillPop,
bool barrierDismissible,
double contentPadding = 20]) async {
dismissLoading(); dismissLoading();
if (_hasDialog) { if (_hasDialog) {
Navigator.pop(context); Navigator.pop(context);
@ -57,16 +59,17 @@ Future<Null> showAlertDialog(BuildContext context, BuildAlertDailog build,
onWillPop: onWillPop, onWillPop: onWillPop,
child: AlertDialog( child: AlertDialog(
title: widgets.item1, title: widgets.item1,
contentPadding: const EdgeInsets.all(20.0), contentPadding: EdgeInsets.all(contentPadding),
content: widgets.item2, content: widgets.item2,
actions: widgets.item3, actions: widgets.item3,
)); ));
}); });
await showDialog<void>( var res = await showDialog<T>(
context: context, context: context,
barrierDismissible: false, barrierDismissible: barrierDismissible,
builder: (context) => dialog); builder: (context) => dialog);
_hasDialog = false; _hasDialog = false;
return res;
} }
void msgbox(String type, String title, String text, BuildContext context) { 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)); _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)); var p = _getByName(Utf8.toUtf8(name), Utf8.toUtf8(arg));
assert(p != nullptr && p != null); assert(p != nullptr && p != null);
var res = Utf8.fromUtf8(p); var res = Utf8.fromUtf8(p);

View File

@ -105,7 +105,9 @@ class _RemotePageState extends State<RemotePage> {
IconButton( IconButton(
color: Colors.white, color: Colors.white,
icon: Icon(Icons.tv), icon: Icon(Icons.tv),
onPressed: () {}, onPressed: () {
showOptions(widget.id, context);
},
), ),
IconButton( IconButton(
color: Colors.white, color: Colors.white,
@ -130,7 +132,7 @@ class _RemotePageState extends State<RemotePage> {
constrained: false, constrained: false,
panEnabled: true, panEnabled: true,
onInteractionUpdate: (details) { onInteractionUpdate: (details) {
print("$details"); print('$details');
}, },
child: Stack(children: [ child: Stack(children: [
ImagePaint(), ImagePaint(),
@ -186,57 +188,54 @@ class ImagePainter extends CustomPainter {
void enterPasswordDialog(String id, BuildContext context) { void enterPasswordDialog(String id, BuildContext context) {
final controller = TextEditingController(); final controller = TextEditingController();
var remember = FFI.getByName('remember', arg: id) == 'true'; var remember = FFI.getByName('remember', id) == 'true';
showAlertDialog( showAlertDialog(
context, context,
(setState) => Tuple3( (setState) => Tuple3(
Text('Please enter your password'), Text('Please enter your password'),
Column(mainAxisSize: MainAxisSize.min, children: [ Column(mainAxisSize: MainAxisSize.min, children: [
TextField( TextField(
autofocus: true, autofocus: true,
obscureText: true, obscureText: true,
controller: controller, controller: controller,
decoration: const InputDecoration( decoration: const InputDecoration(
labelText: 'Password', labelText: 'Password',
),
), ),
ListTile( ),
title: Text( ListTile(
'Remember the password', title: Text(
), 'Remember the password',
leading: Checkbox(
value: remember,
onChanged: (v) {
setState(() {
remember = v;
});
},
),
), ),
]), leading: Checkbox(
[ value: remember,
TextField( onChanged: (v) {
autofocus: true, setState(() => remember = v);
obscureText: true, },
controller: controller,
decoration: const InputDecoration(
labelText: 'Password',
),
), ),
ListTile( ),
title: Text( ]),
'Remember the password', [
), FlatButton(
leading: Checkbox( textColor: MyTheme.accent,
value: remember, onPressed: () {
onChanged: (v) { Navigator.pop(context);
setState(() { Navigator.pop(context);
remember = v; },
}); 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) { 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);
}