From 718f7f6d1897cb5cd5d9cf83104f7b3dad0d00c4 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Tue, 22 Dec 2020 10:07:06 +0800 Subject: [PATCH] add popupmenu --- example/lib/example_pop_up_menu.dart | 40 ++++++++++++++++++ example/lib/main_home.dart | 5 +++ example/pubspec.lock | 61 ---------------------------- example/pubspec.yaml | 18 +------- example/test/widget_test.dart | 30 -------------- lib/ansu_ui.dart | 2 + lib/pop_up_menu/pop_up_menu.dart | 31 ++++++++++++++ 7 files changed, 79 insertions(+), 108 deletions(-) create mode 100644 example/lib/example_pop_up_menu.dart delete mode 100644 example/test/widget_test.dart create mode 100644 lib/pop_up_menu/pop_up_menu.dart diff --git a/example/lib/example_pop_up_menu.dart b/example/lib/example_pop_up_menu.dart new file mode 100644 index 0000000..a632f0f --- /dev/null +++ b/example/lib/example_pop_up_menu.dart @@ -0,0 +1,40 @@ +import 'package:ansu_ui/ansu_ui.dart'; +import 'package:flutter/material.dart'; + +class ExamplePopUpMenu extends StatefulWidget { + ExamplePopUpMenu({Key key}) : super(key: key); + + @override + _ExamplePopUpMenuState createState() => _ExamplePopUpMenuState(); +} + +class _ExamplePopUpMenuState extends State { + @override + Widget build(BuildContext context) { + return ASScaffold( + title: 'PopUpMenu', + body: ListView( + children: [ + ListTile( + title: 'PopUpMenu'.text, + trailing: Builder( + builder: (context) { + return TextButton( + child: 'test'.text, + onPressed: () { + showASPopUpMenu( + context: context, + items: [ + PopupMenuItem(child: 'test'.text, value: 1), + ], + ).then((value) {}); + }, + ); + }, + ), + ), + ], + ), + ); + } +} diff --git a/example/lib/main_home.dart b/example/lib/main_home.dart index 1419ece..0c61774 100644 --- a/example/lib/main_home.dart +++ b/example/lib/main_home.dart @@ -4,6 +4,7 @@ import 'package:example/example_box.dart'; import 'package:example/example_dialog.dart'; import 'package:example/example_drawer.dart'; import 'package:example/example_listtile.dart'; +import 'package:example/example_pop_up_menu.dart'; import 'package:example/example_refresh.dart'; import 'package:example/example_tag.dart'; import 'package:example/example_text_field.dart'; @@ -99,6 +100,10 @@ class _MainHomeState extends State { title: '选框 Box', onPressed: () => Get.to(ExampleBox()), ), + _innerButton( + title: 'Pop Up Menu', + onPressed: () => Get.to(ExamplePopUpMenu()), + ), ], ); } diff --git a/example/pubspec.lock b/example/pubspec.lock index bbd4d67..f267400 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -8,20 +8,6 @@ packages: relative: true source: path version: "0.0.4" - async: - dependency: transitive - description: - name: async - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.5.0-nullsafety.1" - boolean_selector: - dependency: transitive - description: - name: boolean_selector - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.1.0-nullsafety.1" bot_toast: dependency: transitive description: @@ -43,13 +29,6 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.2.0-nullsafety.1" - clock: - dependency: transitive - description: - name: clock - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.1.0-nullsafety.1" collection: dependency: transitive description: @@ -64,13 +43,6 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.0.0" - fake_async: - dependency: transitive - description: - name: fake_async - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.2.0-nullsafety.1" flutter: dependency: "direct main" description: flutter @@ -102,11 +74,6 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "3.2.0" - flutter_test: - dependency: "direct dev" - description: flutter - source: sdk - version: "0.0.0" get: dependency: "direct main" description: @@ -156,13 +123,6 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.1.0" - matcher: - dependency: transitive - description: - name: matcher - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.12.10-nullsafety.1" meta: dependency: transitive description: @@ -203,20 +163,6 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.8.0-nullsafety.2" - stack_trace: - dependency: transitive - description: - name: stack_trace - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.10.0-nullsafety.1" - stream_channel: - dependency: transitive - description: - name: stream_channel - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.1.0-nullsafety.1" string_scanner: dependency: transitive description: @@ -231,13 +177,6 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.2.0-nullsafety.1" - test_api: - dependency: transitive - description: - name: test_api - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.2.19-nullsafety.2" typed_data: dependency: transitive description: diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 9b18d46..6f282f7 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,20 +1,6 @@ name: example description: A new Flutter project. - -# The following line prevents the package from being accidentally published to -# pub.dev using `pub publish`. This is preferred for private packages. -publish_to: "none" # Remove this line if you wish to publish to pub.dev - -# The following defines the version and build number for your application. -# A version number is three numbers separated by dots, like 1.2.43 -# followed by an optional build number separated by a +. -# Both the version and the builder number may be overridden in flutter -# build by specifying --build-name and --build-number, respectively. -# In Android, build-name is used as versionName while build-number used as versionCode. -# Read more about Android versioning at https://developer.android.com/studio/publish/versioning -# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. -# Read more about iOS versioning at -# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html +publish_to: "none" version: 1.0.0+1 environment: @@ -33,8 +19,6 @@ dependencies: path: ../ get: -dev_dependencies: - flutter_test: flutter: uses-material-design: true assets: diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart deleted file mode 100644 index 747db1d..0000000 --- a/example/test/widget_test.dart +++ /dev/null @@ -1,30 +0,0 @@ -// This is a basic Flutter widget test. -// -// To perform an interaction with a widget in your test, use the WidgetTester -// utility that Flutter provides. For example, you can send tap and scroll -// gestures. You can also use WidgetTester to find child widgets in the widget -// tree, read text, and verify that the values of widget properties are correct. - -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:example/main.dart'; - -void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { - // Build our app and trigger a frame. - await tester.pumpWidget(MyApp()); - - // Verify that our counter starts at 0. - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); - - // Tap the '+' icon and trigger a frame. - await tester.tap(find.byIcon(Icons.add)); - await tester.pump(); - - // Verify that our counter has incremented. - expect(find.text('0'), findsNothing); - expect(find.text('1'), findsOneWidget); - }); -} diff --git a/lib/ansu_ui.dart b/lib/ansu_ui.dart index 7f97d90..d0c4bf5 100644 --- a/lib/ansu_ui.dart +++ b/lib/ansu_ui.dart @@ -47,6 +47,8 @@ export 'refresh/as_refresh.dart'; export 'box/as_check_box.dart'; +export 'pop_up_menu/pop_up_menu.dart'; + export 'tag/as_tag.dart'; export 'divider/as_divider.dart'; export 'text_field/as_search_text_field.dart'; diff --git a/lib/pop_up_menu/pop_up_menu.dart b/lib/pop_up_menu/pop_up_menu.dart new file mode 100644 index 0000000..67c3f77 --- /dev/null +++ b/lib/pop_up_menu/pop_up_menu.dart @@ -0,0 +1,31 @@ +import 'package:ansu_ui/utils/screen_adapter.dart'; +import 'package:ansu_ui/extension/num_extension.dart'; +import 'package:flutter/material.dart'; + +/// ## 弹框菜单 +///```dart +/// showASPopUpMenu( +/// context: context, +/// items: [ +/// PopupMenuItem(child: 'test'.text, value: 1), +/// ], +/// ).then((value) {}); +/// ``` +Future showASPopUpMenu({ + @required BuildContext context, + @required List> items, +}) async { + final RenderBox renderBox = context.findRenderObject(); + Offset offset = renderBox.localToGlobal(Offset.zero); + return await showMenu( + context: context, + position: RelativeRect.fromLTRB( + offset.dx, + offset.dy, + screenWidth, + screenHeight, + ), + items: items, + shape: RoundedRectangleBorder(borderRadius: 10.radius), + ); +}