Merge branch 'master' of https://git.mokkon.com/sainw/fcs
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:fcs/fcs/common/services/messaging_service.dart';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
@@ -29,7 +31,7 @@ class MessagingFCM {
|
||||
log.info("onMessage: $message");
|
||||
if (onMessage != null) _onNotify(message, onMessage);
|
||||
},
|
||||
onBackgroundMessage: backgroundMessageHandler,
|
||||
onBackgroundMessage: Platform.isIOS ? null : backgroundMessageHandler,
|
||||
onLaunch: (Map<String, dynamic> message) async {
|
||||
log.info("onLaunch: $message");
|
||||
if (onLaunch != null) _onNotify(message, onLaunch);
|
||||
@@ -39,9 +41,8 @@ class MessagingFCM {
|
||||
if (onResume != null) _onNotify(message, onResume);
|
||||
},
|
||||
);
|
||||
_firebaseMessaging.requestNotificationPermissions(
|
||||
const IosNotificationSettings(
|
||||
sound: true, badge: true, alert: true, provisional: true));
|
||||
_firebaseMessaging
|
||||
.requestNotificationPermissions(const IosNotificationSettings());
|
||||
_firebaseMessaging.onIosSettingsRegistered
|
||||
.listen((IosNotificationSettings settings) {
|
||||
log.info("Settings registered: $settings");
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:logging/logging.dart';
|
||||
import 'package:fcs/vo/status.dart';
|
||||
|
||||
import '../../../config.dart';
|
||||
import 'dev_info.dart';
|
||||
|
||||
final log = Logger('requestAPI');
|
||||
|
||||
@@ -19,18 +20,16 @@ Future<dynamic> requestAPI(
|
||||
String token,
|
||||
String url,
|
||||
}) async {
|
||||
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
||||
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
|
||||
String deviceName = "${androidInfo.model}(${androidInfo.id})";
|
||||
log.info("device:${androidInfo.androidId},deviceName:$deviceName");
|
||||
DevInfo devInfo = await DevInfo.getDevInfo();
|
||||
|
||||
String deviceName = "${devInfo.model}(${devInfo.id})";
|
||||
log.info("device:${devInfo.deviceID},deviceName:$deviceName");
|
||||
|
||||
Map<String, dynamic> headers = {};
|
||||
if (token != null) {
|
||||
headers["Token"] = token;
|
||||
}
|
||||
if (androidInfo.androidId != null) {
|
||||
headers["Device"] = androidInfo.androidId + ":" + deviceName;
|
||||
}
|
||||
headers["Device"] = devInfo.deviceID + ":" + deviceName;
|
||||
headers["Project-ID"] = Config.instance.reportProjectID;
|
||||
|
||||
BaseOptions options = new BaseOptions(
|
||||
|
||||
32
lib/fcs/common/helpers/dev_info.dart
Normal file
32
lib/fcs/common/helpers/dev_info.dart
Normal file
@@ -0,0 +1,32 @@
|
||||
import 'package:device_info/device_info.dart';
|
||||
import 'dart:io' show Platform;
|
||||
|
||||
class DevInfo {
|
||||
bool isAndroid;
|
||||
bool isIOS;
|
||||
String deviceID;
|
||||
String id;
|
||||
String model;
|
||||
|
||||
static DevInfo _instance;
|
||||
|
||||
static Future<DevInfo> getDevInfo() async {
|
||||
if (_instance != null) return Future.value(_instance);
|
||||
|
||||
_instance = DevInfo();
|
||||
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
||||
|
||||
if (Platform.isAndroid) {
|
||||
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
|
||||
_instance.deviceID = androidInfo.androidId;
|
||||
_instance.id = androidInfo.id;
|
||||
_instance.model = androidInfo.model;
|
||||
} else if (Platform.isIOS) {
|
||||
IosDeviceInfo iosDeviceInfo = await deviceInfo.iosInfo;
|
||||
_instance.deviceID = iosDeviceInfo.identifierForVendor;
|
||||
_instance.id = iosDeviceInfo.utsname.release;
|
||||
_instance.model = iosDeviceInfo.model;
|
||||
}
|
||||
return Future.value(_instance);
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import 'package:fcs/pages_fcs/package_list.dart';
|
||||
import 'package:fcs/widget/banner.dart';
|
||||
import 'package:fcs/widget/bottom_up_page_route.dart';
|
||||
import 'package:fcs/widget/offline_redirect.dart';
|
||||
import 'package:fcs/widget/right_left_page_route%20copy.dart';
|
||||
import 'package:fcs/widget/right_left_page_rout.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_icons/flutter_icons.dart';
|
||||
|
||||
@@ -114,8 +114,8 @@ class MainModel extends ChangeNotifier {
|
||||
Future<void> _loadSetting() async {
|
||||
try {
|
||||
Services.instance.authService.getSetting().listen((event) {
|
||||
this.setting = event;
|
||||
notifyListeners();
|
||||
this.setting = event;
|
||||
notifyListeners();
|
||||
});
|
||||
} finally {}
|
||||
// _initSetting(setting);
|
||||
@@ -141,6 +141,7 @@ class MainModel extends ChangeNotifier {
|
||||
}
|
||||
|
||||
bool isSupport() {
|
||||
return true;
|
||||
if (packageInfo == null || setting == null) return false;
|
||||
return int.parse(packageInfo.buildNumber) >= setting.supportBuildNum;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import 'dart:async';
|
||||
|
||||
import 'package:fcs/fcs/common/pages/model/main_model.dart';
|
||||
import 'package:fcs/fcs/common/helpers/theme.dart';
|
||||
import 'package:fcs/widget/local_text.dart';
|
||||
import 'package:fcs/fcs/common/pages/widgets/local_text.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
@@ -579,7 +579,6 @@ Widget fcsButton(BuildContext context, String text, {Function callack}) {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
String getLocalString(BuildContext context,String key){
|
||||
String getLocalString(BuildContext context, String key) {
|
||||
return AppTranslations.of(context).text(key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,9 @@ final FirebaseAuth auth = FirebaseAuth.instance;
|
||||
|
||||
Future<String> getToken() async {
|
||||
FirebaseUser firebaseUser = await auth.currentUser();
|
||||
IdTokenResult token = await firebaseUser.getIdToken();
|
||||
return token.token;
|
||||
// IdTokenResult token = await firebaseUser.getIdToken();
|
||||
// return token.token;
|
||||
return "";
|
||||
}
|
||||
|
||||
Stream<QuerySnapshot> getQuerySnapshot(String path) {
|
||||
|
||||
@@ -322,32 +322,33 @@ class MainModel extends ChangeNotifier {
|
||||
var token = result["Token"];
|
||||
|
||||
// login with custom token
|
||||
AuthResult r = await this.auth.signInWithCustomToken(token: token);
|
||||
this.firebaseUser = r.user;
|
||||
// AuthResult r = await this.auth.signInWithCustomToken(token: token);
|
||||
// this.firebaseUser = r.user;
|
||||
isLoaded = false;
|
||||
_loadUser();
|
||||
_logUser(this.firebaseUser);
|
||||
}
|
||||
|
||||
Future<FirebaseUser> getProfile(FirebaseUser firebaseUser) async {
|
||||
IdTokenResult idtoken = await firebaseUser.getIdToken();
|
||||
// IdTokenResult idtoken = await firebaseUser.getIdToken();
|
||||
var data = await requestAPI(
|
||||
"/profile",
|
||||
"GET",
|
||||
token: idtoken.token,
|
||||
token: "", //idtoken.token,
|
||||
);
|
||||
var _token = data["Token"];
|
||||
AuthResult a = await this.auth.signInWithCustomToken(token: _token);
|
||||
return a.user;
|
||||
// AuthResult a = await this.auth.signInWithCustomToken(token: _token);
|
||||
// return a.user;
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<void> _logUser(FirebaseUser firebaseUser) async {
|
||||
IdTokenResult idtoken = await firebaseUser.getIdToken();
|
||||
// IdTokenResult idtoken = await firebaseUser.getIdToken();
|
||||
|
||||
await requestAPI(
|
||||
"/log",
|
||||
"GET",
|
||||
token: idtoken.token,
|
||||
token: "", //idtoken.token,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,13 +67,13 @@ class User {
|
||||
}
|
||||
|
||||
Future<void> setFirebaseUser(FirebaseUser firebaseUser) async {
|
||||
IdTokenResult idToken = await firebaseUser.getIdToken(refresh: true);
|
||||
String privileges = idToken.claims["privileges"];
|
||||
if (privileges == null || privileges == "") return;
|
||||
this.claimPrivileges = privileges.split(":").toList();
|
||||
// IdTokenResult idToken = await firebaseUser.getIdToken(refresh: true);
|
||||
// String privileges = idToken.claims["privileges"];
|
||||
// if (privileges == null || privileges == "") return;
|
||||
// this.claimPrivileges = privileges.split(":").toList();
|
||||
|
||||
this.accountID = idToken.claims["account_id"];
|
||||
this.bizID = idToken.claims["biz_id"];
|
||||
// this.accountID = idToken.claims["account_id"];
|
||||
// this.bizID = idToken.claims["biz_id"];
|
||||
}
|
||||
|
||||
User(
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import 'package:fcs/fcs/common/localization/app_translations.dart';
|
||||
import 'package:fcs/fcs/common/pages/model/language_model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:fcs/model/language_model.dart';
|
||||
import 'package:fcs/fcs/common/helpers/theme.dart';
|
||||
|
||||
import 'localization/app_translations.dart';
|
||||
|
||||
class LocalText extends Text {
|
||||
final BuildContext context;
|
||||
LocalText(this.context, String translationKey,
|
||||
|
||||
@@ -27,7 +27,7 @@ class _OfflineRedirectState extends State<OfflineRedirect> {
|
||||
}
|
||||
|
||||
_startOfflineTimer() async {
|
||||
if (offlineTimer!=null && offlineTimer.isActive) return;
|
||||
if (offlineTimer != null && offlineTimer.isActive) return;
|
||||
var _duration = new Duration(milliseconds: 500);
|
||||
this.offlineTimer = new Timer.periodic(_duration, offlineNav);
|
||||
}
|
||||
@@ -47,6 +47,6 @@ class _OfflineRedirectState extends State<OfflineRedirect> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return widget.child;
|
||||
return SafeArea(child: widget.child);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user