From c571dd48c61b66f660745907e540c7f127c666bf Mon Sep 17 00:00:00 2001 From: RainVisitor Date: Thu, 18 Jul 2019 19:58:17 +0800 Subject: [PATCH 1/6] Fix calculate unit text color in dark theme --- lib/pages/home/calculate_units_page.dart | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/pages/home/calculate_units_page.dart b/lib/pages/home/calculate_units_page.dart index 8a000d9e..7936b42e 100644 --- a/lib/pages/home/calculate_units_page.dart +++ b/lib/pages/home/calculate_units_page.dart @@ -66,11 +66,11 @@ class CalculateUnitsPageState extends State } _textBlueStyle() { - return TextStyle(color: Resource.Colors.blue, fontSize: 16.0); + return TextStyle(color: Resource.Colors.blueText, fontSize: 16.0); } _textStyle() { - return TextStyle(color: Colors.black, fontSize: 14.0); + return TextStyle(fontSize: 14.0); } _scoreTitle() => TableRow( @@ -148,7 +148,8 @@ class CalculateUnitsPageState extends State flex: 1, child: Text( app.calculateUnitsContent, - style: TextStyle(color: Resource.Colors.blue, fontSize: 16.0), + style: + TextStyle(color: Resource.Colors.blueText, fontSize: 16.0), ), ), Expanded( From 82982c87c5d49169cd64263db9375966b0cc6a95 Mon Sep 17 00:00:00 2001 From: RainVisitor Date: Sun, 21 Jul 2019 02:26:32 +0800 Subject: [PATCH 2/6] Code tune drawer widget --- lib/widgets/drawer_body.dart | 155 ++++++++++++++++++++++------------- 1 file changed, 97 insertions(+), 58 deletions(-) diff --git a/lib/widgets/drawer_body.dart b/lib/widgets/drawer_body.dart index 1bb45d11..b7e9a547 100644 --- a/lib/widgets/drawer_body.dart +++ b/lib/widgets/drawer_body.dart @@ -1,3 +1,4 @@ +import 'dart:io'; import 'dart:typed_data'; import 'package:dio/dio.dart'; @@ -11,34 +12,35 @@ import 'package:nkust_ap/res/assets.dart'; import 'package:nkust_ap/res/resource.dart' as Resource; import 'package:nkust_ap/utils/app_localizations.dart'; import 'package:nkust_ap/utils/cache_utils.dart'; +import 'package:nkust_ap/utils/preferences.dart'; import 'package:nkust_ap/utils/utils.dart'; -import 'package:shared_preferences/shared_preferences.dart'; Uint8List pictureBytes; class DrawerBody extends StatefulWidget { final UserInfo userInfo; - const DrawerBody({Key key, this.userInfo}) : super(key: key); + const DrawerBody({Key key, @required this.userInfo}) : super(key: key); @override DrawerBodyState createState() => DrawerBodyState(); } class DrawerBodyState extends State { - SharedPreferences prefs; - bool displayPicture = true; - AppLocalizations app; + bool displayPicture = true; bool isStudyExpanded = false; bool isBusExpanded = false; bool isLeaveExpanded = false; + TextStyle get _defaultStyle => + TextStyle(color: Resource.Colors.grey, fontSize: 16.0); + @override void initState() { - super.initState(); _getPreference(); + super.initState(); } @override @@ -46,8 +48,6 @@ class DrawerBodyState extends State { super.dispose(); } - _defaultStyle() => TextStyle(color: Resource.Colors.grey, fontSize: 16.0); - @override Widget build(BuildContext context) { app = AppLocalizations.of(context); @@ -70,7 +70,7 @@ class DrawerBodyState extends State { child: Stack( children: [ UserAccountsDrawerHeader( - margin: EdgeInsets.all(0), + margin: const EdgeInsets.all(0), currentAccountPicture: pictureBytes != null && displayPicture ? Hero( @@ -102,19 +102,15 @@ class DrawerBodyState extends State { ), ), accountName: Text( - widget.userInfo == null - ? "" - : "${widget.userInfo.studentNameCht}", + '${widget.userInfo?.studentNameCht}', style: TextStyle(color: Colors.white), ), accountEmail: Text( - widget.userInfo == null - ? "" - : "${widget.userInfo.studentId}", + '${widget.userInfo?.studentId}', style: TextStyle(color: Colors.white), ), decoration: BoxDecoration( - color: Color(0xff0071FF), + color: Resource.Colors.blue500, image: DecorationImage( image: AssetImage(ImageAssets.drawerBackground), fit: BoxFit.fitWidth, @@ -124,11 +120,9 @@ class DrawerBodyState extends State { Positioned( bottom: 20.0, right: 20.0, - child: Container( - child: Image.asset( - ImageAssets.drawerIcon, - width: 90.0, - ), + child: Image.asset( + ImageAssets.drawerIcon, + width: 90.0, ), ), ], @@ -146,12 +140,23 @@ class DrawerBodyState extends State { ? Resource.Colors.blueAccent : Resource.Colors.grey, ), - title: Text(app.courseInfo, style: _defaultStyle()), + title: Text(app.courseInfo, style: _defaultStyle), children: [ - _subItem(Icons.class_, app.course, CoursePageRoute()), - _subItem(Icons.assignment, app.score, ScorePageRoute()), _subItem( - Icons.apps, app.calculateUnits, CalculateUnitsPageRoute()), + icon: Icons.class_, + title: app.course, + route: CoursePageRoute(), + ), + _subItem( + icon: Icons.assignment, + title: app.score, + route: ScorePageRoute(), + ), + _subItem( + icon: Icons.apps, + title: app.calculateUnits, + route: CalculateUnitsPageRoute(), + ), ], ), ExpansionTile( @@ -166,12 +171,18 @@ class DrawerBodyState extends State { ? Resource.Colors.blueAccent : Resource.Colors.grey, ), - title: Text(app.leave, style: _defaultStyle()), + title: Text(app.leave, style: _defaultStyle), children: [ _subItem( - Icons.edit, app.leaveApply, LeavePageRoute(initIndex: 0)), - _subItem(Icons.assignment, app.leaveRecords, - LeavePageRoute(initIndex: 1)), + icon: Icons.edit, + title: app.leaveApply, + route: LeavePageRoute(initIndex: 0), + ), + _subItem( + icon: Icons.assignment, + title: app.leaveRecords, + route: LeavePageRoute(initIndex: 1), + ), ], ), ExpansionTile( @@ -186,17 +197,35 @@ class DrawerBodyState extends State { ? Resource.Colors.blueAccent : Resource.Colors.grey, ), - title: Text(app.bus, style: _defaultStyle()), + title: Text(app.bus, style: _defaultStyle), children: [ - _subItem(Icons.date_range, app.busReserve, - BusPageRoute(initIndex: 0)), - _subItem(Icons.assignment, app.busReservations, - BusPageRoute(initIndex: 1)), + _subItem( + icon: Icons.date_range, + title: app.busReserve, + route: BusPageRoute(initIndex: 0), + ), + _subItem( + icon: Icons.assignment, + title: app.busReservations, + route: BusPageRoute(initIndex: 1), + ), ], ), - _item(Icons.info, app.schoolInfo, SchoolInfoPageRoute()), - _item(Icons.face, app.about, AboutUsPageRoute()), - _item(Icons.settings, app.settings, SettingPageRoute()), + _item( + icon: Icons.info, + title: app.schoolInfo, + route: SchoolInfoPageRoute(), + ), + _item( + icon: Icons.face, + title: app.about, + route: AboutUsPageRoute(), + ), + _item( + icon: Icons.settings, + title: app.settings, + route: SettingPageRoute(), + ), ListTile( leading: Icon( Icons.power_settings_new, @@ -206,7 +235,7 @@ class DrawerBodyState extends State { Navigator.popUntil( context, ModalRoute.withName(Navigator.defaultRouteName)); }, - title: Text(app.logout, style: _defaultStyle()), + title: Text(app.logout, style: _defaultStyle), ), ], ), @@ -214,33 +243,43 @@ class DrawerBodyState extends State { ); } - _item(IconData icon, String title, MaterialPageRoute route) => ListTile( + _item({ + @required IconData icon, + @required String title, + @required MaterialPageRoute route, + }) => + ListTile( leading: Icon(icon, color: Resource.Colors.grey), - title: Text(title, style: _defaultStyle()), + title: Text(title, style: _defaultStyle), onTap: () { Navigator.pop(context); Navigator.push(context, route); }, ); - _subItem(IconData icon, String title, MaterialPageRoute route) => ListTile( + _subItem({ + @required IconData icon, + @required String title, + @required MaterialPageRoute route, + }) => + ListTile( contentPadding: EdgeInsets.symmetric(horizontal: 72.0), leading: Icon(icon, color: Resource.Colors.grey), - title: Text(title, style: _defaultStyle()), + title: Text(title, style: _defaultStyle), onTap: () async { - SharedPreferences prefs = await SharedPreferences.getInstance(); - if (route is BusPageRoute) { - bool bus = prefs.getBool(Constants.PREF_BUS_ENABLE) ?? true; - if (!bus) { - Utils.showToast(context, app.canNotUseFeature); - return; - } - } - if (route is LeavePageRoute) { - bool leave = prefs.getBool(Constants.PREF_LEAVE_ENABLE) ?? true; - if (!leave) { - Utils.showToast(context, app.canNotUseFeature); - return; + if (Platform.isAndroid || Platform.isIOS) { + if (route is BusPageRoute) { + bool bus = Preferences.getBool(Constants.PREF_BUS_ENABLE, true); + if (!bus) { + Utils.showToast(context, app.canNotUseFeature); + return; + } + } else if (route is LeavePageRoute) { + bool leave = Preferences.getBool(Constants.PREF_BUS_ENABLE, true); + if (!leave) { + Utils.showToast(context, app.canNotUseFeature); + return; + } } } Navigator.of(context).pop(); @@ -284,12 +323,12 @@ class DrawerBodyState extends State { } _getPreference() async { - prefs = await SharedPreferences.getInstance(); - if (!prefs.getBool(Constants.PREF_IS_OFFLINE_LOGIN)) { + if (!Preferences.getBool(Constants.PREF_IS_OFFLINE_LOGIN, false)) { _getUserPicture(); } setState(() { - displayPicture = prefs.getBool(Constants.PREF_DISPLAY_PICTURE) ?? true; + displayPicture = + Preferences.getBool(Constants.PREF_DISPLAY_PICTURE, true); }); } } From a5f8cd431a9680fd6aa13b979247b5af2680a846 Mon Sep 17 00:00:00 2001 From: RainVisitor Date: Sun, 21 Jul 2019 16:06:14 +0800 Subject: [PATCH 3/6] Add semester picker widget and code tune course page Upgrade: dart mini sdk to 2.2.2 --- lib/pages/home/course_page.dart | 170 +++++++------------------------ lib/widgets/semester_picker.dart | 154 ++++++++++++++++++++++++++++ pubspec.yaml | 2 +- 3 files changed, 194 insertions(+), 132 deletions(-) create mode 100644 lib/widgets/semester_picker.dart diff --git a/lib/pages/home/course_page.dart b/lib/pages/home/course_page.dart index 66614358..9202aeb7 100644 --- a/lib/pages/home/course_page.dart +++ b/lib/pages/home/course_page.dart @@ -4,9 +4,10 @@ import 'package:nkust_ap/models/models.dart'; import 'package:nkust_ap/res/resource.dart' as Resource; import 'package:nkust_ap/utils/cache_utils.dart'; import 'package:nkust_ap/utils/global.dart'; +import 'package:nkust_ap/utils/preferences.dart'; import 'package:nkust_ap/widgets/default_dialog.dart'; import 'package:nkust_ap/widgets/hint_content.dart'; -import 'package:shared_preferences/shared_preferences.dart'; +import 'package:nkust_ap/widgets/semester_picker.dart'; enum _State { loading, finish, error, empty, offlineEmpty } @@ -21,21 +22,21 @@ class CoursePageRoute extends MaterialPageRoute { } class CoursePage extends StatefulWidget { - static const String routerName = "/course"; + static const String routerName = '/course'; @override CoursePageState createState() => CoursePageState(); } -class CoursePageState extends State - with SingleTickerProviderStateMixin { +class CoursePageState extends State { + final key = GlobalKey(); + AppLocalizations app; ScaffoldState scaffold; _State state = _State.loading; int base = 6; - int selectSemesterIndex; double childAspectRatio = 0.5; Semester selectSemester; @@ -46,9 +47,8 @@ class CoursePageState extends State @override void initState() { + FA.setCurrentScreen('CoursePage', 'course_page.dart'); super.initState(); - FA.setCurrentScreen("CoursePage", "course_page.dart"); - _getSemester(); } @override @@ -73,23 +73,19 @@ class CoursePageState extends State mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ SizedBox(height: 8.0), - FlatButton( - onPressed: (semesterData != null) ? _selectSemester : null, - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - Text( - selectSemester == null ? "" : selectSemester.text, - style: TextStyle( - color: Resource.Colors.semesterText, fontSize: 18.0), - ), - SizedBox(width: 8.0), - Icon( - Icons.keyboard_arrow_down, - color: Resource.Colors.semesterText, - ) - ], - ), + SemesterPicker( + key: key, + onSelect: (semester, index) { + setState(() { + selectSemester = semester; + state = _State.loading; + }); + if (Preferences.getBool( + Constants.PREF_IS_OFFLINE_LOGIN, false)) + _loadCourseData(semester.value); + else + _getCourseTables(); + }, ), Text( '${isOffline ? app.offlineCourse + ' ' : ''}' @@ -127,13 +123,13 @@ class CoursePageState extends State if (state == _State.error) _getCourseTables(); else - _selectSemester(); + key.currentState.pickSemester(); FA.logAction('retry', 'click'); }, child: HintContent( - icon: Icons.class_, - content: - state == _State.error ? app.clickToRetry : app.courseEmpty), + icon: Icons.class_, + content: state == _State.error ? app.clickToRetry : app.courseEmpty, + ), ); case _State.offlineEmpty: return HintContent( @@ -171,15 +167,15 @@ class CoursePageState extends State List renderCourseList() { List weeks = [ - "Sunday", - "Monday", - "Tuesday", - "Wednesday", - "Thursday", - "Friday" + 'Sunday', + 'Monday', + 'Tuesday', + 'Wednesday', + 'Thursday', + 'Friday' ]; var list = [ - TableRow(children: [_titleBorder("")]) + TableRow(children: [_titleBorder('')]) ]; for (var week in app.weekdaysCourse.sublist(0, 4)) list[0].children.add(_titleBorder(week)); @@ -192,8 +188,8 @@ class CoursePageState extends State list[0].children.add(_titleBorder(app.weekdaysCourse[4])); list[0].children.add(_titleBorder(app.weekdaysCourse[5])); list[0].children.add(_titleBorder(app.weekdaysCourse[6])); - weeks.add("Saturday"); - weeks.add("Sunday"); + weeks.add('Saturday'); + weeks.add('Sunday'); base = 8; childAspectRatio = 1.1; } @@ -209,7 +205,7 @@ class CoursePageState extends State } list.add(TableRow(children: [])); list[i].children.add(_titleBorder(text)); - for (var j = 0; j < base - 1; j++) list[i].children.add(_titleBorder("")); + for (var j = 0; j < base - 1; j++) list[i].children.add(_titleBorder('')); } var timeCodes = courseData.courseTables.timeCode; for (int i = 0; i < weeks.length; i++) { @@ -231,7 +227,7 @@ class CoursePageState extends State alignment: Alignment.center, child: Text( text ?? '', - style: TextStyle(color: Resource.Colors.blueText, fontSize: 12.0), + style: TextStyle(color: Resource.Colors.blueText, fontSize: 14.0), ), ); } @@ -281,62 +277,13 @@ class CoursePageState extends State padding: EdgeInsets.symmetric(vertical: 8.0), alignment: Alignment.center, child: Text( - (course.title[0] + course.title[1]) ?? "", - style: TextStyle(fontSize: 14.0), + (course.title[0] + course.title[1]) ?? '', + style: TextStyle(fontSize: 16.0), ), ), ); } - void _getSemester() async { - _loadSemesterData(); - SharedPreferences prefs = await SharedPreferences.getInstance(); - if (prefs.getBool(Constants.PREF_IS_OFFLINE_LOGIN)) { - return; - } - Helper.instance.getSemester().then((semesterData) { - this.semesterData = semesterData; - CacheUtils.saveSemesterData(semesterData); - if (mounted) { - setState(() { - selectSemester = semesterData.defaultSemester; - selectSemesterIndex = semesterData.defaultIndex; - _getCourseTables(); - }); - } - }).catchError((e) { - if (e is DioError) { - switch (e.type) { - case DioErrorType.RESPONSE: - Utils.handleResponseError(context, 'getSemester', mounted, e); - break; - case DioErrorType.CANCEL: - break; - default: - state = _State.error; - if (mounted) Utils.handleDioError(context, e); - break; - } - } else { - throw e; - } - _loadCourseData(selectSemester.value); - }); - } - - void _loadSemesterData() async { - this.semesterData = await CacheUtils.loadSemesterData(); - if (this.semesterData == null) return; - setState(() { - selectSemester = semesterData.defaultSemester; - selectSemesterIndex = semesterData.defaultIndex; - }); - SharedPreferences prefs = await SharedPreferences.getInstance(); - if (prefs.getBool(Constants.PREF_IS_OFFLINE_LOGIN)) { - _loadCourseData(semesterData.defaultSemester.value); - } - } - void _loadCourseData(String value) async { courseData = await CacheUtils.loadCourseData(value); if (mounted) { @@ -355,49 +302,10 @@ class CoursePageState extends State } } - void _selectSemester() { - var semesters = []; - if (semesterData == null) return; - for (var semester in semesterData.semesters) { - semesters.add(_dialogItem(semesters.length, semester.text)); - } - FA.logAction('pick_yms', 'click'); - showDialog( - context: context, - builder: (BuildContext context) => SimpleDialog( - title: Text(app.picksSemester), - children: semesters)).then((int position) async { - if (position != null) { - setState(() { - selectSemesterIndex = position; - selectSemester = semesterData.semesters[selectSemesterIndex]; - state = _State.loading; - }); - SharedPreferences prefs = await SharedPreferences.getInstance(); - if (prefs.getBool(Constants.PREF_IS_OFFLINE_LOGIN)) - _loadCourseData(semesterData.semesters[selectSemesterIndex].value); - else - _getCourseTables(); - } - }); - } - - SimpleDialogOption _dialogItem(int index, String text) { - return SimpleDialogOption( - child: Text(text), - onPressed: () { - Navigator.pop(context, index); - }); - } - _getCourseTables() async { - Helper.cancelToken.cancel(""); + Helper.cancelToken.cancel(''); Helper.cancelToken = CancelToken(); - if (semesterData == null) { - _getSemester(); - return; - } - var textList = semesterData.semesters[selectSemesterIndex].value.split(","); + var textList = selectSemester.value.split(','); if (textList.length == 2) { Helper.instance .getCourseTables(textList[0], textList[1]) diff --git a/lib/widgets/semester_picker.dart b/lib/widgets/semester_picker.dart new file mode 100644 index 00000000..ed0273ac --- /dev/null +++ b/lib/widgets/semester_picker.dart @@ -0,0 +1,154 @@ +import 'package:dio/dio.dart'; +import 'package:flutter/material.dart'; +import 'package:nkust_ap/api/helper.dart'; +import 'package:nkust_ap/config/constants.dart'; +import 'package:nkust_ap/models/semester_data.dart'; +import 'package:nkust_ap/res/resource.dart' as Resource; +import 'package:nkust_ap/utils/app_localizations.dart'; +import 'package:nkust_ap/utils/cache_utils.dart'; +import 'package:nkust_ap/utils/firebase_analytics_utils.dart'; +import 'package:nkust_ap/utils/preferences.dart'; +import 'package:nkust_ap/utils/utils.dart'; + +typedef SemesterCallback = void Function(Semester semester, int index); + +class SemesterPicker extends StatefulWidget { + final SemesterCallback onSelect; + + const SemesterPicker({Key key, this.onSelect}) : super(key: key); + + @override + SemesterPickerState createState() => SemesterPickerState(); +} + +class SemesterPickerState extends State { + SemesterData semesterData; + Semester selectSemester; + + @override + void initState() { + _getSemester(); + super.initState(); + } + + @override + Widget build(BuildContext context) { + return FlatButton( + onPressed: () { + if (semesterData != null) pickSemester(); + FA.logAction('pick_yms', 'click'); + }, + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Text( + selectSemester?.text ?? '', + style: TextStyle( + color: Resource.Colors.semesterText, + fontSize: 18.0, + ), + ), + SizedBox(width: 8.0), + Icon( + Icons.keyboard_arrow_down, + color: Resource.Colors.semesterText, + ) + ], + ), + ); + } + + void _loadSemesterData() async { + this.semesterData = await CacheUtils.loadSemesterData(); + if (this.semesterData == null) return; + widget.onSelect(semesterData.defaultSemester, semesterData.defaultIndex); + setState(() { + selectSemester = semesterData.defaultSemester; + }); + } + + void _getSemester() async { + if (Preferences.getBool(Constants.PREF_IS_OFFLINE_LOGIN, false)) { + _loadSemesterData(); + return; + } + Helper.instance.getSemester().then((semesterData) { + this.semesterData = semesterData; + CacheUtils.saveSemesterData(semesterData); + if (mounted) { + widget.onSelect( + semesterData.defaultSemester, semesterData.defaultIndex); + setState(() { + selectSemester = semesterData.defaultSemester; + }); + } + }).catchError((e) { + if (e is DioError) { + switch (e.type) { + case DioErrorType.RESPONSE: + Utils.handleResponseError(context, 'getSemester', mounted, e); + break; + case DioErrorType.CANCEL: + break; + default: + if (mounted) Utils.handleDioError(context, e); + break; + } + } else { + throw e; + } + //widget.onSelect(semesterData.defaultSemester, semesterData.defaultIndex); + }); + } + + void pickSemester() { + showDialog( + context: context, + builder: (BuildContext context) => SimpleDialog( + title: Text(AppLocalizations.of(context).picksSemester), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all( + Radius.circular(8), + ), + ), + children: [ + for (var i = 0; i < semesterData.semesters.length; i++) ...[ + SimpleDialogOption( + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + semesterData.semesters[i].text, + style: TextStyle( + fontSize: 16.0, + color: (semesterData.semesters[i].text == + selectSemester.text) + ? Resource.Colors.blueAccent + : null), + ), + if (semesterData.semesters[i].text == selectSemester.text) + Icon( + Icons.check, + color: Resource.Colors.blueAccent, + ) + ], + ), + onPressed: () { + Navigator.pop(context, i); + }), + Divider( + height: 6.0, + ) + ] + ], + ), + ).then((int position) async { + if (position != null) { + widget.onSelect(semesterData.semesters[position], position); + setState(() { + selectSemester = semesterData.semesters[position]; + }); + } + }); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index 7d7dcfbe..2b1f6f53 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ description: A new Flutter application. version: 3.1.11+30111 environment: - sdk: ">=2.1.0 <3.0.0" + sdk: ">=2.2.2 <3.0.0" dependencies: flutter: From 0aa5b5c9473d9ce946c9632378a58b1835272d8e Mon Sep 17 00:00:00 2001 From: RainVisitor Date: Sun, 21 Jul 2019 16:30:06 +0800 Subject: [PATCH 4/6] Code tune score page Add semester picker in score page --- lib/pages/home/score_page.dart | 232 +++++++++---------------------- lib/widgets/semester_picker.dart | 1 + 2 files changed, 64 insertions(+), 169 deletions(-) diff --git a/lib/pages/home/score_page.dart b/lib/pages/home/score_page.dart index 23679ddf..028aeacb 100644 --- a/lib/pages/home/score_page.dart +++ b/lib/pages/home/score_page.dart @@ -4,8 +4,9 @@ import 'package:nkust_ap/models/models.dart'; import 'package:nkust_ap/res/resource.dart' as Resource; import 'package:nkust_ap/utils/cache_utils.dart'; import 'package:nkust_ap/utils/global.dart'; +import 'package:nkust_ap/utils/preferences.dart'; import 'package:nkust_ap/widgets/hint_content.dart'; -import 'package:shared_preferences/shared_preferences.dart'; +import 'package:nkust_ap/widgets/semester_picker.dart'; enum _State { loading, finish, error, empty, offlineEmpty } @@ -20,33 +21,34 @@ class ScorePageRoute extends MaterialPageRoute { } class ScorePage extends StatefulWidget { - static const String routerName = "/score"; + static const String routerName = '/score'; @override ScorePageState createState() => ScorePageState(); } -class ScorePageState extends State - with SingleTickerProviderStateMixin { +class ScorePageState extends State { + final key = GlobalKey(); + AppLocalizations app; _State state = _State.loading; - List scoreWeightList = []; - - int selectSemesterIndex; - Semester selectSemester; SemesterData semesterData; ScoreData scoreData; bool isOffline = false; + TextStyle get _textBlueStyle => + TextStyle(color: Resource.Colors.blueText, fontSize: 16.0); + + TextStyle get _textStyle => TextStyle(fontSize: 15.0); + @override void initState() { + FA.setCurrentScreen('ScorePage', 'score_page.dart'); super.initState(); - FA.setCurrentScreen("ScorePage", "score_page.dart"); - _getSemester(); } @override @@ -58,9 +60,7 @@ class ScorePageState extends State Widget build(BuildContext context) { app = AppLocalizations.of(context); return Scaffold( - // Appbar appBar: AppBar( - // Title title: Text(app.score), backgroundColor: Resource.Colors.blue, ), @@ -71,36 +71,28 @@ class ScorePageState extends State mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ SizedBox(height: 8.0), - FlatButton( - onPressed: (semesterData != null) ? _selectSemester : null, - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - Text( - selectSemester == null ? "" : selectSemester.text, - style: TextStyle( - color: Resource.Colors.semesterText, fontSize: 18.0), - ), - SizedBox(width: 8.0), - Icon( - Icons.keyboard_arrow_down, - color: Resource.Colors.semesterText, - ) - ], + SemesterPicker( + key: key, + onSelect: (semester, index) { + setState(() { + selectSemester = semester; + state = _State.loading; + }); + if (Preferences.getBool( + Constants.PREF_IS_OFFLINE_LOGIN, false)) + _loadOfflineScoreData(); + else + _getSemesterScore(); + }), + if (isOffline) + Text( + app.offlineScore, + style: TextStyle(color: Resource.Colors.grey), ), - ), - Container( - child: isOffline - ? Text( - app.offlineScore, - style: TextStyle(color: Resource.Colors.grey), - ) - : null, - ), Expanded( child: RefreshIndicator( onRefresh: () async { - _getSemesterScore(); + await _getSemesterScore(); FA.logAction('refresh', 'swipe'); return null; }, @@ -125,7 +117,7 @@ class ScorePageState extends State if (state == _State.error) _getSemesterScore(); else - _selectSemester(); + key.currentState.pickSemester(); FA.logAction('retry', 'click'); }, child: HintContent( @@ -168,7 +160,17 @@ class ScorePageState extends State width: 0.5, ), ), - children: scoreWeightList, + children: [ + TableRow( + children: [ + _scoreTextBorder(app.subject, true), + _scoreTextBorder(app.midtermScore, true), + _scoreTextBorder(app.finalScore, true), + ], + ), + for (var score in scoreData.content.scores) + _scoreTableRowTitle(score) + ], ), ), SizedBox(height: 20.0), @@ -184,16 +186,16 @@ class ScorePageState extends State child: Column( children: [ _textBorder( - "${app.conductScore}:${scoreData.content.detail.conduct}", + '${app.conductScore}:${scoreData.content.detail.conduct}', true), _textBorder( - "${app.average}:${scoreData.content.detail.average}", + '${app.average}:${scoreData.content.detail.average}', false), _textBorder( - "${app.rank}:${scoreData.content.detail.classRank}", + '${app.rank}:${scoreData.content.detail.classRank}', false), _textBorder( - "${app.percentage}:${scoreData.content.detail.classPercentage}", + '${app.percentage}:${scoreData.content.detail.classPercentage}', false), ], ), @@ -205,22 +207,6 @@ class ScorePageState extends State } } - _textBlueStyle() { - return TextStyle(color: Resource.Colors.blueText, fontSize: 16.0); - } - - _textStyle() { - return TextStyle(fontSize: 14.0); - } - - _scoreTitle() => TableRow( - children: [ - _scoreTextBorder(app.subject, true), - _scoreTextBorder(app.midtermScore, true), - _scoreTextBorder(app.finalScore, true), - ], - ); - Widget _textBorder(String text, bool isTop) { return Container( width: double.infinity, @@ -233,133 +219,45 @@ class ScorePageState extends State ), ), child: Text( - text ?? "", + text ?? '', textAlign: TextAlign.center, - style: _textBlueStyle(), + style: _textBlueStyle, ), ); } + TableRow _scoreTableRowTitle(Score score) { + return TableRow(children: [ + _scoreTextBorder(score.title, false), + _scoreTextBorder(score.middleScore, false), + _scoreTextBorder(score.finalScore, false) + ]); + } + Widget _scoreTextBorder(String text, bool isTitle) { return Container( width: double.maxFinite, padding: EdgeInsets.symmetric(vertical: 2.0, horizontal: 4.0), alignment: Alignment.center, child: Text( - text ?? "", + text ?? '', textAlign: TextAlign.center, - style: isTitle ? _textBlueStyle() : _textStyle(), + style: isTitle ? _textBlueStyle : _textStyle, ), ); } - TableRow _scoreTableRowTitle(Score score) { - return TableRow(children: [ - _scoreTextBorder(score.title, false), - _scoreTextBorder(score.middleScore, false), - _scoreTextBorder(score.finalScore, false) - ]); - } - - void _selectSemester() { - if (semesterData.semesters == null) return; - var semesters = []; - for (var semester in semesterData.semesters) { - semesters.add(_dialogItem(semesters.length, semester.text)); - } - FA.logAction('pick_yms', 'click'); - showDialog( - context: context, - builder: (BuildContext context) => SimpleDialog( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.all( - Radius.circular(8), - ), - ), - title: Text(app.picksSemester), - children: semesters)).then((int position) { - if (position != null) { - if (mounted) { - setState(() { - selectSemesterIndex = position; - selectSemester = semesterData.semesters[selectSemesterIndex]; - }); - _getSemesterScore(); - } - } - }); - } - - void _getSemester() async { - this.semesterData = await CacheUtils.loadSemesterData(); - if (this.semesterData == null) return; - setState(() { - selectSemester = semesterData.defaultSemester; - selectSemesterIndex = semesterData.defaultIndex; - }); - SharedPreferences prefs = await SharedPreferences.getInstance(); - if (prefs.getBool(Constants.PREF_IS_OFFLINE_LOGIN)) { - _getSemesterScore(); - return; - } - Helper.instance.getSemester().then((semesterData) { - if (mounted) { - setState(() { - this.semesterData = semesterData; - selectSemester = semesterData.defaultSemester; - selectSemesterIndex = semesterData.defaultIndex; - }); - _getSemesterScore(); - } - CacheUtils.saveSemesterData(semesterData); - }).catchError((e) { - if (e is DioError) { - switch (e.type) { - case DioErrorType.RESPONSE: - if (mounted) { - Utils.handleResponseError(context, 'getSemester', mounted, e); - } - break; - case DioErrorType.CANCEL: - break; - default: - state = _State.error; - if (mounted) { - Utils.handleDioError(context, e); - } - break; - } - } else { - throw e; - } - _loadOfflineScoreData(); - }); - } - - _renderScoreDataWidget() { - scoreWeightList.clear(); - scoreWeightList.add(_scoreTitle()); - for (var score in scoreData.content.scores) { - scoreWeightList.add(_scoreTableRowTitle(score)); - } - } - _getSemesterScore() async { - Helper.cancelToken?.cancel(""); + Helper.cancelToken?.cancel(''); Helper.cancelToken = CancelToken(); if (mounted) { setState(() { state = _State.loading; }); } - if (semesterData.semesters == null) { - _getSemester(); - return; - } - var textList = semesterData.semesters[selectSemesterIndex].value.split(","); + var textList = selectSemester.value.split(','); if (textList.length == 2) { - SharedPreferences prefs = await SharedPreferences.getInstance(); - if (prefs.getBool(Constants.PREF_IS_OFFLINE_LOGIN)) + if (Preferences.getBool(Constants.PREF_IS_OFFLINE_LOGIN, false)) _loadOfflineScoreData(); else Helper.instance.getScores(textList[0], textList[1]).then((response) { @@ -369,11 +267,9 @@ class ScorePageState extends State if (scoreData.status == 204) state = _State.empty; else { - _renderScoreDataWidget(); state = _State.finish; } - CacheUtils.saveScoreData( - semesterData.semesters[selectSemesterIndex].value, scoreData); + CacheUtils.saveScoreData(selectSemester.value, scoreData); }); }).catchError((e) { if (e is DioError) { @@ -415,8 +311,7 @@ class ScorePageState extends State } _loadOfflineScoreData() async { - scoreData = await CacheUtils.loadScoreData( - semesterData.semesters[selectSemesterIndex].value); + scoreData = await CacheUtils.loadScoreData(selectSemester.value); if (mounted) { setState(() { isOffline = true; @@ -425,7 +320,6 @@ class ScorePageState extends State else if (scoreData.status == 204) state = _State.empty; else { - _renderScoreDataWidget(); state = _State.finish; } }); diff --git a/lib/widgets/semester_picker.dart b/lib/widgets/semester_picker.dart index ed0273ac..0b078f6a 100644 --- a/lib/widgets/semester_picker.dart +++ b/lib/widgets/semester_picker.dart @@ -97,6 +97,7 @@ class SemesterPickerState extends State { } else { throw e; } + _loadSemesterData(); //widget.onSelect(semesterData.defaultSemester, semesterData.defaultIndex); }); } From 9423f92f735a341db77b1c5ae47a0b80a3bad86d Mon Sep 17 00:00:00 2001 From: RainVisitor Date: Mon, 22 Jul 2019 02:20:07 +0800 Subject: [PATCH 5/6] Code tone leave record page Add semester picker in leave record page --- lib/pages/home/leaves/leave_apply_page.dart | 3 +- lib/pages/home/leaves/leave_record_page.dart | 386 +++++++------------ lib/res/app_theme.dart | 2 + 3 files changed, 146 insertions(+), 245 deletions(-) diff --git a/lib/pages/home/leaves/leave_apply_page.dart b/lib/pages/home/leaves/leave_apply_page.dart index 3d318e14..e4b4f666 100644 --- a/lib/pages/home/leaves/leave_apply_page.dart +++ b/lib/pages/home/leaves/leave_apply_page.dart @@ -20,7 +20,7 @@ class LeaveApplyPageRoute extends MaterialPageRoute { } class LeaveApplyPage extends StatefulWidget { - static const String routerName = "/leaves/reservations"; + static const String routerName = "/leave/apply"; @override LeaveApplyPageState createState() => new LeaveApplyPageState(); @@ -53,6 +53,7 @@ class LeaveApplyPageState extends State @override Widget build(BuildContext context) { + super.build(context); app = AppLocalizations.of(context); return _body(); } diff --git a/lib/pages/home/leaves/leave_record_page.dart b/lib/pages/home/leaves/leave_record_page.dart index 059e3663..1bac80cb 100644 --- a/lib/pages/home/leaves/leave_record_page.dart +++ b/lib/pages/home/leaves/leave_record_page.dart @@ -5,9 +5,10 @@ import 'package:nkust_ap/models/models.dart'; import 'package:nkust_ap/res/resource.dart' as Resource; import 'package:nkust_ap/utils/cache_utils.dart'; import 'package:nkust_ap/utils/global.dart'; +import 'package:nkust_ap/utils/preferences.dart'; import 'package:nkust_ap/widgets/default_dialog.dart'; import 'package:nkust_ap/widgets/hint_content.dart'; -import 'package:shared_preferences/shared_preferences.dart'; +import 'package:nkust_ap/widgets/semester_picker.dart'; enum _State { loading, finish, error, empty, offlineEmpty } @@ -23,7 +24,7 @@ class LeaveRecordPageRoute extends MaterialPageRoute { } class LeaveRecordPage extends StatefulWidget { - static const String routerName = "/score"; + static const String routerName = '/leave/record'; @override LeaveRecordPageState createState() => LeaveRecordPageState(); @@ -34,31 +35,32 @@ class LeaveRecordPageState extends State @override bool get wantKeepAlive => true; + final key = GlobalKey(); + AppLocalizations app; _State state = _State.loading; - List leaveWeightList = []; - - int selectSemesterIndex; + Orientation orientation; Semester selectSemester; SemesterData semesterData; LeaveResponse leaveResponse; - bool hasNight = false; - - Orientation orientation; - double count = 1.0; + bool hasNight = false; bool isOffline = false; + TextStyle get _textBlueStyle => + TextStyle(color: Resource.Colors.blueText, fontSize: 16.0); + + TextStyle get _textStyle => TextStyle(fontSize: 15.0); + @override void initState() { + FA.setCurrentScreen('LeaveRecordPage', 'leave_record_page.dart'); super.initState(); - FA.setCurrentScreen("LeaveRecordPage", "leave_record_page.dart"); - _getSemester(); } @override @@ -66,93 +68,9 @@ class LeaveRecordPageState extends State super.dispose(); } - _textBlueStyle() { - return TextStyle(color: Resource.Colors.blueText, fontSize: 16.0); - } - - _textStyle() { - return TextStyle(fontSize: 14.0); - } - - _leaveTitle(List timeCodes) { - List widgets = []; - widgets.add(_textBorder(app.date, true)); - for (var timeCode in timeCodes) { - if (hasNight) { - if (orientation == Orientation.landscape) - widgets.add(_textBorder(timeCode, true)); - else if (timeCode.length < 2) widgets.add(_textBorder(timeCode, true)); - } else if (timeCode.length < 2) widgets.add(_textBorder(timeCode, true)); - } - count = widgets.length.toDouble(); - return TableRow(children: widgets); - } - - Widget _textBorder(String text, bool isTitle) { - return Container( - width: double.maxFinite, - padding: EdgeInsets.symmetric(vertical: 2.0, horizontal: 4.0), - alignment: Alignment.center, - child: Text( - text ?? "", - textAlign: TextAlign.center, - style: isTitle ? _textBlueStyle() : _textStyle(), - ), - ); - } - - _leaveBorder(Leaves leave, List timeCodes) { - List widgets = []; - widgets.add(InkWell( - child: _textBorder(leave.date.substring(4), false), - onTap: (leave.leaveSheetId.isEmpty && leave.instructorsComment.isEmpty) - ? null - : () { - showDialog( - context: context, - builder: (BuildContext context) => DefaultDialog( - title: app.leaveContent, - actionText: app.iKnow, - actionFunction: () => - Navigator.of(context, rootNavigator: true).pop('dialog'), - contentWidget: RichText( - text: TextSpan( - style: TextStyle( - color: Resource.Colors.grey, - height: 1.3, - fontSize: 16.0), - children: [ - TextSpan( - text: '${app.leaveSheetId}:', - style: TextStyle(fontWeight: FontWeight.bold)), - TextSpan(text: '${leave.leaveSheetId}\n'), - TextSpan( - text: '${app.instructorsComment}:' - '${leave.instructorsComment.length < 8 ? '' : '\n'}', - style: TextStyle(fontWeight: FontWeight.bold)), - TextSpan( - text: - '${leave.instructorsComment.replaceAll(':', ' ')}'), - ]), - ), - ), - ); - }, - )); - for (var timeCode in timeCodes) { - if (hasNight) { - if (orientation == Orientation.landscape) - widgets.add(_textBorder(leave.getReason(timeCode), false)); - else if (timeCode.length < 2) - widgets.add(_textBorder(leave.getReason(timeCode), false)); - } else if (timeCode.length < 2) - widgets.add(_textBorder(leave.getReason(timeCode), false)); - } - return TableRow(children: widgets); - } - @override Widget build(BuildContext context) { + super.build(context); app = AppLocalizations.of(context); return Container( child: Flex( @@ -161,37 +79,29 @@ class LeaveRecordPageState extends State mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ SizedBox(height: 8.0), - FlatButton( - onPressed: (semesterData != null) ? _selectSemester : null, - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - Text( - selectSemester == null ? "" : selectSemester.text, - style: TextStyle( - color: Resource.Colors.semesterText, fontSize: 18.0), - ), - SizedBox(width: 8.0), - Icon( - Icons.keyboard_arrow_down, - color: Resource.Colors.semesterText, - ) - ], - ), - ), - Container( - child: isOffline - ? Text( - app.offlineLeaveData, - style: TextStyle(color: Resource.Colors.grey), - ) - : null, + SemesterPicker( + key: key, + onSelect: (semester, index) { + setState(() { + selectSemester = semester; + state = _State.loading; + }); + if (Preferences.getBool(Constants.PREF_IS_OFFLINE_LOGIN, false)) + _loadOfflineLeaveData(); + else + _getSemesterLeaveRecord(); + }, ), + if (isOffline) + Text( + app.offlineLeaveData, + style: TextStyle(color: Resource.Colors.grey), + ), Expanded( child: RefreshIndicator( onRefresh: () async { if (isOffline) await Helper.instance.initByPreference(); - _getSemesterLeaveRecord(); + await _getSemesterLeaveRecord(); FA.logAction('refresh', 'swipe'); return null; }, @@ -207,10 +117,6 @@ class LeaveRecordPageState extends State Widget _body(Orientation orientation) { this.orientation = orientation; - if (state == _State.finish) { - hasNight = _checkHasNight(); - _renderLeavesWidget(); - } switch (state) { case _State.loading: return Container( @@ -218,8 +124,13 @@ class LeaveRecordPageState extends State case _State.error: case _State.empty: return FlatButton( - onPressed: - state == _State.error ? _getSemesterLeaveRecord : _selectSemester, + onPressed: () { + if (state == _State.error) + _getSemesterLeaveRecord(); + else + key.currentState.pickSemester(); + FA.logAction('retry', 'click'); + }, child: HintContent( icon: Icons.assignment, content: state == _State.error ? app.clickToRetry : app.leaveEmpty, @@ -231,16 +142,17 @@ class LeaveRecordPageState extends State content: app.noOfflineData, ); default: + hasNight = _checkHasNight(); + final leaveTitle = _leaveTitle(leaveResponse.timeCode); return SingleChildScrollView( physics: const AlwaysScrollableScrollPhysics(), - child: Container( + child: Padding( padding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 8), child: Column( mainAxisSize: MainAxisSize.max, children: [ - hasNight && orientation == Orientation.portrait - ? Text(app.leaveNight) - : Container(height: 0.0), + if (hasNight && orientation == Orientation.portrait) + Text(app.leaveNight), SizedBox(height: 16.0), Container( decoration: BoxDecoration( @@ -258,8 +170,13 @@ class LeaveRecordPageState extends State defaultColumnWidth: FractionColumnWidth(0.85 / count), defaultVerticalAlignment: TableCellVerticalAlignment.middle, border: TableBorder.symmetric( - inside: BorderSide(color: Colors.grey)), - children: leaveWeightList, + inside: BorderSide(color: Colors.grey), + ), + children: [ + leaveTitle, + for (var leave in leaveResponse.leaves) + _leaveBorder(leave, leaveResponse.timeCode) + ], ), ), ], @@ -269,79 +186,100 @@ class LeaveRecordPageState extends State } } - void _selectSemester() { - if (semesterData.semesters == null) return; - var semesters = []; - for (var semester in semesterData.semesters) { - semesters.add(_dialogItem(semesters.length, semester.text)); - } - showDialog( - context: context, - builder: (BuildContext context) => SimpleDialog( - title: Text(app.picksSemester), - children: semesters)).then((int position) { - if (position != null) { - setState(() { - selectSemesterIndex = position; - selectSemester = semesterData.semesters[selectSemesterIndex]; - }); - _getSemesterLeaveRecord(); + bool _checkHasNight() { + if (leaveResponse == null) return false; + if (leaveResponse.leaves == null) return false; + for (var leave in leaveResponse.leaves) { + if (leave.leaveSections == null) continue; + for (var section in leave.leaveSections) { + if (section.section.length > 1) return true; } - }); + } + return false; } - void _getSemester() { - _loadSemesterData(); - Helper.instance.getSemester().then((semesterData) { - if (mounted) { - setState(() { - this.semesterData = semesterData; - selectSemester = semesterData.defaultSemester; - selectSemesterIndex = semesterData.defaultIndex; - }); - } - CacheUtils.saveSemesterData(semesterData); - _getSemesterLeaveRecord(); - }).catchError((e) { - if (e is DioError) { - switch (e.type) { - case DioErrorType.RESPONSE: - Utils.handleResponseError(context, 'getSemester', mounted, e); - break; - case DioErrorType.CANCEL: - break; - default: - state = _State.error; - Utils.handleDioError(context, e); - break; - } - } else { - throw e; - } - _loadOfflineLeaveData(); - }); + TableRow _leaveTitle(List timeCodes) { + List widgets = []; + widgets.add(_textBorder(app.date, true)); + for (var timeCode in timeCodes) { + if (hasNight) { + if (orientation == Orientation.landscape) + widgets.add(_textBorder(timeCode, true)); + else if (timeCode.length < 2) widgets.add(_textBorder(timeCode, true)); + } else if (timeCode.length < 2) widgets.add(_textBorder(timeCode, true)); + } + count = widgets.length.toDouble(); + return TableRow(children: widgets); + } + + Widget _textBorder(String text, bool isTitle) { + return Container( + width: double.maxFinite, + padding: EdgeInsets.symmetric(vertical: 2.0, horizontal: 4.0), + alignment: Alignment.center, + child: Text( + text ?? '', + textAlign: TextAlign.center, + style: isTitle ? _textBlueStyle : _textStyle, + ), + ); + } + + TableRow _leaveBorder(Leaves leave, List timeCodes) { + List widgets = []; + widgets.add(InkWell( + child: _textBorder(leave.date.substring(4), false), + onTap: (leave.leaveSheetId.isEmpty && leave.instructorsComment.isEmpty) + ? null + : () { + showDialog( + context: context, + builder: (BuildContext context) => DefaultDialog( + title: app.leaveContent, + actionText: app.iKnow, + actionFunction: () => + Navigator.of(context, rootNavigator: true).pop('dialog'), + contentWidget: RichText( + text: TextSpan( + style: TextStyle( + color: Resource.Colors.grey, + height: 1.3, + fontSize: 16.0), + children: [ + TextSpan( + text: '${app.leaveSheetId}:', + style: TextStyle(fontWeight: FontWeight.bold)), + TextSpan(text: '${leave.leaveSheetId}\n'), + TextSpan( + text: '${app.instructorsComment}:' + '${leave.instructorsComment.length < 8 ? '' : '\n'}', + style: TextStyle(fontWeight: FontWeight.bold)), + TextSpan( + text: + '${leave.instructorsComment.replaceAll(':', ' ')}'), + ]), + ), + ), + ); + }, + )); + for (var timeCode in timeCodes) { + if (hasNight) { + if (orientation == Orientation.landscape) + widgets.add(_textBorder(leave.getReason(timeCode), false)); + else if (timeCode.length < 2) + widgets.add(_textBorder(leave.getReason(timeCode), false)); + } else if (timeCode.length < 2) + widgets.add(_textBorder(leave.getReason(timeCode), false)); + } + return TableRow(children: widgets); } _getSemesterLeaveRecord() async { - Helper.cancelToken.cancel(""); + Helper.cancelToken.cancel(''); Helper.cancelToken = CancelToken(); - leaveWeightList.clear(); - if (mounted) { - setState(() { - state = _State.loading; - }); - } - if (semesterData.semesters == null) { - _getSemester(); - return; - } - var textList = semesterData.semesters[selectSemesterIndex].value.split(","); + var textList = selectSemester.value.split(','); if (textList.length == 2) { - SharedPreferences prefs = await SharedPreferences.getInstance(); - if (prefs.getBool(Constants.PREF_IS_OFFLINE_LOGIN)) { - _loadOfflineLeaveData(); - return; - } Helper.instance.getLeaves(textList[0], textList[1]).then((response) { if (mounted) setState(() { @@ -352,8 +290,7 @@ class LeaveRecordPageState extends State state = _State.finish; } }); - CacheUtils.saveLeaveData( - semesterData.semesters[selectSemesterIndex].value, leaveResponse); + CacheUtils.saveLeaveData(selectSemester.value, leaveResponse); }).catchError((e) { if (e is DioError) { switch (e.type) { @@ -378,53 +315,14 @@ class LeaveRecordPageState extends State } }); } else { - state = _State.error; - setState(() {}); - } - } - - SimpleDialogOption _dialogItem(int index, String text) { - return SimpleDialogOption( - child: Text(text), - onPressed: () { - Navigator.pop(context, index); - }, - ); - } - - List _renderLeavesWidget() { - leaveWeightList.clear(); - leaveWeightList.add(_leaveTitle(leaveResponse.timeCode)); - for (var leave in leaveResponse.leaves) { - leaveWeightList.add(_leaveBorder(leave, leaveResponse.timeCode)); - } - return leaveWeightList; - } - - bool _checkHasNight() { - if (leaveResponse == null) return false; - if (leaveResponse.leaves == null) return false; - for (var leave in leaveResponse.leaves) { - if (leave.leaveSections == null) continue; - for (var section in leave.leaveSections) { - if (section.section.length > 1) return true; - } + setState(() { + state = _State.error; + }); } - return false; - } - - void _loadSemesterData() async { - this.semesterData = await CacheUtils.loadSemesterData(); - if (this.semesterData == null) return; - setState(() { - selectSemester = semesterData.defaultSemester; - selectSemesterIndex = semesterData.defaultIndex; - }); } void _loadOfflineLeaveData() async { - leaveResponse = await CacheUtils.loadLeaveData( - semesterData.semesters[selectSemesterIndex].value); + leaveResponse = await CacheUtils.loadLeaveData(selectSemester.value); if (mounted) { setState(() { isOffline = true; diff --git a/lib/res/app_theme.dart b/lib/res/app_theme.dart index d03c0bf4..0a792109 100644 --- a/lib/res/app_theme.dart +++ b/lib/res/app_theme.dart @@ -19,6 +19,7 @@ class AppTheme { } static ThemeData get light => ThemeData( + //platform: TargetPlatform.iOS, brightness: Brightness.light, appBarTheme: AppBarTheme( color: Resource.Colors.blue, @@ -35,6 +36,7 @@ class AppTheme { ); static ThemeData get dark => ThemeData( + //platform: TargetPlatform.iOS, brightness: Brightness.dark, scaffoldBackgroundColor: Resource.Colors.onyx, accentColor: Resource.Colors.blueAccent, From 0c3f8be6fe055e5b5df489ba51a3a5be788c3703 Mon Sep 17 00:00:00 2001 From: RainVisitor Date: Mon, 22 Jul 2019 02:21:18 +0800 Subject: [PATCH 6/6] Update to v3.1.12 --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 2b1f6f53..69cf39f9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: nkust_ap description: A new Flutter application. -version: 3.1.11+30111 +version: 3.1.12+30112 environment: sdk: ">=2.2.2 <3.0.0"