Skip to content

Commit bf585b3

Browse files
committed
[macos] Implement popUp metnod
1 parent b939533 commit bf585b3

File tree

13 files changed

+490
-72
lines changed

13 files changed

+490
-72
lines changed

example/lib/main.dart

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,34 @@
11
import 'package:flutter/material.dart';
2-
import 'dart:async';
2+
import 'package:bot_toast/bot_toast.dart';
33

4-
import 'package:flutter/services.dart';
5-
import 'package:contextual_menu/contextual_menu.dart';
4+
import './pages/home.dart';
65

76
void main() {
7+
WidgetsFlutterBinding.ensureInitialized();
8+
89
runApp(const MyApp());
910
}
1011

1112
class MyApp extends StatefulWidget {
1213
const MyApp({Key? key}) : super(key: key);
1314

1415
@override
15-
State<MyApp> createState() => _MyAppState();
16+
_MyAppState createState() => _MyAppState();
1617
}
1718

1819
class _MyAppState extends State<MyApp> {
19-
String _platformVersion = 'Unknown';
20-
21-
@override
22-
void initState() {
23-
super.initState();
24-
initPlatformState();
25-
}
26-
27-
// Platform messages are asynchronous, so we initialize in an async method.
28-
Future<void> initPlatformState() async {
29-
String platformVersion;
30-
// Platform messages may fail, so we use a try/catch PlatformException.
31-
// We also handle the message potentially returning null.
32-
try {
33-
platformVersion =
34-
await ContextualMenu.platformVersion ?? 'Unknown platform version';
35-
} on PlatformException {
36-
platformVersion = 'Failed to get platform version.';
37-
}
38-
39-
// If the widget was removed from the tree while the asynchronous platform
40-
// message was in flight, we want to discard the reply rather than calling
41-
// setState to update our non-existent appearance.
42-
if (!mounted) return;
43-
44-
setState(() {
45-
_platformVersion = platformVersion;
46-
});
47-
}
48-
4920
@override
5021
Widget build(BuildContext context) {
5122
return MaterialApp(
52-
home: Scaffold(
53-
appBar: AppBar(
54-
title: const Text('Plugin example app'),
55-
),
56-
body: Center(
57-
child: Text('Running on: $_platformVersion\n'),
58-
),
23+
theme: ThemeData(
24+
primaryColor: const Color(0xff416ff4),
25+
canvasColor: Colors.white,
26+
scaffoldBackgroundColor: const Color(0xffF7F9FB),
27+
dividerColor: Colors.grey.withOpacity(0.3),
5928
),
29+
builder: BotToastInit(),
30+
navigatorObservers: [BotToastNavigatorObserver()],
31+
home: const HomePage(),
6032
);
6133
}
6234
}

example/lib/pages/home.dart

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import 'package:bot_toast/bot_toast.dart';
2+
import 'package:flutter/gestures.dart';
3+
import 'package:flutter/material.dart';
4+
import 'package:preference_list/preference_list.dart';
5+
import 'package:contextual_menu/contextual_menu.dart';
6+
7+
class HomePage extends StatefulWidget {
8+
const HomePage({Key? key}) : super(key: key);
9+
10+
@override
11+
_HomePageState createState() => _HomePageState();
12+
}
13+
14+
class _HomePageState extends State<HomePage> {
15+
bool _shouldReact = false;
16+
Offset? _position;
17+
18+
Menu? _menu;
19+
20+
@override
21+
void initState() {
22+
super.initState();
23+
}
24+
25+
void _handleClickPopUp() {
26+
_menu ??= Menu(
27+
items: [
28+
MenuItem(
29+
label: 'Copy',
30+
onClick: (_) {
31+
BotToast.showText(text: 'Clicked Copy');
32+
},
33+
),
34+
MenuItem(
35+
label: 'Paste',
36+
onClick: (_) {
37+
BotToast.showText(text: 'Clicked Paste');
38+
},
39+
),
40+
MenuItem(
41+
label: 'Paste as values',
42+
),
43+
MenuItem.separator(),
44+
MenuItem(
45+
label: 'Item number two',
46+
),
47+
MenuItem(
48+
label: 'Disabled item',
49+
disabled: true,
50+
),
51+
MenuItem(
52+
label: 'Disabled item with shortcut',
53+
disabled: true,
54+
),
55+
MenuItem.separator(),
56+
MenuItem.submenu(
57+
label: 'Submenu',
58+
submenu: Menu(
59+
items: [
60+
MenuItem.checkbox(
61+
key: 'checkbox1',
62+
label: 'Checkbox1',
63+
checked: true,
64+
onClick: (menuItem) {
65+
menuItem.checked = !(menuItem.checked == true);
66+
},
67+
),
68+
MenuItem.checkbox(
69+
label: 'Checkbox2',
70+
checked: false,
71+
),
72+
MenuItem.checkbox(
73+
label: 'Checkbox3',
74+
checked: null,
75+
),
76+
],
77+
),
78+
),
79+
MenuItem.separator(),
80+
MenuItem(
81+
label: 'Control shortcut',
82+
),
83+
],
84+
);
85+
popUpContextualMenu(
86+
_menu!,
87+
position: _position,
88+
placement: Placement.topRight,
89+
);
90+
}
91+
92+
Widget _buildBody(BuildContext context) {
93+
return PreferenceList(
94+
children: <Widget>[
95+
PreferenceListSection(
96+
title: const Text('Methods'),
97+
children: [
98+
PreferenceListItem(
99+
title: const Text('popUp'),
100+
onTap: () {
101+
_position = null;
102+
_handleClickPopUp();
103+
},
104+
),
105+
],
106+
),
107+
],
108+
);
109+
}
110+
111+
@override
112+
Widget build(BuildContext context) {
113+
return Listener(
114+
onPointerDown: (event) {
115+
_shouldReact = event.kind == PointerDeviceKind.mouse &&
116+
event.buttons == kSecondaryMouseButton;
117+
},
118+
onPointerUp: (event) {
119+
if (!_shouldReact) return;
120+
121+
_position = Offset(
122+
event.position.dx,
123+
event.position.dy,
124+
);
125+
126+
_handleClickPopUp();
127+
},
128+
child: Scaffold(
129+
appBar: AppBar(
130+
title: const Text('Plugin example app'),
131+
),
132+
body: _buildBody(context),
133+
),
134+
);
135+
}
136+
}

example/macos/Podfile.lock

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
PODS:
2+
- contextual_menu (0.0.1):
3+
- FlutterMacOS
4+
- FlutterMacOS (1.0.0)
5+
6+
DEPENDENCIES:
7+
- contextual_menu (from `Flutter/ephemeral/.symlinks/plugins/contextual_menu/macos`)
8+
- FlutterMacOS (from `Flutter/ephemeral`)
9+
10+
EXTERNAL SOURCES:
11+
contextual_menu:
12+
:path: Flutter/ephemeral/.symlinks/plugins/contextual_menu/macos
13+
FlutterMacOS:
14+
:path: Flutter/ephemeral
15+
16+
SPEC CHECKSUMS:
17+
contextual_menu: 6d35fb15942c0d8769f5eae8d3bda653994a6f5a
18+
FlutterMacOS: 57701585bf7de1b3fc2bb61f6378d73bbdea8424
19+
20+
PODFILE CHECKSUM: 6eac6b3292e5142cfc23bdeb71848a40ec51c14c
21+
22+
COCOAPODS: 1.11.2

example/macos/Runner.xcodeproj/project.pbxproj

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F22044A3C60003C045 /* Assets.xcassets */; };
2727
33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F42044A3C60003C045 /* MainMenu.xib */; };
2828
33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */; };
29+
94ECFFF023B51DFE6DBE5C93 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A1E695E9169BBD8AA2FC608B /* Pods_Runner.framework */; };
2930
/* End PBXBuildFile section */
3031

