hyzp_ybqx-Commit138:已经将flutter_background_service_my.dart文件添加到git库中

master
WinUser01 4 years ago
parent 7dbf4f0901
commit 8c33cb05bf

@ -871,7 +871,7 @@ Widget getImageWidget() {
color: Color.fromRGBO(49, 216, 123, 1),
fontWeight: FontWeight.bold)),
),
SizedBox(height: ScreenUtil().setHeight(copyright_info.contains('\n') ? 50 : 90)),
SizedBox(height: ScreenUtil().setHeight(copyright_info.contains('\n') ? 40 : 90)),
Container(
alignment: Alignment.center,
child: Text(copyright_info,

@ -0,0 +1,85 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_background_service/flutter_background_service.dart';
import '../../services/Storage.dart';
import '../../components/commonFun.dart';
import '../../components/dioFun.dart';
int remindCount = 0;
void onStart() {
WidgetsFlutterBinding.ensureInitialized();
final service = FlutterBackgroundService();
service.onDataReceived.listen((event) {
if (event["action"] == "setAsForeground") {
service.setForegroundMode(true);
return;
}
if (event["action"] == "setAsBackground") {
service.setForegroundMode(false);
}
if (event["action"] == "stopService") {
service.stopBackgroundService();
}
});
// service.setForegroundMode(true);
setRemindTimer(service);
}
//
setRemindTimer(FlutterBackgroundService service) async {
g_remindGap = await Storage.getInt('nRemindGap');
g_remindGap = (null == g_remindGap) ? 60 : g_remindGap; // 60S
print('g_remindGap = $g_remindGap');
g_bVoiceRemind = await Storage.getBool('bVoiceRemind');
g_bVoiceRemind = (null == g_bVoiceRemind) ? true : g_bVoiceRemind; //
print('g_bVoiceRemind = $g_bVoiceRemind');
service.setForegroundMode(g_bVoiceRemind);
//
if (g_bVoiceRemind && g_remindGap > 0) {
remindCount = 0;
// remindGap
Timer.periodic(Duration(seconds: g_remindGap), (timer) async {
if (await service.isServiceRunning()) {
doRemind();
} else {
timer.cancel();
}
service.setNotificationInfo(
title: "My App Service",
content: "Updated at ${DateTime.now()}",
);
service.sendData({"current_date": DateTime.now().toIso8601String()});
});
if (qx_code < 0) {
qx_code = await Storage.getInt('qx_code'); // qx_code
}
print("设置间隔 ${g_remindGap}S 的定时任务成功!");
}
}
doRemind() async {
await getReviewedList(); //访
if (listReviewed.length > 0) {
//
myPlayVoiceRemind();
remindCount++;
DateTime dateTime = DateTime.now();
print(
"语音提醒(gap=${g_remindGap}S) ${remindCount.toString().padLeft(6, '0')}${dateTime.hour.toString().padLeft(2, '0')}:${dateTime.minute.toString().padLeft(2, '0')}:${dateTime.second.toString().padLeft(2, '0')}");
}
}
Loading…
Cancel
Save