Skip to content

Commit 1245fcd

Browse files
committed
Add: Popup style widget
1 parent ef31ad4 commit 1245fcd

File tree

4 files changed

+165
-0
lines changed

4 files changed

+165
-0
lines changed

lib/component/main/MainPage.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class _MainState extends State<MainPage> {
6363
"Progress",
6464
"Segment",
6565
"DropDown",
66+
"Popup",
6667
];
6768
return _sortTitles;
6869
}
@@ -86,6 +87,7 @@ class _MainState extends State<MainPage> {
8687
"/MainProgressPage",
8788
"/SegmentPage",
8889
"/DropDownPage",
90+
"/MainPopupPage",
8991
];
9092
return _sortRouteNames;
9193
}

lib/main.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import 'package:flutter_app_sample/sample/drag/DragListPage.dart';
2323
import 'package:flutter_app_sample/sample/ink/ink_page.dart';
2424
import 'package:flutter_app_sample/sample/notifier/CardInfoPage.dart';
2525
import 'package:flutter_app_sample/sample/notifier/CardMainPage.dart';
26+
import 'package:flutter_app_sample/sample/popup/main_popup_page.dart';
2627
import 'package:flutter_localizations/flutter_localizations.dart';
2728
import 'package:provider/provider.dart';
2829

@@ -120,6 +121,7 @@ class Test extends StatelessWidget {
120121
"/MainProgressPage": (_) => MainProgressPage(),
121122
"/SegmentPage": (_) => SegmentPage(),
122123
"/DropDownPage": (_) => DropDownPage(),
124+
"/MainPopupPage": (_) => MainPopupPage(),
123125
},
124126
);
125127
},
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:popup_menu/popup_menu.dart';
3+
4+
///
5+
/// MainPopupPage
6+
class MainPopupPage extends StatefulWidget {
7+
@override
8+
State<StatefulWidget> createState() {
9+
return _MainPopupState();
10+
}
11+
}
12+
13+
///
14+
/// _MainPopupState
15+
class _MainPopupState extends State<MainPopupPage> {
16+
GlobalKey btnKey = GlobalKey();
17+
GlobalKey btnKey2 = GlobalKey();
18+
GlobalKey btnKey3 = GlobalKey();
19+
20+
GlobalKey btnKey1Right = GlobalKey();
21+
GlobalKey btnKey2Right = GlobalKey();
22+
GlobalKey btnKey3Right = GlobalKey();
23+
24+
@override
25+
Widget build(BuildContext context) {
26+
PopupMenu.context = context;
27+
28+
return Scaffold(
29+
appBar: AppBar(
30+
title: Text("Popup"),
31+
),
32+
body: Row(
33+
children: <Widget>[
34+
Spacer(),
35+
Column(children: <Widget>[
36+
Spacer(),
37+
RaisedButton.icon(
38+
key: btnKey,
39+
onPressed: () {
40+
_createMenu(btnKey);
41+
},
42+
icon: Icon(Icons.folder_open),
43+
label: Text("left top"),
44+
),
45+
Spacer(),
46+
RaisedButton.icon(
47+
key: btnKey2,
48+
onPressed: () {
49+
_createMenu(btnKey2);
50+
},
51+
icon: Icon(Icons.folder_open),
52+
label: Text("left center"),
53+
),
54+
Spacer(),
55+
RaisedButton.icon(
56+
key: btnKey3,
57+
onPressed: () {
58+
_createMenu(btnKey3);
59+
},
60+
icon: Icon(Icons.folder_open),
61+
label: Text("left bottom"),
62+
),
63+
Spacer(),
64+
]),
65+
Spacer(),
66+
Spacer(),
67+
Column(children: <Widget>[
68+
Spacer(),
69+
RaisedButton.icon(
70+
key: btnKey1Right,
71+
onPressed: () {
72+
_createMenu(btnKey1Right);
73+
},
74+
icon: Icon(Icons.folder_open),
75+
label: Text("right top"),
76+
),
77+
Spacer(),
78+
RaisedButton.icon(
79+
key: btnKey2Right,
80+
onPressed: () {
81+
_createMenu(btnKey2Right);
82+
},
83+
icon: Icon(Icons.folder_open),
84+
label: Text("right center"),
85+
),
86+
Spacer(),
87+
RaisedButton.icon(
88+
key: btnKey3Right,
89+
onPressed: () {
90+
_createMenu(btnKey3Right);
91+
},
92+
icon: Icon(Icons.folder_open),
93+
label: Text("right bottom"),
94+
),
95+
Spacer(),
96+
]),
97+
Spacer(),
98+
],
99+
),
100+
);
101+
}
102+
103+
_createMenu(GlobalKey globalKey) {
104+
PopupMenu menu = PopupMenu(
105+
backgroundColor: Colors.teal,
106+
lineColor: Colors.tealAccent,
107+
maxColumn: 3,
108+
items: [
109+
MenuItem(title: 'Copy', image: Image.asset('assets/avatar.jpg')),
110+
MenuItem(
111+
title: 'Home',
112+
textStyle: TextStyle(fontSize: 10.0, color: Colors.tealAccent),
113+
image: Icon(
114+
Icons.home,
115+
color: Colors.white,
116+
)),
117+
MenuItem(
118+
title: 'Mail',
119+
image: Icon(
120+
Icons.mail,
121+
color: Colors.white,
122+
)),
123+
MenuItem(
124+
title: 'Power',
125+
image: Icon(
126+
Icons.power,
127+
color: Colors.white,
128+
)),
129+
MenuItem(
130+
title: 'Setting',
131+
image: Icon(
132+
Icons.settings,
133+
color: Colors.white,
134+
)),
135+
MenuItem(
136+
title: 'PopupMenu',
137+
image: Icon(
138+
Icons.menu,
139+
color: Colors.white,
140+
))
141+
],
142+
onClickMenu: onClickMenu,
143+
onDismiss: onDismiss);
144+
menu.show(widgetKey: globalKey);
145+
}
146+
147+
void onClickMenu(MenuItemProvider item) {
148+
print('Click menu -> ${item.menuTitle}');
149+
}
150+
151+
void onDismiss() {
152+
print('Menu is dismiss');
153+
}
154+
155+
void stateChanged(bool isShow) {
156+
print('menu is ${isShow ? 'showing' : 'closed'}');
157+
}
158+
}

pubspec.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ dependencies:
7777

7878
# navigation bar
7979
curved_navigation_bar: ^0.3.2
80+
81+
# popup menu
82+
popup_menu: ^1.0.5
8083
dev_dependencies:
8184
flutter_test:
8285
sdk: flutter

0 commit comments

Comments
 (0)