16
16
17
17
## ` Installation `
18
18
19
- Add this to your package's pubspec.yaml file:
19
+ - Add this to your package's pubspec.yaml file:
20
20
21
21
``` yaml
22
22
dependencies :
@@ -25,10 +25,20 @@ dependencies:
25
25
26
26
and
27
27
28
+ - Download dependencies
29
+
28
30
` ` ` sh
29
31
flutter pub get
30
32
```
31
33
34
+ and
35
+
36
+ - Create or Edit file .env api Key
37
+
38
+ ```
39
+ PUSH_LINK_API_KEY=your-api-key
40
+ ```
41
+
32
42
---
33
43
34
44
## ` Running Project `
@@ -73,214 +83,12 @@ import 'package:flutter_push_link/flutter_push_link.dart';
73
83
...
74
84
75
85
String deviceId = await FlutterPushLink.deviceId().catchError(onError);
76
- bool started = await FlutterPushLink.startPushLink(DotEnv.env['PUSH_LINK_API_KEY'], deviceId).catchError(onError);
77
- ```
78
86
79
- <details >
80
- <summary >Click to expand! (main.dart)</summary >
81
-
82
- ## Example code application
83
-
84
- ``` dart
85
- import 'package:flutter/material.dart';
86
- import 'dart:async';
87
- import 'package:flutter_statusbarcolor/flutter_statusbarcolor.dart';
88
- import 'package:flutter_dotenv/flutter_dotenv.dart' as DotEnv;
89
-
90
- import 'package:flutter_push_link/flutter_push_link.dart';
87
+ bool started = await FlutterPushLink.startPushLink(DotEnv.env['PUSH_LINK_API_KEY'], deviceId).catchError(onError);
91
88
92
- void main() async {
93
- await DotEnv.load(fileName: ".env");
94
- runApp(MyApp());
95
- }
96
-
97
- class MyApp extends StatefulWidget {
98
- @override
99
- _MyAppState createState() => _MyAppState();
100
- }
101
-
102
- class HexColor extends Color {
103
- static int _getColorFromHex(String hexColor) {
104
- hexColor = hexColor.toUpperCase().replaceAll("#", "");
105
- if (hexColor.length == 6) {
106
- hexColor = "FF" + hexColor;
107
- }
108
- return int.parse(hexColor, radix: 16);
109
- }
110
-
111
- HexColor(final String hexColor) : super(_getColorFromHex(hexColor));
112
- }
113
-
114
- void onError(dynamic error) {
115
- debugPrint("onError Print: " + error);
116
- FlutterPushLink.toastMessage(error);
117
- }
118
-
119
- class _MyAppState extends State<MyApp> {
120
- String _deviceId = '';
121
- Map currentStrategy;
122
- bool pushLinkStaterd = false;
123
- String currentStrategySelected = 'CUSTOM';
124
- List<String> strategys = ['ANNOYING_POPUP', 'FRIENDLY_POPUP', 'STATUS_BAR', 'CUSTOM', 'NINJA'];
125
-
126
- @override
127
- void initState() {
128
- super.initState();
129
- initPlatformState();
130
- }
131
-
132
- Future<void> initPlatformState() async {
133
- String deviceId = await FlutterPushLink.deviceId().catchError(onError);
134
- if (!mounted) return;
135
- getCurrentStrategy();
136
- setState(() => _deviceId = deviceId);
137
- }
138
-
139
- void getCurrentStrategy() async {
140
- currentStrategy = await FlutterPushLink.getCurrentStrategy().catchError(onError);
141
- setState(() => currentStrategy = currentStrategy);
142
- }
143
-
144
- void startPushLink() async {
145
- bool started = await FlutterPushLink.startPushLink(DotEnv.env['PUSH_LINK_API_KEY'], _deviceId).catchError(onError);
146
- setState(() => pushLinkStaterd = started);
147
- }
148
-
149
- void _reciverEventListenerCustom(data) {
150
- debugPrint("_reciverEventListener CUSTOM $data");
151
- }
152
-
153
- void selectStrategy() async {
154
- switch (currentStrategySelected) {
155
- case 'ANNOYING_POPUP':
156
- AnnoyingPopupProperties annoyingPopupProperties;
157
- annoyingPopupProperties.popUpMessage = 'Update PushLink Example';
158
- annoyingPopupProperties.updateButton = 'Update';
159
- await FlutterPushLink.setStrategyAnnoyingPoup(annoyingPopupProperties).catchError(onError);
160
- break;
161
- case 'FRIENDLY_POPUP':
162
- FriendlyePopupProperties friendlyePopupProperties;
163
- friendlyePopupProperties.notNowButton = 'Now';
164
- friendlyePopupProperties.popUpMessage = 'Update PushLink Example';
165
- friendlyePopupProperties.reminderTimeInSeconds = 60;
166
- friendlyePopupProperties.updateButton = 'Update';
167
- await FlutterPushLink.setStrategyFriendlyPopup(friendlyePopupProperties).catchError(onError);
168
- break;
169
- case 'STATUS_BAR':
170
- StatusBarProperties statusBarProperties;
171
- statusBarProperties.statusBarDescription = 'Click to Update, PushLink Example Flutter';
172
- statusBarProperties.statusBarTitle = 'New version Application Example Flutter';
173
- await FlutterPushLink.setStrategyStatusBar(statusBarProperties).catchError(onError);
174
- break;
175
- case 'CUSTOM':
176
- FlutterPushLink.toastMessage("CUSTOM requires the app to be DEVICE OWNER");
177
- await FlutterPushLink.setStrategyCustom(TypesBroadcastReceiver.APPLY, _reciverEventListenerCustom).catchError(onError);
178
- break;
179
- case 'NINJA':
180
- FlutterPushLink.toastMessage("NINJA only for ROOTED devices (DEPRECATED)");
181
- await FlutterPushLink.setStrategyNinja();
182
- break;
183
- default:
184
- }
185
- getCurrentStrategy();
186
- }
187
-
188
- @override
189
- Widget build(BuildContext context) {
190
- FlutterStatusbarcolor.setStatusBarColor(Colors.transparent);
191
- FlutterStatusbarcolor.setStatusBarWhiteForeground(true);
192
- FlutterStatusbarcolor.setNavigationBarWhiteForeground(true);
193
- FlutterStatusbarcolor.setNavigationBarColor(HexColor('#3d9874'), animate: true);
194
-
195
- return MaterialApp(
196
- debugShowCheckedModeBanner: false,
197
- theme: ThemeData(
198
- primaryColor: HexColor('#3d9874'),
199
- primarySwatch: Colors.blue,
200
- ),
201
- home: Scaffold(
202
- appBar: AppBar(
203
- title: const Text('PushLink Example'),
204
- ),
205
- body: SingleChildScrollView(
206
- child: Column(
207
- children: [
208
- Container(
209
- margin: EdgeInsets.only(top: 30.0, bottom: 30),
210
- child: Image.network('https://pushlink.com/javax.faces.resource/images/site/logo-verde.png.xhtml?ln=pushlink',
211
- width: 250, fit: BoxFit.contain)),
212
- Container(
213
- margin: EdgeInsets.only(bottom: 20),
214
- child: Center(
215
- child: Text(
216
- 'DeviceId: $_deviceId',
217
- textAlign: TextAlign.center,
218
- ),
219
- ),
220
- ),
221
- ElevatedButton(
222
- onPressed: () => {startPushLink()},
223
- child: Text('Start PushLink'),
224
- style: ElevatedButton.styleFrom(
225
- primary: Colors.red, // background
226
- onPrimary: Colors.white, // foreground
227
- ),
228
- ),
229
- Container(
230
- margin: EdgeInsets.only(top: 30),
231
- child: Text(
232
- 'Current Strategy:',
233
- style: TextStyle(color: Colors.black.withOpacity(0.6), fontWeight: FontWeight.bold),
234
- textAlign: TextAlign.center,
235
- ),
236
- ),
237
- Container(
238
- child: Text(
239
- currentStrategy.toString(),
240
- style: TextStyle(color: Colors.black.withOpacity(0.4), fontSize: 12),
241
- textAlign: TextAlign.center,
242
- ),
243
- ),
244
- Container(
245
- margin: EdgeInsets.only(top: 30),
246
- child: Text(
247
- 'Select Strategy:',
248
- style: TextStyle(color: Colors.black.withOpacity(0.6), fontWeight: FontWeight.bold),
249
- ),
250
- ),
251
- Container(
252
- child: DropdownButton<String>(
253
- value: currentStrategySelected,
254
- onChanged: (String newValue) {
255
- setState(() {
256
- currentStrategySelected = newValue;
257
- });
258
- },
259
- items: strategys.map<DropdownMenuItem<String>>((String value) {
260
- return DropdownMenuItem<String>(
261
- value: value,
262
- child: Text(value),
263
- );
264
- }).toList(),
265
- ),
266
- ),
267
- ElevatedButton(
268
- onPressed: () => {selectStrategy()},
269
- child: Text('Set Strategy'),
270
- style: ElevatedButton.styleFrom(
271
- primary: HexColor("#1fa6cb"), // background
272
- onPrimary: Colors.white, // foreground
273
- ),
274
- ),
275
- ],
276
- )),
277
- ),
278
- );
279
- }
280
- }
281
89
```
282
90
283
- </ details >
91
+ <a target = " _blank " href = " https://github.com/diogo-bruno/flutter-push-link/blob/master/example/lib/main.dart " >Open file Application: < b >main.dart</ b ></ a >
284
92
285
93
---
286
94
0 commit comments