From d9cbd4230a61cf0623339390b27993defd87d6d0 Mon Sep 17 00:00:00 2001 From: open-trade Date: Fri, 20 Nov 2020 02:12:48 +0800 Subject: [PATCH] toggle option --- flutter_hbb/lib/common.dart | 13 ++-- flutter_hbb/lib/model.dart | 2 +- flutter_hbb/lib/remote_page.dart | 128 +++++++++++++++++++------------ 3 files changed, 90 insertions(+), 53 deletions(-) diff --git a/flutter_hbb/lib/common.dart b/flutter_hbb/lib/common.dart index dc4deac90..db8f0cf41 100644 --- a/flutter_hbb/lib/common.dart +++ b/flutter_hbb/lib/common.dart @@ -43,8 +43,10 @@ typedef BuildAlertDailog = Tuple3> Function( void Function(void Function())); // https://material.io/develop/flutter/components/dialogs -Future showAlertDialog(BuildContext context, BuildAlertDailog build, - {WillPopCallback onWillPop}) async { +Future showAlertDialog(BuildContext context, BuildAlertDailog build, + [WillPopCallback onWillPop, + bool barrierDismissible, + double contentPadding = 20]) async { dismissLoading(); if (_hasDialog) { Navigator.pop(context); @@ -57,16 +59,17 @@ Future 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( + var res = await showDialog( context: context, - barrierDismissible: false, + barrierDismissible: barrierDismissible, builder: (context) => dialog); _hasDialog = false; + return res; } void msgbox(String type, String title, String text, BuildContext context) { diff --git a/flutter_hbb/lib/model.dart b/flutter_hbb/lib/model.dart index f3ee99956..2f73df63e 100644 --- a/flutter_hbb/lib/model.dart +++ b/flutter_hbb/lib/model.dart @@ -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); diff --git a/flutter_hbb/lib/remote_page.dart b/flutter_hbb/lib/remote_page.dart index 36a24b972..d3ccce7a6 100644 --- a/flutter_hbb/lib/remote_page.dart +++ b/flutter_hbb/lib/remote_page.dart @@ -105,7 +105,9 @@ class _RemotePageState extends State { 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 { 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); +}