hyzp_ybqx-Commit125:已使用flutter_background_service 0.0.1+21插件,初步实现后台提醒
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import 'package:hyzp_ybqx/components/commonFun.dart';
|
import 'package:hyzp_ybqx/components/commonFun.dart';
|
||||||
import 'package:hyzp_ybqx/pages/Works/DWDT/dwInfo_data.dart';
|
import 'package:hyzp_ybqx/pages/Works/DWDT/dwInfo_data.dart';
|
||||||
|
import 'package:hyzp_ybqx/services/Storage.dart';
|
||||||
import 'EncryptUtil.dart';
|
import 'EncryptUtil.dart';
|
||||||
import 'commonFun.dart';
|
import 'commonFun.dart';
|
||||||
|
|
||||||
@@ -25,8 +25,10 @@ class UserInfo {
|
|||||||
setQxInfo(mapUserInfo["qx_code"], mapUserInfo["qx_name"]);
|
setQxInfo(mapUserInfo["qx_code"], mapUserInfo["qx_name"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
setQxInfo(String _qx_code, String _qx_name) {
|
setQxInfo(String _qx_code, String _qx_name) async {
|
||||||
qx_code = int.parse(_qx_code.trim());
|
qx_code = int.parse(_qx_code.trim());
|
||||||
|
await Storage.setInt('qx_code', qx_code); // 为启动前台服务,保存 qx_code 到用户配置中
|
||||||
|
|
||||||
qx_name = _qx_name;
|
qx_name = _qx_name;
|
||||||
//区县用户登录接口增加返回字段“sfsy”,0表示正式账号,1表示试用账号
|
//区县用户登录接口增加返回字段“sfsy”,0表示正式账号,1表示试用账号
|
||||||
qx_trial_tag = mapUserInfo['sfsy'];
|
qx_trial_tag = mapUserInfo['sfsy'];
|
||||||
|
|||||||
@@ -119,43 +119,44 @@ const int g_sip = 1; // 新增sip参数,0表示市级平台,1表示区县平
|
|||||||
List listReviewed = [];
|
List listReviewed = [];
|
||||||
bool g_bVoiceRemind = false; // 用户设置是否开启语音提醒
|
bool g_bVoiceRemind = false; // 用户设置是否开启语音提醒
|
||||||
int g_remindGap = 60; // 提醒间隔默认为60S,0表示取消定时提醒
|
int g_remindGap = 60; // 提醒间隔默认为60S,0表示取消定时提醒
|
||||||
Timer g_remindTimer; //定时提醒变量
|
|
||||||
|
|
||||||
// 设置定时提醒
|
// Timer g_remindTimer; //定时提醒变量
|
||||||
setRemindTimer({bool enable = true}) {
|
//
|
||||||
// 先取消旧的定时任务
|
// // 设置定时提醒
|
||||||
if (null != g_remindTimer) {
|
// setRemindTimer({bool enable = true}) {
|
||||||
g_remindTimer.cancel(); //取消计时器
|
// // 先取消旧的定时任务
|
||||||
}
|
// if (null != g_remindTimer) {
|
||||||
|
// g_remindTimer.cancel(); //取消计时器
|
||||||
// 设置新的定时任务
|
// }
|
||||||
if (enable && g_remindGap > 0) {
|
//
|
||||||
///循环执行定时任务,间隔 g_remindGap 秒
|
// // 设置新的定时任务
|
||||||
g_remindTimer = Timer.periodic(Duration(seconds: g_remindGap), (timer) {
|
// if (enable && g_remindGap > 0) {
|
||||||
///定时任务
|
// ///循环执行定时任务,间隔 g_remindGap 秒
|
||||||
doRemind();
|
// g_remindTimer = Timer.periodic(Duration(seconds: g_remindGap), (timer) {
|
||||||
});
|
// ///定时任务
|
||||||
}
|
// doRemind();
|
||||||
}
|
// });
|
||||||
|
// }
|
||||||
// 执行语音提醒
|
// }
|
||||||
Future doRemind() async {
|
//
|
||||||
// 获取待审核黑烟车记录
|
// // 执行语音提醒
|
||||||
if (g_bVoiceRemind) {
|
// Future doRemind() async {
|
||||||
listReviewed.clear();
|
// // 获取待审核黑烟车记录
|
||||||
print("listReviewed = $listReviewed");
|
|
||||||
await getReviewedList(); //注意:访问区县后台接口,需要统一添加区县代码参数
|
|
||||||
print("listReviewed = $listReviewed");
|
|
||||||
// if (g_bVoiceRemind) {
|
// if (g_bVoiceRemind) {
|
||||||
// import 'dart:io';
|
// listReviewed.clear();
|
||||||
// import 'package:audioplayers/audio_cache.dart';
|
// print("listReviewed = $listReviewed");
|
||||||
// print("播放:语音提醒.mp3");
|
// await getReviewedList(); //注意:访问区县后台接口,需要统一添加区县代码参数
|
||||||
if (listReviewed.length > 0) {
|
// print("listReviewed = $listReviewed");
|
||||||
// AudioCache().play(File('audio/语音提醒.mp3').path); //语音提醒
|
// // if (g_bVoiceRemind) {
|
||||||
myPlayVoiceRemind();
|
// // import 'dart:io';
|
||||||
}
|
// // import 'package:audioplayers/audio_cache.dart';
|
||||||
}
|
// // print("播放:语音提醒.mp3");
|
||||||
}
|
// if (listReviewed.length > 0) {
|
||||||
|
// // AudioCache().play(File('audio/语音提醒.mp3').path); //语音提醒
|
||||||
|
// myPlayVoiceRemind();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
///用于定时提醒的变量和函数
|
///用于定时提醒的变量和函数
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import '../../services/ServiceLocator.dart';
|
|||||||
import '../../services/Storage.dart';
|
import '../../services/Storage.dart';
|
||||||
import 'page1_work.dart';
|
import 'page1_work.dart';
|
||||||
// import 'package:audioplayers/audio_cache.dart';
|
// import 'package:audioplayers/audio_cache.dart';
|
||||||
|
import 'package:flutter_background_service/flutter_background_service.dart';
|
||||||
|
import 'package:hyzp_ybqx/pages/tabs/flutter_background_service_my.dart';
|
||||||
|
|
||||||
class Tabs extends StatefulWidget {
|
class Tabs extends StatefulWidget {
|
||||||
Tabs({Key key, this.arguments = 0}) : super(key: key);
|
Tabs({Key key, this.arguments = 0}) : super(key: key);
|
||||||
@@ -65,6 +67,7 @@ class _TabsState extends State<Tabs> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
getlistItems().then((value) => try_setState());
|
getlistItems().then((value) => try_setState());
|
||||||
print('widget.arguments = ${widget.arguments}');
|
print('widget.arguments = ${widget.arguments}');
|
||||||
//_currentIndex = 3 == widget.arguments ? 0 : widget.arguments; //解决"我的"页面根据用户所属组及时刷新问题
|
//_currentIndex = 3 == widget.arguments ? 0 : widget.arguments; //解决"我的"页面根据用户所属组及时刷新问题
|
||||||
@@ -85,47 +88,17 @@ class _TabsState extends State<Tabs> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init() async {
|
init() async {
|
||||||
// // 从磁盘读取变量
|
|
||||||
// g_bVoiceRemind = await Storage.getBool('bVoiceRemind');
|
|
||||||
// g_bVoiceRemind = (null == g_bVoiceRemind) ? false : g_bVoiceRemind;
|
|
||||||
// // print('g_bVoiceRemind = $g_bVoiceRemind');
|
|
||||||
// eventBus.fire(VoiceRemindUpdate('g_bVoiceRemind 数据已更新'));
|
|
||||||
|
|
||||||
// 执行语音提醒
|
// 执行语音提醒
|
||||||
doRemind();
|
|
||||||
|
|
||||||
//设置定时提醒,循环执行定时任务,间隔 g_remindGap 秒
|
|
||||||
setRemindTimer();
|
|
||||||
|
|
||||||
// g_remindTimer = Timer.periodic(Duration(seconds: g_remindGap), (timer) {
|
|
||||||
// ///定时任务
|
|
||||||
// doRemind();
|
// doRemind();
|
||||||
// });
|
//设置定时提醒,循环执行定时任务,间隔 g_remindGap 秒
|
||||||
}
|
// setRemindTimer();
|
||||||
|
|
||||||
// // 执行语音提醒
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
// Future doRemind() async {
|
FlutterBackgroundService.initialize(onStart);
|
||||||
// // 获取待审核黑烟车记录
|
}
|
||||||
// listReviewed.clear();
|
|
||||||
// print("listReviewed = $listReviewed");
|
|
||||||
// await getReviewedList(); //注意:访问区县后台接口,需要统一添加区县代码参数
|
|
||||||
// print("listReviewed = $listReviewed");
|
|
||||||
// if (g_bVoiceRemind && listReviewed.length > 0) {
|
|
||||||
// // if (g_bVoiceRemind) {
|
|
||||||
// // import 'dart:io';
|
|
||||||
// // import 'package:audioplayers/audio_cache.dart';
|
|
||||||
// // print("播放:语音提醒.mp3");
|
|
||||||
// AudioCache().play(File('audio/语音提醒.mp3').path); //语音提醒
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
// 取消定时任务
|
|
||||||
if (null != g_remindTimer) {
|
|
||||||
g_remindTimer.cancel(); //取消计时器
|
|
||||||
}
|
|
||||||
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import 'package:hyzp_ybqx/services/Storage.dart';
|
|||||||
|
|
||||||
import '../../components/commonFun.dart';
|
import '../../components/commonFun.dart';
|
||||||
import '../../widget/JdButton.dart';
|
import '../../widget/JdButton.dart';
|
||||||
|
import 'package:flutter_background_service/flutter_background_service.dart';
|
||||||
|
import 'package:hyzp_ybqx/pages/tabs/flutter_background_service_my.dart';
|
||||||
|
|
||||||
class page7_setRemind extends StatefulWidget {
|
class page7_setRemind extends StatefulWidget {
|
||||||
page7_setRemind({Key key}) : super(key: key);
|
page7_setRemind({Key key}) : super(key: key);
|
||||||
@@ -19,6 +21,9 @@ class page7_setRemind extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _LoginPageState extends State<page7_setRemind> {
|
class _LoginPageState extends State<page7_setRemind> {
|
||||||
|
bool bVoiceRemind;
|
||||||
|
int remindGap;
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
@@ -27,16 +32,7 @@ class _LoginPageState extends State<page7_setRemind> {
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
bVoiceRemind = g_bVoiceRemind;
|
bVoiceRemind = g_bVoiceRemind;
|
||||||
|
remindGap = g_remindGap;
|
||||||
getListView();
|
|
||||||
|
|
||||||
// //监听 g_bVoiceRemind 更新事件
|
|
||||||
// eventBus.on<VoiceRemindUpdate>().listen((event) async {
|
|
||||||
// print(event.str + ", g_bVoiceRemind = $g_bVoiceRemind");
|
|
||||||
// setState(() {
|
|
||||||
// getListView();
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////
|
////////
|
||||||
@@ -106,85 +102,15 @@ class _LoginPageState extends State<page7_setRemind> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
bVoiceRemind = !bVoiceRemind;
|
bVoiceRemind = !bVoiceRemind;
|
||||||
print("bVoiceRemind = $bVoiceRemind");
|
print("bVoiceRemind = $bVoiceRemind");
|
||||||
// Storage.setBool('bVoiceRemind', bVoiceRemind);
|
|
||||||
if (bVoiceRemind) {
|
|
||||||
print("播放语音提醒");
|
print("播放语音提醒");
|
||||||
// AudioCache().play(File('audio/语音提醒.mp3').path); //语音提醒
|
if (bVoiceRemind) {
|
||||||
myPlayVoiceRemind();
|
myPlayVoiceRemind();
|
||||||
|
} else {
|
||||||
|
myPlayClick();
|
||||||
}
|
}
|
||||||
getListView();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bVoiceRemind;
|
|
||||||
|
|
||||||
getListView() {
|
|
||||||
_listViewUser.clear();
|
|
||||||
_listViewUser = [
|
|
||||||
Center(
|
|
||||||
child: Container(
|
|
||||||
margin: EdgeInsets.only(top: 30),
|
|
||||||
height: ScreenUtil().setWidth(160),
|
|
||||||
width: ScreenUtil().setWidth(160),
|
|
||||||
//child: Image.asset('assets/images/user.png', fit: BoxFit.cover),
|
|
||||||
child: Image.asset('assets/images/ybsthbj.png', fit: BoxFit.fitHeight),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
SizedBox(height: 50),
|
|
||||||
_getListTile('待审提醒',
|
|
||||||
leadPath: 'assets/images/语音提醒.png',
|
|
||||||
leadColor: _deepGreyColor,
|
|
||||||
textColor: bVoiceRemind ? Colors.blue : null,
|
|
||||||
onTapFun: OnTap_Remind,
|
|
||||||
trailWidget: bVoiceRemind
|
|
||||||
? Icon(Icons.check_box, color: Colors.blue)
|
|
||||||
: Icon(Icons.check_box_outline_blank, color: Colors.blueAccent)),
|
|
||||||
_getListTile('提醒间隔(秒)',
|
|
||||||
leadPath: 'assets/images/时间间隔.png',
|
|
||||||
leadColor: _deepBlueColor,
|
|
||||||
trailWidget: getTextField()),
|
|
||||||
SizedBox(height: 60),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
||||||
children: [
|
|
||||||
JdButton(
|
|
||||||
height: 128,
|
|
||||||
width: 282,
|
|
||||||
//height: 126,
|
|
||||||
text: "确认",
|
|
||||||
color: Colors.blueAccent,
|
|
||||||
onTop: () {
|
|
||||||
g_bVoiceRemind = bVoiceRemind;
|
|
||||||
print("g_bVoiceRemind = $g_bVoiceRemind");
|
|
||||||
Storage.setBool('bVoiceRemind', g_bVoiceRemind);
|
|
||||||
|
|
||||||
g_remindGap = _gap;
|
|
||||||
print("g_remindGap = $g_remindGap");
|
|
||||||
Storage.setInt('nRemindGap', g_remindGap);
|
|
||||||
setRemindTimer(enable: g_bVoiceRemind);
|
|
||||||
|
|
||||||
// AudioCache().play(File('audio/yinxiao1064.mp3').path); //音效提醒
|
|
||||||
myPlayClacks(); //音效提醒
|
|
||||||
Navigator.pop(context);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
JdButton(
|
|
||||||
height: 128,
|
|
||||||
width: 282,
|
|
||||||
//height: 126,
|
|
||||||
text: "取消",
|
|
||||||
color: Colors.blueAccent,
|
|
||||||
onTop: () {
|
|
||||||
Navigator.pop(context);
|
|
||||||
},
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
int _gap = g_remindGap;
|
|
||||||
|
|
||||||
Widget getTextField() {
|
Widget getTextField() {
|
||||||
return Container(
|
return Container(
|
||||||
width: ScreenUtil().setWidth(150),
|
width: ScreenUtil().setWidth(150),
|
||||||
@@ -193,10 +119,10 @@ class _LoginPageState extends State<page7_setRemind> {
|
|||||||
focusNode: FocusNode(),
|
focusNode: FocusNode(),
|
||||||
textAlignVertical: TextAlignVertical(y: 1.0),
|
textAlignVertical: TextAlignVertical(y: 1.0),
|
||||||
controller: TextEditingController.fromValue(TextEditingValue(
|
controller: TextEditingController.fromValue(TextEditingValue(
|
||||||
text: _gap.toString(),
|
text: remindGap.toString(),
|
||||||
// 保持光标在最后
|
// 保持光标在最后
|
||||||
selection: TextSelection.fromPosition(
|
selection: TextSelection.fromPosition(TextPosition(
|
||||||
TextPosition(affinity: TextAffinity.downstream, offset: _gap.toString().length)))),
|
affinity: TextAffinity.downstream, offset: remindGap.toString().length)))),
|
||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
@@ -209,7 +135,7 @@ class _LoginPageState extends State<page7_setRemind> {
|
|||||||
enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.lightBlue)),
|
enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.lightBlue)),
|
||||||
),
|
),
|
||||||
onChanged: (v) {
|
onChanged: (v) {
|
||||||
_gap = int.parse(v);
|
remindGap = int.parse(v);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -279,7 +205,83 @@ class _LoginPageState extends State<page7_setRemind> {
|
|||||||
body: Container(
|
body: Container(
|
||||||
padding: EdgeInsets.only(top: 30, bottom: 20, left: 20, right: 20),
|
padding: EdgeInsets.only(top: 30, bottom: 20, left: 20, right: 20),
|
||||||
child: ListView(
|
child: ListView(
|
||||||
children: _listViewUser,
|
children: [
|
||||||
|
Center(
|
||||||
|
child: Container(
|
||||||
|
margin: EdgeInsets.only(top: 30),
|
||||||
|
height: ScreenUtil().setWidth(160),
|
||||||
|
width: ScreenUtil().setWidth(160),
|
||||||
|
//child: Image.asset('assets/images/user.png', fit: BoxFit.cover),
|
||||||
|
child: Image.asset('assets/images/ybsthbj.png', fit: BoxFit.fitHeight),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 50),
|
||||||
|
_getListTile('待审提醒',
|
||||||
|
leadPath: 'assets/images/语音提醒.png',
|
||||||
|
leadColor: _deepGreyColor,
|
||||||
|
textColor: bVoiceRemind ? Colors.blue : null,
|
||||||
|
onTapFun: OnTap_Remind,
|
||||||
|
trailWidget: bVoiceRemind
|
||||||
|
? Icon(Icons.check_box, color: Colors.blue)
|
||||||
|
: Icon(Icons.check_box_outline_blank, color: Colors.blueAccent)),
|
||||||
|
_getListTile('提醒间隔(秒)',
|
||||||
|
leadPath: 'assets/images/时间间隔.png',
|
||||||
|
leadColor: _deepBlueColor,
|
||||||
|
trailWidget: getTextField()),
|
||||||
|
SizedBox(height: 60),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||||
|
children: [
|
||||||
|
JdButton(
|
||||||
|
height: 128,
|
||||||
|
width: 282,
|
||||||
|
//height: 126,
|
||||||
|
text: "确认",
|
||||||
|
color: Colors.blueAccent,
|
||||||
|
onTop: () async {
|
||||||
|
if (g_bVoiceRemind != bVoiceRemind && g_remindGap != remindGap) {
|
||||||
|
if (await FlutterBackgroundService().isServiceRunning()) {
|
||||||
|
FlutterBackgroundService().sendData({"action": "stopService"});
|
||||||
|
}
|
||||||
|
|
||||||
|
g_bVoiceRemind = bVoiceRemind;
|
||||||
|
print("g_bVoiceRemind = $g_bVoiceRemind");
|
||||||
|
await Storage.setBool('bVoiceRemind', g_bVoiceRemind);
|
||||||
|
|
||||||
|
g_remindGap = remindGap;
|
||||||
|
print("g_remindGap = $g_remindGap");
|
||||||
|
await Storage.setInt('nRemindGap', g_remindGap);
|
||||||
|
|
||||||
|
if (bVoiceRemind) {
|
||||||
|
while (true) {
|
||||||
|
var isRunning = await FlutterBackgroundService().isServiceRunning();
|
||||||
|
if (!isRunning) {
|
||||||
|
await FlutterBackgroundService.initialize(onStart);
|
||||||
|
myPlayVoiceRemind();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
myPlayClick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
JdButton(
|
||||||
|
height: 128,
|
||||||
|
width: 282,
|
||||||
|
//height: 126,
|
||||||
|
text: "取消",
|
||||||
|
color: Colors.blueAccent,
|
||||||
|
onTop: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user