3132
/* Begin PBXContainerItemProxy section */
@@ -52,9 +53,10 @@
5253
/* End PBXCopyFilesBuildPhase section */
5354

5455
/* Begin PBXFileReference section */
56+
2E4E7A17233CE9BAB4E6AFD4 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
5557
333000ED22D3DE5D00554162 /* Warnings.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Warnings.xcconfig; sourceTree = "<group>"; };
5658
335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneratedPluginRegistrant.swift; sourceTree = "<group>"; };
57-
33CC10ED2044A3C60003C045 /* contextual_menu_example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "contextual_menu_example.app"; sourceTree = BUILT_PRODUCTS_DIR; };
59+
33CC10ED2044A3C60003C045 /* contextual_menu_example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = contextual_menu_example.app; sourceTree = BUILT_PRODUCTS_DIR; };
5860
33CC10F02044A3C60003C045 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
5961
33CC10F22044A3C60003C045 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = Runner/Assets.xcassets; sourceTree = "<group>"; };
6062
33CC10F52044A3C60003C045 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = "<group>"; };
@@ -66,21 +68,36 @@
6668
33E51913231747F40026EE4D /* DebugProfile.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DebugProfile.entitlements; sourceTree = "<group>"; };
6769
33E51914231749380026EE4D /* Release.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = Release.entitlements; sourceTree = "<group>"; };
6870
33E5194F232828860026EE4D /* AppInfo.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = AppInfo.xcconfig; sourceTree = "<group>"; };
71+
73CEA9A98397EEB976012B1F /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
6972
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = "<group>"; };
73+
899C75AD5295627294526A87 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
7074
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = "<group>"; };
75+
A1E695E9169BBD8AA2FC608B /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
7176
/* End PBXFileReference section */
7277

