From 8090726649ca5db0b06b32424acdc24d3143a5a3 Mon Sep 17 00:00:00 2001 From: open-trade Date: Mon, 23 Nov 2020 12:00:56 +0800 Subject: [PATCH] lock and long press pop menu --- flutter_hbb/lib/remote_page.dart | 29 +++++++++++++++-- flutter_hbb/pubspec.lock | 56 +++++++++++++++++++++++++++++++- flutter_hbb/pubspec.yaml | 1 + 3 files changed, 82 insertions(+), 4 deletions(-) diff --git a/flutter_hbb/lib/remote_page.dart b/flutter_hbb/lib/remote_page.dart index 4f9e22919..b8cfbc699 100644 --- a/flutter_hbb/lib/remote_page.dart +++ b/flutter_hbb/lib/remote_page.dart @@ -9,6 +9,7 @@ import 'dart:math' as math; import 'package:tuple/tuple.dart'; import 'common.dart'; import 'model.dart'; +import 'package:wakelock/wakelock.dart'; class RemotePage extends StatefulWidget { RemotePage({Key key, this.id}) : super(key: key); @@ -38,6 +39,7 @@ class _RemotePageState extends State { _interval = Timer.periodic(Duration(milliseconds: 30), (timer) => interval()); }); + Wakelock.enable(); } @override @@ -48,6 +50,7 @@ class _RemotePageState extends State { _interval.cancel(); dismissLoading(); SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values); + Wakelock.disable(); } void interval() { @@ -197,9 +200,29 @@ class _RemotePageState extends State { LongPressGestureRecognizer>( () => LongPressGestureRecognizer(), (LongPressGestureRecognizer instance) { - instance.onLongPress = () { - print('long press'); - }; + var x = 0.0; + var y = 0.0; + instance + ..onLongPressStart = (details) { + x = details.globalPosition.dx; + y = details.globalPosition.dy; + } + ..onLongPress = () { + print('long press'); + () async { + await showMenu( + context: context, + position: RelativeRect.fromLTRB(x, y, 0, 0), + items: [ + PopupMenuItem( + child: const Text('Doge'), value: 'Doge'), + PopupMenuItem( + child: const Text('Lion'), value: 'Lion'), + ], + elevation: 8.0, + ); + }(); + }; }, ), PanGestureRecognizer: diff --git a/flutter_hbb/pubspec.lock b/flutter_hbb/pubspec.lock index 3b1d42184..4a14ca263 100644 --- a/flutter_hbb/pubspec.lock +++ b/flutter_hbb/pubspec.lock @@ -43,6 +43,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.15.0-nullsafety.3" + csslib: + dependency: transitive + description: + name: csslib + url: "https://pub.dartlang.org" + source: hosted + version: "0.16.2" cupertino_icons: dependency: "direct main" description: @@ -95,6 +102,25 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + html: + dependency: transitive + description: + name: html + url: "https://pub.dartlang.org" + source: hosted + version: "0.14.0+4" + import_js_library: + dependency: transitive + description: + name: import_js_library + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2" intl: dependency: transitive description: @@ -102,6 +128,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.16.1" + js: + dependency: transitive + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.2" matcher: dependency: transitive description: @@ -268,6 +301,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0-nullsafety.3" + wakelock: + dependency: "direct main" + description: + name: wakelock + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.1+1" + wakelock_platform_interface: + dependency: transitive + description: + name: wakelock_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.0+1" + wakelock_web: + dependency: transitive + description: + name: wakelock_web + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.0+3" win32: dependency: transitive description: @@ -284,4 +338,4 @@ packages: version: "0.1.2" sdks: dart: ">=2.10.0-110 <2.11.0" - flutter: ">=1.16.0 <2.0.0" + flutter: ">=1.20.0 <2.0.0" diff --git a/flutter_hbb/pubspec.yaml b/flutter_hbb/pubspec.yaml index 9aa35bd58..038f1e574 100644 --- a/flutter_hbb/pubspec.yaml +++ b/flutter_hbb/pubspec.yaml @@ -33,6 +33,7 @@ dependencies: provider: ^4.3.2+2 flutter_easyloading: ^2.1.3 tuple: ^1.0.1 + wakelock: ^0.2.1+1 dev_dependencies: flutter_test: