@@ -44,10 +44,69 @@ Displays as a notification in the notification center [Help Needed]
44
44
45
45
## Example
46
46
47
- ### Request overlay permission
47
+ #### Show Overlay
48
+
49
+ #### Request overlay permission
48
50
await SystemAlertWindow.requestPermissions;
49
51
50
- ### Show the overlay
52
+ ### Inside ` main.dart ` create an entry point for your Overlay widget;
53
+ ``` dart
54
+ // overlay entry point
55
+ @pragma("vm:entry-point")
56
+ void overlayMain() {
57
+ runApp(const MaterialApp(
58
+ debugShowCheckedModeBanner: false,
59
+ home: Material(child: Text("My overlay"))
60
+ ));
61
+ }
62
+
63
+
64
+ //Open overLay content
65
+
66
+ // - Optional arguments:
67
+ /// `gravity` Position of the window and default is [SystemWindowGravity.CENTER]
68
+ /// `width` Width of the window and default is [Constants.MATCH_PARENT]
69
+ /// `height` Height of the window and default is [Constants.WRAP_CONTENT]
70
+ /// `notificationTitle` Notification title, applicable in case of bubble
71
+ /// `notificationBody` Notification body, applicable in case of bubble
72
+ /// `prefMode` Preference for the system window. Default is [SystemWindowPrefMode.DEFAULT]
73
+ /// `isDisableClicks` Disables the clicks across the system window. Default is false. This is not applicable for bubbles.
74
+ await SystemAlertWindow.showSystemWindow();
75
+
76
+ // closes overlay if open
77
+ await SystemAlertWindow.closeSystemWindow();
78
+
79
+ // broadcast data to and from overlay app
80
+ await SystemAlertWindow.sendMessageToOverlay("Hello from the other side");
81
+
82
+ //streams message shared between overlay and main app
83
+ SystemAlertWindow.overlayListener.listen((event) {
84
+ log("Current Event: $event");
85
+ });
86
+
87
+ //to add custom logs in log file
88
+ SystemAlertWindow.addCustomLog("add custom log")
89
+
90
+
91
+ /// update the overlay flag while the overlay in action
92
+ /// - Optional arguments:
93
+ /// `gravity` Position of the window and default is [SystemWindowGravity.CENTER]
94
+ /// `width` Width of the window and default is [Constants.MATCH_PARENT]
95
+ /// `height` Height of the window and default is [Constants.WRAP_CONTENT]
96
+ /// `notificationTitle` Notification title, applicable in case of bubble
97
+ /// `notificationBody` Notification body, applicable in case of bubble
98
+ /// `prefMode` Preference for the system window. Default is [SystemWindowPrefMode.DEFAULT]
99
+ /// `isDisableClicks` Disables the clicks across the system window. Default is false. This is not applicable for bubbles.
100
+ await FlutterOverlayWindow.updateSystemWindow();
101
+
102
+ ```
103
+
104
+ ### Close the overlay
105
+ SystemAlertWindow.closeSystemWindow();
106
+
107
+
108
+
109
+ #### Show the Bubble
51
110
52
111
SystemWindowHeader header = SystemWindowHeader(
53
112
title: SystemWindowText(text: "Incoming Call", fontSize: 10, textColor: Colors.black45),
@@ -111,7 +170,7 @@ Displays as a notification in the notification center [Help Needed]
111
170
//Using SystemWindowPrefMode.OVERLAY forces overlay window instead of bubble in Android 11.
112
171
//Using SystemWindowPrefMode.BUBBLE forces Bubble instead of overlay window in Android 10 & above
113
172
114
- ### Register for onClick events (button click)
173
+ #### Register for onClick events (button click)
115
174
116
175
SystemAlertWindow.registerOnClickListener(callBackFunction);
117
176
@@ -136,12 +195,9 @@ Displays as a notification in the notification center [Help Needed]
136
195
}
137
196
}
138
197
139
- ### Close the overlay
140
198
141
- SystemAlertWindow.closeSystemWindow();
142
-
143
- ### Isolate communication
144
- ##### Use this snippet, if you want the callbacks on your main thread, instead of handling them in an isolate (like mentioned above)
199
+ #### Isolate communication
200
+ ###### Use this snippet, if you want the callbacks on your main thread, instead of handling them in an isolate (like mentioned above)
145
201
146
202
###### Create an isolate_manager.dart
147
203
```
@@ -193,7 +249,7 @@ class IsolateManager{
193
249
SystemAlertWindow.registerOnClickListener(callBackFunction);
194
250
```
195
251
196
- ###### Now the callBackFunction should looks like
252
+ ###### Now the callBackFunction should looks like
197
253
```
198
254
bool callBackFunction(String tag) {
199
255
print("Got tag " + tag);
@@ -202,3 +258,7 @@ bool callBackFunction(String tag) {
202
258
return true;
203
259
}
204
260
```
261
+
262
+
263
+
264
+
0 commit comments