Skip to content

Commit

Permalink
Merge pull request #83 from NKUST-ITC/develop
Browse files Browse the repository at this point in the history
Update to v3.2.11
  • Loading branch information
abc873693 authored Oct 22, 2019
2 parents 8ee4332 + 4dc26c3 commit 9bdf3ae
Show file tree
Hide file tree
Showing 15 changed files with 1,124 additions and 217 deletions.
9 changes: 4 additions & 5 deletions ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
# 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=/Users/rainvisitor/Documents/GitHub-NKUST-ITC/NKUST-AP-Flutter/lib/main.dart"
export "FLUTTER_TARGET=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"
export "FLUTTER_BUILD_NAME=3.2.9"
export "FLUTTER_BUILD_NUMBER=30209"
export "TRACK_WIDGET_CREATION=true"
export "FLUTTER_FRAMEWORK_DIR=/Users/rainvisitor/development/flutter/bin/cache/artifacts/engine/ios-release"
export "FLUTTER_BUILD_NAME=3.2.11"
export "FLUTTER_BUILD_NUMBER=30211"
59 changes: 58 additions & 1 deletion lib/api/helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import 'package:nkust_ap/utils/preferences.dart';
import 'package:nkust_ap/utils/utils.dart';

class Helper {
static const HOST = 'nkus-ap-staging.rainvisitor.me';
static const HOST = 'nkust-ap-staging.rainvisitor.me';

static const VERSION = 'v3';

Expand Down Expand Up @@ -113,6 +113,27 @@ class Helper {
}
}

Future<LoginResponse> adminLogin(String username, String password) async {
try {
var response = await dio.post(
'/oauth/admin/token',
data: {
'username': username,
'password': password,
},
);
if (response == null) print('null');
var loginResponse = LoginResponse.fromJson(response.data);
options.headers = _createBearerTokenAuth(loginResponse.token);
expireTime = loginResponse.expireTime;
Helper.username = username;
Helper.password = password;
return loginResponse;
} catch (dioError) {
throw dioError;
}
}

Future<Response> deleteToken() async {
try {
var response = await dio.delete(
Expand Down Expand Up @@ -162,6 +183,42 @@ class Helper {
}
}

Future<Response> addAnnouncement(Announcements announcements) async {
try {
var response = await dio.post(
"/news/announcements/add",
data: announcements.toUpdateJson(),
);
return response;
} on DioError catch (dioError) {
throw dioError;
}
}

Future<Response> updateAnnouncement(Announcements announcements) async {
try {
var response = await dio.put(
"/news/announcements/update/${announcements.id}",
data: announcements.toUpdateJson(),
);
return response;
} on DioError catch (dioError) {
throw dioError;
}
}

Future<Response> deleteAnnouncement(Announcements announcements) async {
try {
var response = await dio.delete(
"/news/announcements/remove/${announcements.id}",
data: announcements.toUpdateJson(),
);
return response;
} on DioError catch (dioError) {
throw dioError;
}
}

Future<UserInfo> getUsersInfo() async {
if (isExpire()) await login(username, password);
try {
Expand Down
176 changes: 176 additions & 0 deletions lib/app.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
import 'dart:async';
import 'dart:io';
import 'dart:typed_data';

import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:firebase_analytics/observer.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart'
show debugDefaultTargetPlatformOverride;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:nkust_ap/config/constants.dart';
import 'package:nkust_ap/pages/home/bus/bus_rule_page.dart';
import 'package:nkust_ap/pages/home/news/news_admin_page.dart';
import 'package:nkust_ap/pages/page.dart';
import 'package:nkust_ap/res/app_icon.dart';
import 'package:nkust_ap/res/app_theme.dart';
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';

class MyApp extends StatefulWidget {
final ThemeData themeData;

const MyApp({Key key, @required this.themeData}) : super(key: key);

@override
MyAppState createState() => MyAppState();
}

class MyAppState extends State<MyApp> {
FirebaseAnalytics analytics;
FirebaseMessaging firebaseMessaging;
ThemeData themeData;
UserInfo userInfo;
LoginResponse loginResponse;
Uint8List pictureBytes;
bool isLogin = false, offlineLogin = false;

setThemeData(ThemeData themeData) {
setState(() {
this.themeData = themeData;
});
}

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;
if (kIsWeb) {
} else if (Platform.isAndroid || Platform.isIOS) {
analytics = FirebaseAnalytics();
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(
data: this,
child: MaterialApp(
localeResolutionCallback:
(Locale locale, Iterable<Locale> supportedLocales) {
return locale;
},
onGenerateTitle: (context) => AppLocalizations.of(context).appName,
debugShowCheckedModeBanner: false,
routes: <String, WidgetBuilder>{
Navigator.defaultRouteName: (context) => HomePage(),
LoginPage.routerName: (BuildContext context) => LoginPage(),
HomePage.routerName: (BuildContext context) => HomePage(),
CoursePage.routerName: (BuildContext context) => CoursePage(),
BusPage.routerName: (BuildContext context) => BusPage(),
BusRulePage.routerName: (BuildContext context) => BusRulePage(),
ScorePage.routerName: (BuildContext context) => ScorePage(),
SchoolInfoPage.routerName: (BuildContext context) => SchoolInfoPage(),
SettingPage.routerName: (BuildContext context) => SettingPage(),
AboutUsPage.routerName: (BuildContext context) => AboutUsPage(),
OpenSourcePage.routerName: (BuildContext context) => OpenSourcePage(),
UserInfoPage.routerName: (BuildContext context) => UserInfoPage(),
NewsAdminPage.routerName: (BuildContext context) => NewsAdminPage(),
CalculateUnitsPage.routerName: (BuildContext context) =>
CalculateUnitsPage(),
NewsContentPage.routerName: (BuildContext context) =>
NewsContentPage(null),
LeavePage.routerName: (BuildContext context) => LeavePage(),
},
theme: themeData,
navigatorObservers: (kIsWeb)
? []
: (Platform.isIOS || Platform.isAndroid)
? [
FirebaseAnalyticsObserver(analytics: analytics),
]
: [],
localizationsDelegates: [
const AppLocalizationsDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [
const Locale('en', 'US'), // English
const Locale('zh', 'TW'), // Chinese
],
),
);
}

void _initFCM() {
firebaseMessaging.requestNotificationPermissions();
firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
if (Constants.isInDebugMode) print("onMessage: $message");
Utils.showFCMNotification(
message['notification']['title'] ?? '',
message['notification']['title'] ?? '',
message['notification']['body'] ?? '');
},
onLaunch: (Map<String, dynamic> message) async {
if (Constants.isInDebugMode) print("onLaunch: $message");
//_navigateToItemDetail(message);
},
onResume: (Map<String, dynamic> message) async {
if (Constants.isInDebugMode) print("onResume: $message");
},
);
firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(
sound: true,
badge: true,
alert: true,
),
);
firebaseMessaging.onIosSettingsRegistered
.listen((IosNotificationSettings settings) {
print("Settings registered: $settings");
});
firebaseMessaging.getToken().then((String token) {
if (token == null) return;
if (Constants.isInDebugMode) {
print("Push Messaging token: $token");
}
if (Platform.isAndroid)
firebaseMessaging.subscribeToTopic("Android");
else if (Platform.isIOS) firebaseMessaging.subscribeToTopic("IOS");
});
}
}
Loading

0 comments on commit 9bdf3ae

Please sign in to comment.