Skip to content

Commit

Permalink
Merge pull request #78 from NKUST-ITC/develop
Browse files Browse the repository at this point in the history
Update to v3.2.7
  • Loading branch information
abc873693 authored Sep 27, 2019
2 parents e569dd6 + a2b4000 commit 8089bee
Show file tree
Hide file tree
Showing 23 changed files with 1,431 additions and 363 deletions.
1 change: 1 addition & 0 deletions assets/leaves_campus_data.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/rainvisitor/development/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/rainvisitor/Documents/GitHub-NKUST-ITC/NKUST-AP-Flutter"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_TARGET=/Users/rainvisitor/Documents/GitHub-NKUST-ITC/NKUST-AP-Flutter/lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "FLUTTER_FRAMEWORK_DIR=/Users/rainvisitor/development/flutter/bin/cache/artifacts/engine/ios-release"
export "FLUTTER_FRAMEWORK_DIR=/Users/rainvisitor/development/flutter/bin/cache/artifacts/engine/ios"
export "FLUTTER_BUILD_NAME=3.2.6"
export "FLUTTER_BUILD_NUMBER=30206"
export "TRACK_WIDGET_CREATION=true"
6 changes: 6 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@
<true/>
<key>NSCalendarsUsageDescription</key>
<string>Feature calendar would be add schedule to calendar app</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Feature leaves apply would be select photos to apply leaves</string>
<key>NSCameraUsageDescription</key>
<string>Feature leaves apply would be select photos to apply leaves</string>
<key>NSMicrophoneUsageDescription</key>
<string>Feature leaves apply would be select photos to apply leaves</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand Down
28 changes: 23 additions & 5 deletions lib/api/helper.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:dio/dio.dart';
import 'package:encrypt/encrypt.dart';
Expand All @@ -9,7 +10,7 @@ import 'package:nkust_ap/models/announcements_data.dart';
import 'package:nkust_ap/models/booking_bus_data.dart';
import 'package:nkust_ap/models/bus_violation_records_data.dart';
import 'package:nkust_ap/models/cancel_bus_data.dart';
import 'package:nkust_ap/models/leave_info_data.dart';
import 'package:nkust_ap/models/leave_submit_info_data.dart';
import 'package:nkust_ap/models/leaves_data.dart';
import 'package:nkust_ap/models/leaves_submit_data.dart';
import 'package:nkust_ap/models/library_info_data.dart';
Expand Down Expand Up @@ -38,7 +39,10 @@ class Helper {
static DateTime expireTime;

bool isExpire() {
return DateTime.now().isAfter(expireTime.add(Duration(hours: 8)));
if (expireTime == null)
return false;
else
return DateTime.now().isAfter(expireTime.add(Duration(hours: 8)));
}

static Helper get instance {
Expand Down Expand Up @@ -155,7 +159,10 @@ class Helper {
Future<AnnouncementsData> getAllAnnouncements() async {
try {
var response = await dio.get("/news/announcements/all");
return AnnouncementsData.fromJson(response.data);
if (response.statusCode == 204)
return AnnouncementsData(data: []);
else
return AnnouncementsData.fromJson(response.data);
} on DioError catch (dioError) {
print(dioError);
throw dioError;
Expand Down Expand Up @@ -425,12 +432,17 @@ class Helper {
}
}

Future<Response> sendLeavesSubmit(LeavesSubmitData data) async {
Future<Response> sendLeavesSubmit(LeavesSubmitData data, File image) async {
if (isExpire()) await login(username, password);
try {
var response = await dio.post(
'/leaves/submit',
data: data.toJson(),
data: {
'leavesData': data.toJson(),
'leavesProof': image == null
? null
: UploadFileInfo(image, image.path.split('/').last),
},
cancelToken: cancelToken,
);
return response;
Expand Down Expand Up @@ -471,4 +483,10 @@ class Helper {
'Authorization': 'Bearer $token',
};
}

static void clearSetting() {
expireTime = null;
username = null;
password = null;
}
}
38 changes: 33 additions & 5 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';
import 'dart:io';
import 'dart:typed_data';

import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:firebase_analytics/observer.dart';
Expand All @@ -20,8 +21,10 @@ import 'package:nkust_ap/utils/app_localizations.dart';
import 'package:nkust_ap/utils/firebase_analytics_utils.dart';
import 'package:nkust_ap/utils/preferences.dart';
import 'package:nkust_ap/utils/utils.dart';
import 'package:nkust_ap/widgets/drawer_body.dart';
import 'package:nkust_ap/widgets/share_data_widget.dart';

import 'api/helper.dart';
import 'models/login_response.dart';
import 'models/user_info.dart';

Expand All @@ -32,15 +35,13 @@ void main() async {
Preferences.getString(Constants.PREF_ICON_STYLE_CODE, AppIcon.OUTLINED);
AppTheme.code =
Preferences.getString(Constants.PREF_THEME_CODE, AppTheme.LIGHT);
if (kIsWeb || Constants.isInDebugMode) {
if (kIsWeb) {
} else if (Platform.isIOS || Platform.isAndroid) {
Crashlytics.instance.enableInDevMode = true;
// Pass all uncaught errors from the framework to Crashlytics.
FlutterError.onError = Crashlytics.instance.recordFlutterError;
} else {
// See https://github.com/flutter/flutter/wiki/Desktop-shells#target-platform-override
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
//TODO add other platform Crashlytics
_setTargetPlatformForDesktop();
}
runApp(
MyApp(
Expand All @@ -49,6 +50,18 @@ void main() async {
);
}

void _setTargetPlatformForDesktop() {
TargetPlatform targetPlatform;
if (Platform.isMacOS) {
targetPlatform = TargetPlatform.iOS;
} else if (Platform.isLinux || Platform.isWindows) {
targetPlatform = TargetPlatform.android;
}
if (targetPlatform != null) {
debugDefaultTargetPlatformOverride = targetPlatform;
}
}

class MyApp extends StatefulWidget {
final ThemeData themeData;

Expand All @@ -64,6 +77,7 @@ class MyAppState extends State<MyApp> {
ThemeData themeData;
UserInfo userInfo;
LoginResponse loginResponse;
Uint8List pictureBytes;
bool isLogin = false, offlineLogin = false;

setThemeData(ThemeData themeData) {
Expand All @@ -72,6 +86,17 @@ class MyAppState extends State<MyApp> {
});
}

logout() {
setState(() {
this.isLogin = false;
this.offlineLogin = false;
this.userInfo = null;
this.loginResponse = null;
this.pictureBytes = null;
Helper.clearSetting();
});
}

@override
void initState() {
themeData = widget.themeData;
Expand All @@ -81,13 +106,16 @@ class MyAppState extends State<MyApp> {
firebaseMessaging = FirebaseMessaging();
_initFCM();
FA.analytics = analytics;
FA.setUserProperty('theme', AppTheme.code);
FA.setUserProperty('icon_style', AppIcon.code);
Preferences.init();
}
super.initState();
}

@override
Widget build(BuildContext context) {
print(AppLocalizations.languageCode);
return ShareDataWidget(
this,
child: MaterialApp(
Expand All @@ -98,7 +126,7 @@ class MyAppState extends State<MyApp> {
onGenerateTitle: (context) => AppLocalizations.of(context).appName,
debugShowCheckedModeBanner: false,
routes: <String, WidgetBuilder>{
Navigator.defaultRouteName: (context) => LoginPage(),
Navigator.defaultRouteName: (context) => HomePage(),
LoginPage.routerName: (BuildContext context) => LoginPage(),
HomePage.routerName: (BuildContext context) => HomePage(),
CoursePage.routerName: (BuildContext context) => CoursePage(),
Expand Down
111 changes: 0 additions & 111 deletions lib/models/leave_info_data.dart

This file was deleted.

81 changes: 81 additions & 0 deletions lib/models/leave_submit_info_data.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// To parse this JSON data, do
//
// final leavesSubmitInfoData = leavesSubmitInfoDataFromJson(jsonString);

import 'dart:convert';

class LeavesSubmitInfoData {
Tutor tutor;
List<Type> type;
List<String> timeCodes;

LeavesSubmitInfoData({
this.tutor,
this.type,
this.timeCodes,
});

factory LeavesSubmitInfoData.fromRawJson(String str) => LeavesSubmitInfoData.fromJson(json.decode(str));

String toRawJson() => json.encode(toJson());

factory LeavesSubmitInfoData.fromJson(Map<String, dynamic> json) => LeavesSubmitInfoData(
tutor: json["tutor"] == null ? null : Tutor.fromJson(json["tutor"]),
type: json["type"] == null ? null : List<Type>.from(json["type"].map((x) => Type.fromJson(x))),
timeCodes: json["timeCodes"] == null ? null : List<String>.from(json["timeCodes"].map((x) => x)),
);

Map<String, dynamic> toJson() => {
"tutor": tutor == null ? null : tutor.toJson(),
"type": type == null ? null : List<dynamic>.from(type.map((x) => x.toJson())),
"timeCodes": timeCodes == null ? null : List<dynamic>.from(timeCodes.map((x) => x)),
};
}

class Tutor {
String name;
String id;

Tutor({
this.name,
this.id,
});

factory Tutor.fromRawJson(String str) => Tutor.fromJson(json.decode(str));

String toRawJson() => json.encode(toJson());

factory Tutor.fromJson(Map<String, dynamic> json) => Tutor(
name: json["name"] == null ? null : json["name"],
id: json["id"] == null ? null : json["id"],
);

Map<String, dynamic> toJson() => {
"name": name == null ? null : name,
"id": id == null ? null : id,
};
}

class Type {
String title;
String id;

Type({
this.title,
this.id,
});

factory Type.fromRawJson(String str) => Type.fromJson(json.decode(str));

String toRawJson() => json.encode(toJson());

factory Type.fromJson(Map<String, dynamic> json) => Type(
title: json["title"] == null ? null : json["title"],
id: json["id"] == null ? null : json["id"],
);

Map<String, dynamic> toJson() => {
"title": title == null ? null : title,
"id": id == null ? null : id,
};
}
Loading

0 comments on commit 8089bee

Please sign in to comment.