Skip to content

Commit

Permalink
修复定时器不生效问题
Browse files Browse the repository at this point in the history
  • Loading branch information
nano71 committed Nov 24, 2021
1 parent d60e305 commit 3d20dd8
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 81 deletions.
3 changes: 0 additions & 3 deletions android/app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
</manifest>
3 changes: 0 additions & 3 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@
android:name="flutterEmbedding"
android:value="2" />
</application>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
</manifest>
3 changes: 0 additions & 3 deletions android/app/src/profile/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
</manifest>
2 changes: 2 additions & 0 deletions lib/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class QueryExamRe {

QueryExamRe(this.index);
}

class QueryScoreRe {
int index;

Expand Down Expand Up @@ -58,6 +59,7 @@ Map writeData = {
"color": "blue",
"querySemester": "",
"queryYear": "",
"threshold": "5"
};
List todaySchedule = [];
List tomorrowSchedule = [];
Expand Down
79 changes: 74 additions & 5 deletions lib/pages/setting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class _SettingPageState extends State<SettingPage> with WidgetsBindingObserver {
Row(
children: [
Icon(
!focusNodeType ? Icons.date_range_outlined : Icons.edit_outlined,
Icons.date_range_outlined,
color: readColor(),
),
Container(
Expand Down Expand Up @@ -107,7 +107,7 @@ class _SettingPageState extends State<SettingPage> with WidgetsBindingObserver {
Row(
children: [
Icon(
!focusNode2Type ? Icons.toys_outlined : Icons.edit_outlined,
Icons.toys_outlined,
color: readColor(),
),
Container(
Expand Down Expand Up @@ -206,8 +206,6 @@ class _SettingPageState extends State<SettingPage> with WidgetsBindingObserver {
setState(() {
writeData["color"] = value;
});
// Scaffold.of(context).removeCurrentSnackBar();
// Scaffold.of(context).showSnackBar(jwSnackBar(true, "重新启动后APP生效", 10));
writeConfig();
pageBus.fire(SetPageIndex(0));
Navigator.pushAndRemoveUntil(
Expand All @@ -217,13 +215,84 @@ class _SettingPageState extends State<SettingPage> with WidgetsBindingObserver {
type: 0,
),
),
(route) => false,
(route) => false,
);
},
);
})
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Icon(
Icons.flip_to_back,
color: readColor(),
),
Container(
padding: const EdgeInsets.fromLTRB(16, 14, 0, 14),
child: const Text(
"APP生命",
style: TextStyle(fontSize: 16, color: Colors.black),
),
)
],
),
Builder(builder: (BuildContext context) {
return DropdownButton(
iconEnabledColor: readColor(),
elevation: 0,
hint: Text(
writeData["threshold"] != null
? writeData["threshold"] + "分钟"
: "5分钟",
style: TextStyle(color: readColor()),
),
items: [
DropdownMenuItem(
child: Text(
"5分钟",
),
value: "5"),
DropdownMenuItem(
child: Text(
"10分钟",
),
value: "10"),
DropdownMenuItem(
child: Text(
"20分钟",
),
value: "20"),
DropdownMenuItem(
child: Text(
"30分钟",
),
value: "30"),
DropdownMenuItem(
child: Text(
"40分钟",
),
value: "40"),
DropdownMenuItem(
child: Text(
"不限",
),
value: "9999999999"),
],
underline: Container(height: 0),
onChanged: (value) {
setState(() {
writeData["threshold"] = value;
});
writeConfig();
},
);
})
],
),
InkWell(
onTap: () {
Navigator.of(context).push(
Expand Down
135 changes: 69 additions & 66 deletions lib/widget/lists.dart
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:glutassistantn/config.dart';

import '../data.dart';

GlobalKey<TodayCourseListState> todayCourseListKey = GlobalKey();
GlobalKey<TomorrowCourseListState> tomorrowCourseListKey = GlobalKey();

List _getStartTime(index) {
var startH = startTimeList[index - 1][0];
var endH = endTimeList[index - 1][0];
var startM = startTimeList[index - 1][1];
var endM = endTimeList[index - 1][1];
var y = DateTime
.now()
.year;
var m = DateTime
.now()
.month;
var d = DateTime
.now()
.day;
var h = DateTime
.now()
.hour;
var mm = DateTime
.now()
.minute;
var y = DateTime.now().year;
var m = DateTime.now().month;
var d = DateTime.now().day;
var h = DateTime.now().hour;
var mm = DateTime.now().minute;
var difference = DateTime(y, m, d, startH, startM).difference(DateTime(y, m, d, h, mm));
var difference2 = DateTime(y, m, d, endH, endM).difference(DateTime(y, m, d, h, mm));
bool studying = false;
Expand Down Expand Up @@ -76,30 +70,30 @@ String _timeText(int index) {
}
}

List<String> _timeText2(int index) {
if (index == -1) return ["0", "0"];
List value = _getStartTime(int.parse(todaySchedule[index][3]));
if (value[0] >= 1) {
return ["0", "0"];
} else if (value[1] >= 4) {
return ["0", "0"];
} else if (value[1] >= 1) {
if (value[2] == 0) return [value[1].toString(), "0"];
return [value[1].toString(), value[2].toString()];
} else if (value[3] == "after") {
if (value[2] < 46 && value[2] > 0) {
if (value[1] == 0.0) {
return ["0", value[2].toString()];
} else {
return ["0", "0"];
}
} else {
return ["0", "0"];
}
} else {
return ["0", value[2].toString()];
}
}
// List<String> _timeText2(int index) {
// if (index == -1) return ["0", "0"];
// List value = _getStartTime(int.parse(todaySchedule[index][3]));
// if (value[0] >= 1) {
// return ["0", "0"];
// } else if (value[1] >= 4) {
// return ["0", "0"];
// } else if (value[1] >= 1) {
// if (value[2] == 0) return [value[1].toString(), "0"];
// return [value[1].toString(), value[2].toString()];
// } else if (value[3] == "after") {
// if (value[2] < 46 && value[2] > 0) {
// if (value[1] == 0.0) {
// return ["0", value[2].toString()];
// } else {
// return ["0", "0"];
// }
// } else {
// return ["0", "0"];
// }
// } else {
// return ["0", value[2].toString()];
// }
// }

class TodayCourseList extends StatefulWidget {
const TodayCourseList({Key? key}) : super(key: key);
Expand All @@ -115,9 +109,6 @@ class TomorrowCourseList extends StatefulWidget {
TomorrowCourseListState createState() => TomorrowCourseListState();
}

GlobalKey<TodayCourseListState> todayCourseListKey = GlobalKey();
GlobalKey<TomorrowCourseListState> tomorrowCourseListKey = GlobalKey();

class TodayCourseListState extends State<TodayCourseList> {
List _todaySchedule = todaySchedule;
late StreamSubscription<ReTodayListState> eventBusFn;
Expand All @@ -143,10 +134,38 @@ class TodayCourseListState extends State<TodayCourseList> {
super.dispose();
}

bool timerS = false;
int sum = 0;

timerRe(int index) {
print("timerRe");
if (!timerS && index == 0) {
timerS = !timerS;
Future.delayed(
const Duration(seconds: 1),
() {
if (DateTime.now().second < 2) {
sum++;
if (sum > (int.parse(writeData["threshold"]) * 2)) exit(0);
print("$index : ${DateTime.now().second}");
setState(() {
timerS = !timerS;
});
} else {
print("timerRe End ${DateTime.now().second}");
timerS = !timerS;
timerRe(0);
}
},
);
}
}

@override
Widget build(BuildContext context) {
return SliverList(
delegate: SliverChildBuilderDelegate((BuildContext context, int index) {
timerRe(index);
return TodayCourseListItem(index: index);
}, childCount: _todaySchedule.length),
);
Expand All @@ -163,23 +182,6 @@ class TodayCourseListItem extends StatefulWidget {
}

class TodayCourseListItemState extends State<TodayCourseListItem> {
bool timerS = false;

void timerRe(int index) {
if (!timerS) {
timerS = true;
Future.delayed(const Duration(seconds: 1), () {
List<String> list = _timeText2(index);
if (list[0] != "0" || list[1] != "0") {
print("$index : ${DateTime
.now()
.second}");
setState(() {});
}
});
}
}

IconData _icon(int index) {
String result = _getStartTime(int.parse(todaySchedule[index][3]))[3];
if (result == "before") {
Expand Down Expand Up @@ -239,10 +241,8 @@ class TodayCourseListItemState extends State<TodayCourseListItem> {

@override
Widget build(BuildContext context) {
timerRe(widget.index);
return Container(
margin: const EdgeInsets.fromLTRB(16, 16, 16, 16),
// height: 50,
child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
Row(
children: [
Expand Down Expand Up @@ -335,11 +335,14 @@ class TomorrowCourseListState extends State<TomorrowCourseList> {
return SliverList(
delegate: SliverChildBuilderDelegate((BuildContext context, int index) {
return Container(
margin: const EdgeInsets.fromLTRB(16, 0, 16, 16),
padding: _tomorrowSchedule[index][3] == "1" && index == 0
? const EdgeInsets.fromLTRB(16, 0, 16, 4)
: const EdgeInsets.fromLTRB(16, 0, 16, 0),
margin: const EdgeInsets.fromLTRB(0, 0, 0, 16),
height: 50,
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(6.0)),
),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(6.0)),
color: (_tomorrowSchedule[index][3] == "1" && index == 0 ? readColorBegin() : null)),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expand All @@ -351,7 +354,7 @@ class TomorrowCourseListState extends State<TomorrowCourseList> {
Icons.attachment,
color: (_tomorrowSchedule[index][3] == "1" && index == 0
? Colors.orange[900]
: Colors.blue),
: readColor()),
),
),
Column(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.211114+2
version: 1.1.211124+4

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down

0 comments on commit 3d20dd8

Please sign in to comment.