Skip to content

Commit 607ffa7

Browse files
committed
iOS Pull down menu example added!
1 parent 2b51bcb commit 607ffa7

File tree

1 file changed

+167
-0
lines changed

1 file changed

+167
-0
lines changed

examples/ios_pull_down_menu.dart

+167
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
import 'package:flutter/cupertino.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:pull_down_button/pull_down_button.dart';
4+
5+
void main() {
6+
runApp(const MyApp());
7+
}
8+
9+
class MyApp extends StatelessWidget {
10+
const MyApp({super.key});
11+
12+
@override
13+
Widget build(BuildContext context) {
14+
return MaterialApp(
15+
title: 'Flutter Demo',
16+
debugShowCheckedModeBanner: false,
17+
theme: ThemeData.dark(
18+
useMaterial3: true,
19+
),
20+
home: Banner(
21+
message: 'Flexz',
22+
location: BannerLocation.topEnd,
23+
child: const HomePage(),
24+
),
25+
);
26+
}
27+
}
28+
29+
class HomePage extends StatefulWidget {
30+
const HomePage({super.key});
31+
32+
@override
33+
State<HomePage> createState() => _HomePageState();
34+
}
35+
36+
class _HomePageState extends State<HomePage> {
37+
@override
38+
Widget build(BuildContext context) {
39+
// Retrieve screen dimensions
40+
final screenSize = MediaQuery.of(context).size;
41+
42+
// Define the center position where the menu should appear
43+
final centerX = screenSize.width / 2;
44+
final centerY = screenSize.height / 1.5; // Slightly above the center
45+
46+
// Create a small rectangular region as an anchor point for the menu
47+
final centerRect = Rect.fromCenter(
48+
center: Offset(centerX, centerY),
49+
width: 0, // No width needed, just an anchor point
50+
height: 0, // No height needed, just an anchor point
51+
);
52+
53+
return Scaffold(
54+
appBar: AppBar(
55+
title: const Text('Pull Down Buttons Example'),
56+
),
57+
body: Center(
58+
child: Column(
59+
mainAxisAlignment: MainAxisAlignment.center,
60+
children: [
61+
// First button to show pull-down menu with profile and actions
62+
CupertinoButton.filled(
63+
onPressed: () async {
64+
await showPullDownMenu(
65+
context: context,
66+
items: [
67+
PullDownMenuHeader(
68+
leading: ColoredBox(
69+
color: CupertinoColors.systemBlue.resolveFrom(context),
70+
),
71+
title: 'Profile',
72+
subtitle: 'Tap to open',
73+
onTap: () {},
74+
icon: CupertinoIcons.profile_circled,
75+
),
76+
PullDownMenuItem(
77+
onTap: () {},
78+
title: 'Pin',
79+
icon: CupertinoIcons.pin,
80+
),
81+
PullDownMenuItem(
82+
title: 'Forward',
83+
subtitle: 'Share in different channel',
84+
onTap: () {},
85+
icon: CupertinoIcons.arrowshape_turn_up_right,
86+
),
87+
PullDownMenuItem(
88+
onTap: () {},
89+
title: 'Delete',
90+
isDestructive: true,
91+
icon: CupertinoIcons.delete,
92+
),
93+
],
94+
position: centerRect,
95+
);
96+
},
97+
child: const Text("Medium size Action Item"),
98+
),
99+
const SizedBox(height: 10),
100+
101+
// Second button to show a pull-down menu with actions row
102+
CupertinoButton.filled(
103+
onPressed: () async {
104+
await showPullDownMenu(
105+
context: context,
106+
items: [
107+
PullDownMenuActionsRow.medium(
108+
items: [
109+
PullDownMenuItem(
110+
onTap: () {},
111+
title: 'Reply',
112+
icon: CupertinoIcons.arrowshape_turn_up_left,
113+
),
114+
PullDownMenuItem(
115+
onTap: () {},
116+
title: 'Copy',
117+
icon: CupertinoIcons.doc_on_doc,
118+
),
119+
PullDownMenuItem(
120+
onTap: () {},
121+
title: 'Edit',
122+
icon: CupertinoIcons.pencil,
123+
),
124+
],
125+
),
126+
],
127+
position: centerRect,
128+
);
129+
},
130+
child: const Text("Medium size Action Row"),
131+
),
132+
const SizedBox(height: 10),
133+
134+
// Third button to show a more complex pull-down menu
135+
PullDownButton(
136+
itemBuilder: (context) => [
137+
PullDownMenuItem(
138+
title: 'Photo Library',
139+
icon: CupertinoIcons.photo_on_rectangle,
140+
onTap: () {},
141+
),
142+
const PullDownMenuDivider(),
143+
PullDownMenuItem(
144+
title: 'Take Photo or Video',
145+
onTap: () {},
146+
icon: CupertinoIcons.camera,
147+
),
148+
const PullDownMenuDivider(),
149+
PullDownMenuItem(
150+
title: 'Choose File',
151+
onTap: () {},
152+
icon: CupertinoIcons.folder,
153+
isDestructive: false,
154+
),
155+
],
156+
buttonBuilder: (context, showMenu) => CupertinoButton(
157+
onPressed: showMenu,
158+
padding: EdgeInsets.zero,
159+
child: const Icon(CupertinoIcons.ellipsis_circle),
160+
),
161+
),
162+
],
163+
),
164+
),
165+
);
166+
}
167+
}

0 commit comments

Comments
 (0)