hyzp_ybqx-Commit125:已使用flutter_background_service 0.0.1+21插件,初步实现后台提醒

master
WinUser01 4 years ago
parent 740d79d412
commit 77c57f06db

@ -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;
//sfsy01 //sfsy01
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; // 60S0 int g_remindGap = 60; // 60S0
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(); // doRemind();
// g_remindGap // g_remindGap
setRemindTimer(); // setRemindTimer();
// g_remindTimer = Timer.periodic(Duration(seconds: g_remindGap), (timer) { WidgetsFlutterBinding.ensureInitialized();
// /// FlutterBackgroundService.initialize(onStart);
// doRemind();
// });
} }
// //
// Future doRemind() async {
// //
// 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);
},
)
],
),
],
), ),
), ),
); );

Loading…
Cancel
Save