-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.dart
179 lines (156 loc) · 5.71 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:allnotification/allnotification.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
String _alarmUri = 'Unknown';
String _ringToneUri = 'Unknown';
String _notificationUri = 'Unknown';
String _timeZoneName = 'Unknown';
String _drawableUri = 'Unknown';
String _currentAppPackageName = 'Unknown';
Timer timer;
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
platformVersion = await AllNotification.platformVersion;
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
String alarmUri;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
alarmUri = await AllNotification.getAlarmUri();
} on PlatformException {
alarmUri = 'Failed to get platform version.';
}
String ringToneUri;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
ringToneUri = await AllNotification.getRingToneUri();
} on PlatformException {
ringToneUri = 'Failed to get platform version.';
}
String notificationUri;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
notificationUri = await AllNotification.getNotificationUri();
} on PlatformException {
notificationUri = 'Failed to get platform version.';
}
String timeZoneName;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
timeZoneName = await AllNotification.getTimeZoneName();
} on PlatformException {
timeZoneName = 'Failed to get platform version.';
}
String drawableUri;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
drawableUri = await AllNotification.drawableToUri('ic_launcher');
} on PlatformException {
drawableUri = 'Failed to get platform version.';
}
String currentAppPackageName;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
currentAppPackageName = await AllNotification.getCurrentAppPackageName();
} on PlatformException {
currentAppPackageName = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
_alarmUri = alarmUri;
_ringToneUri = ringToneUri;
_notificationUri = notificationUri;
_timeZoneName = timeZoneName;
_drawableUri = drawableUri;
_currentAppPackageName = currentAppPackageName;
});
final channelName1 = 'Battery Notification Service';
final channelName2 = 'Battery Notification Service2';
openFileExplorerForAudio().then((path) async {
Uri uri = Uri.file(path, windows: false);
print('Uri path: ${uri.path}');
print('Uri ToFilePath: ${uri.toFilePath(windows: false)}');
print('Uri ToString: ${uri.toString()}');
print('Uri IsAbsolute: ${uri.isAbsolute}');
await AllNotification().newNotification(channelName1, channelName1, channelName1, "HeadsUp",
"Unplug/Plug your device, your battery has reached its charging/discharging limit", true, 0,
maxProgress: 100, progress: 50, showProgress: true);
timer = Timer.periodic(Duration(seconds: 10), (timer) async {
print("Timer is firing another notification..");
await AllNotification().showSoundUriNotification(channelName2, channelName2, channelName2, "Battery Alert!",
"Unplug/Plug your device, your battery has reached its charging/discharging limit", true, 0,
maxProgress: 100, progress: 50, showProgress: false, soundUri: await AllNotification.getRingToneUri());
});
});
}
@override
void dispose() {
timer?.cancel();
super.dispose();
}
Future<String> openFileExplorerForAudio() async {
String _fileName;
List<PlatformFile> _paths;
try {
_paths = (await FilePicker.platform.pickFiles(
type: FileType.audio,
allowMultiple: false,
))
?.files;
} on PlatformException catch (e) {
print("Unsupported operation" + e.toString());
} catch (ex) {
print(ex);
}
_fileName = _paths != null ? _paths.map((platformFile) => platformFile.name).toList()[0] : '...';
final path = _paths != null ? _paths.map((e) => e.path).toList()[0] : null;
return path;
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
children: [
Text('Running on: $_platformVersion\n'),
Text('alarmUri: $_alarmUri\n'),
Text('ringToneUri: $_ringToneUri\n'),
Text('notificationUri: $_notificationUri\n'),
Text('timeZoneName: $_timeZoneName\n'),
Text('drawableUri: $_drawableUri\n'),
Text('currentAppPackageName: $_currentAppPackageName\n'),
],
),
),
),
);
}
}