parent
9ed9003805
commit
718f7f6d18
@ -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<ExamplePopUpMenu> {
|
||||||
|
@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<int>(
|
||||||
|
context: context,
|
||||||
|
items: [
|
||||||
|
PopupMenuItem(child: 'test'.text, value: 1),
|
||||||
|
],
|
||||||
|
).then((value) {});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
|
||||||
});
|
|
||||||
}
|
|
@ -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<int>(
|
||||||
|
/// context: context,
|
||||||
|
/// items: [
|
||||||
|
/// PopupMenuItem(child: 'test'.text, value: 1),
|
||||||
|
/// ],
|
||||||
|
/// ).then((value) {});
|
||||||
|
/// ```
|
||||||
|
Future<T> showASPopUpMenu<T>({
|
||||||
|
@required BuildContext context,
|
||||||
|
@required List<PopupMenuEntry<T>> 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),
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in new issue