7378
/* Begin PBXFrameworksBuildPhase section */
7479
33CC10EA2044A3C60003C045 /* Frameworks */ = {
7580
isa = PBXFrameworksBuildPhase;
7681
buildActionMask = 2147483647;
7782
files = (
83+
94ECFFF023B51DFE6DBE5C93 /* Pods_Runner.framework in Frameworks */,
7884
);
7985
runOnlyForDeploymentPostprocessing = 0;
8086
};
8187
/* End PBXFrameworksBuildPhase section */
8288

8389
/* Begin PBXGroup section */
90+
1B56ADF53E8D786780EEBEA4 /* Pods */ = {
91+
isa = PBXGroup;
92+
children = (
93+
2E4E7A17233CE9BAB4E6AFD4 /* Pods-Runner.debug.xcconfig */,
94+
899C75AD5295627294526A87 /* Pods-Runner.release.xcconfig */,
95+
73CEA9A98397EEB976012B1F /* Pods-Runner.profile.xcconfig */,
96+
);
97+
name = Pods;
98+
path = Pods;
99+
sourceTree = "<group>";
100+
};
84101
33BA886A226E78AF003329D5 /* Configs */ = {
85102
isa = PBXGroup;
86103
children = (
@@ -99,6 +116,7 @@
99116
33CEB47122A05771004F2AC0 /* Flutter */,
100117
33CC10EE2044A3C60003C045 /* Products */,
101118
D73912EC22F37F3D000D13A0 /* Frameworks */,
119+
1B56ADF53E8D786780EEBEA4 /* Pods */,
102120
);
103121
sourceTree = "<group>";
104122
};
@@ -148,6 +166,7 @@
148166
D73912EC22F37F3D000D13A0 /* Frameworks */ = {
149167
isa = PBXGroup;
150168
children = (
169+
A1E695E9169BBD8AA2FC608B /* Pods_Runner.framework */,
151170
);
152171
name = Frameworks;
153172
sourceTree = "<group>";
@@ -159,11 +178,13 @@
159178
isa = PBXNativeTarget;
160179
buildConfigurationList = 33CC10FB2044A3C60003C045 /* Build configuration list for PBXNativeTarget "Runner" */;
161180
buildPhases = (
181+
C805E96BA56A10598CD12267 /* [CP] Check Pods Manifest.lock */,
162182
33CC10E92044A3C60003C045 /* Sources */,
163183
33CC10EA2044A3C60003C045 /* Frameworks */,
164184
33CC10EB2044A3C60003C045 /* Resources */,
165185
33CC110E2044A8840003C045 /* Bundle Framework */,
166186
3399D490228B24CF009A79C7 /* ShellScript */,
187+
AF343D80B522A76F5763B389 /* [CP] Embed Pods Frameworks */,
167188
);
168189
buildRules = (
169190
);
@@ -270,6 +291,45 @@
270291
shellPath = /bin/sh;
271292
shellScript = "\"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh && touch Flutter/ephemeral/tripwire";
272293
};
294+
AF343D80B522A76F5763B389 /* [CP] Embed Pods Frameworks */ = {
295+
isa = PBXShellScriptBuildPhase;
296+
buildActionMask = 2147483647;
297+
files = (
298+
);
299+
inputFileListPaths = (
300+
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
301+
);
302+
name = "[CP] Embed Pods Frameworks";
303+
outputFileListPaths = (
304+
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
305+
);
306+
runOnlyForDeploymentPostprocessing = 0;
307+
shellPath = /bin/sh;
308+
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
309+
showEnvVarsInLog = 0;
310+
};
311+
C805E96BA56A10598CD12267 /* [CP] Check Pods Manifest.lock */ = {
312+
isa = PBXShellScriptBuildPhase;
313+
buildActionMask = 2147483647;
314+
files = (
315+
);
316+
inputFileListPaths = (
317+
);
318+
inputPaths = (
319+
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
320+
"${PODS_ROOT}/Manifest.lock",
321+
);
322+
name = "[CP] Check Pods Manifest.lock";
323+
outputFileListPaths = (
324+
);
325+
outputPaths = (
326+
"$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt",
327+
);
328+
runOnlyForDeploymentPostprocessing = 0;
329+
shellPath = /bin/sh;
330+
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
331+
showEnvVarsInLog = 0;
332+
};
273333
/* End PBXShellScriptBuildPhase section */
274334

275335
/* Begin PBXSourcesBuildPhase section */

example/macos/Runner.xcworkspace/contents.xcworkspacedata

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)