This commit is contained in:
2020-09-11 16:14:36 +06:30
parent f65b69aab0
commit 96a095e2e9
29 changed files with 1370 additions and 837 deletions

View File

@@ -9,6 +9,7 @@ import 'package:fcs/fcs/common/domain/entities/auth_status.dart';
import 'package:fcs/fcs/common/domain/entities/setting.dart';
import 'package:fcs/fcs/common/domain/entities/user.dart';
import 'package:fcs/fcs/common/helpers/network_connectivity.dart';
import 'package:fcs/fcs/common/pages/model/base_model.dart';
import 'package:fcs/fcs/common/services/services.dart';
import 'package:flutter/foundation.dart';
import 'package:logging/logging.dart';
@@ -16,6 +17,7 @@ import 'package:package_info/package_info.dart';
class MainModel extends ChangeNotifier {
final log = Logger('MainModel');
List<BaseModel> models = [];
User user;
PackageInfo packageInfo;
@@ -37,67 +39,50 @@ class MainModel extends ChangeNotifier {
notifyListeners();
});
Services.instance.authService.onAuthStatus().listen((event) {
this.user=event;
notifyListeners();
print("main event-->$event");
});
}
bool faqEditable(){
return this.user != null && false;
}
bool termEditable(){
return this.user != null && false;
}
bool contactEditable(){
return this.user != null && false;
}
bool isLogin() {
return this.user != null;
}
bool isCustomer() {
return user != null && user.name != "Owner";
}
bool isOwner() {
return user != null && user.name == "Owner";
}
bool hasEmail() {
return this.user != null && this.user.isEmail();
}
bool agreedTerm() {
return this.user != null && this.user.agreeTerms;
}
bool isBuyer() {
return this.user == null || this.user.isBuyer();
return user != null && user.isCustomer();
}
bool isSysAdmin() {
return this.user != null && this.user.isSysAdmin();
return this.user != null && this.user.hasSysAdmin();
}
bool isSysSupport() {
return this.user != null && this.user.isSysSupport();
}
bool isBizAdmin() {
return this.user != null && this.user.isBizAdmin();
}
bool isOwnerAndAbove() {
return this.user != null && this.user.isOwnerAndAbove();
}
bool isAdmin() {
return this.user != null && this.user.hasAdmin();
}
bool showHistoryBtn() {
return isSysAdmin() || isSysSupport() || isBizAdmin();
}
init() async {
await _loadSetting();
_loadUser();
this.packageInfo = await PackageInfo.fromPlatform();
}
// void addModel(BaseModel model) {
// models.add(model);
// }
void addModel(BaseModel model) {
models.add(model);
}
// void _initUser(User user) {
// models.forEach((m) => m.initUser(user));
@@ -107,18 +92,18 @@ class MainModel extends ChangeNotifier {
// }
// }
// void _initSetting(Setting setting) {
// models.forEach((m) => m.initSetting(setting));
// }
void _initSetting(Setting setting) {
models.forEach((m) => m.initSetting(setting));
}
Future<void> _loadSetting() async {
try {
Services.instance.authService.getSetting().listen((event) {
this.setting = event;
_initSetting(setting);
notifyListeners();
});
} finally {}
// _initSetting(setting);
}
void _loadUser() async {