mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-26 08:44:54 +00:00
added project model
This commit is contained in:
27
lib/features/auth/model/project_model.dart
Normal file
27
lib/features/auth/model/project_model.dart
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
class Project {
|
||||||
|
final String uuid;
|
||||||
|
final String name;
|
||||||
|
final String description;
|
||||||
|
|
||||||
|
const Project({
|
||||||
|
required this.uuid,
|
||||||
|
required this.name,
|
||||||
|
required this.description,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory Project.fromJson(Map<String, dynamic> json) {
|
||||||
|
return Project(
|
||||||
|
uuid: json['uuid'] as String,
|
||||||
|
name: json['name'] as String,
|
||||||
|
description: json['description'] as String,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return {
|
||||||
|
'uuid': uuid,
|
||||||
|
'name': name,
|
||||||
|
'description': description,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,5 +1,6 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:syncrow_app/features/auth/model/project_model.dart';
|
||||||
import 'package:syncrow_app/features/auth/model/token.dart';
|
import 'package:syncrow_app/features/auth/model/token.dart';
|
||||||
|
|
||||||
class UserModel {
|
class UserModel {
|
||||||
@ -20,6 +21,7 @@ class UserModel {
|
|||||||
final bool? hasAcceptedAppAgreement;
|
final bool? hasAcceptedAppAgreement;
|
||||||
final DateTime? appAgreementAcceptedAt;
|
final DateTime? appAgreementAcceptedAt;
|
||||||
final Role? role;
|
final Role? role;
|
||||||
|
final Project? project;
|
||||||
|
|
||||||
UserModel({
|
UserModel({
|
||||||
required this.uuid,
|
required this.uuid,
|
||||||
@ -38,6 +40,7 @@ class UserModel {
|
|||||||
required this.hasAcceptedAppAgreement,
|
required this.hasAcceptedAppAgreement,
|
||||||
required this.appAgreementAcceptedAt,
|
required this.appAgreementAcceptedAt,
|
||||||
required this.role,
|
required this.role,
|
||||||
|
required this.project,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory UserModel.fromJson(Map<String, dynamic> json) {
|
factory UserModel.fromJson(Map<String, dynamic> json) {
|
||||||
@ -62,33 +65,35 @@ class UserModel {
|
|||||||
? DateTime.parse(json['appAgreementAcceptedAt'])
|
? DateTime.parse(json['appAgreementAcceptedAt'])
|
||||||
: null,
|
: null,
|
||||||
role: json['role'] != null ? Role.fromJson(json['role']) : null,
|
role: json['role'] != null ? Role.fromJson(json['role']) : null,
|
||||||
|
project:
|
||||||
|
json['project'] != null ? Project.fromJson(json['project']) : null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
factory UserModel.fromToken(Token token) {
|
factory UserModel.fromToken(Token token) {
|
||||||
Map<String, dynamic> tempJson = Token.decodeToken(token.accessToken);
|
Map<String, dynamic> tempJson = Token.decodeToken(token.accessToken);
|
||||||
return UserModel(
|
return UserModel(
|
||||||
uuid: tempJson['uuid'].toString(),
|
uuid: tempJson['uuid'].toString(),
|
||||||
email: tempJson['email'],
|
email: tempJson['email'],
|
||||||
lastName: tempJson['lastName'],
|
lastName: tempJson['lastName'],
|
||||||
firstName: tempJson['firstName'],
|
firstName: tempJson['firstName'],
|
||||||
profilePicture: UserModel.decodeBase64Image(tempJson['profilePicture']),
|
profilePicture: UserModel.decodeBase64Image(tempJson['profilePicture']),
|
||||||
phoneNumber: null,
|
phoneNumber: null,
|
||||||
isEmailVerified: null,
|
isEmailVerified: null,
|
||||||
isAgreementAccepted: null,
|
isAgreementAccepted: null,
|
||||||
regionUuid: null,
|
regionUuid: null,
|
||||||
regionName: tempJson['region']?['regionName'],
|
regionName: tempJson['region']?['regionName'],
|
||||||
timeZone: tempJson['timezone']?['timeZoneOffset'],
|
timeZone: tempJson['timezone']?['timeZoneOffset'],
|
||||||
hasAcceptedWebAgreement: tempJson['hasAcceptedWebAgreement'],
|
hasAcceptedWebAgreement: tempJson['hasAcceptedWebAgreement'],
|
||||||
webAgreementAcceptedAt: tempJson['webAgreementAcceptedAt'] != null
|
webAgreementAcceptedAt: tempJson['webAgreementAcceptedAt'] != null
|
||||||
? DateTime.parse(tempJson['webAgreementAcceptedAt'])
|
? DateTime.parse(tempJson['webAgreementAcceptedAt'])
|
||||||
: null,
|
: null,
|
||||||
hasAcceptedAppAgreement: tempJson['hasAcceptedAppAgreement'],
|
hasAcceptedAppAgreement: tempJson['hasAcceptedAppAgreement'],
|
||||||
appAgreementAcceptedAt: tempJson['appAgreementAcceptedAt'] != null
|
appAgreementAcceptedAt: tempJson['appAgreementAcceptedAt'] != null
|
||||||
? DateTime.parse(tempJson['appAgreementAcceptedAt'])
|
? DateTime.parse(tempJson['appAgreementAcceptedAt'])
|
||||||
: null,
|
: null,
|
||||||
role: tempJson['role'] != null ? Role.fromJson(tempJson['role']) : null,
|
role: tempJson['role'] != null ? Role.fromJson(tempJson['role']) : null,
|
||||||
);
|
project: null);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8List? decodeBase64Image(String? base64String) {
|
static Uint8List? decodeBase64Image(String? base64String) {
|
||||||
@ -137,8 +142,10 @@ class Role {
|
|||||||
factory Role.fromJson(Map<String, dynamic> json) {
|
factory Role.fromJson(Map<String, dynamic> json) {
|
||||||
return Role(
|
return Role(
|
||||||
uuid: json['uuid'],
|
uuid: json['uuid'],
|
||||||
createdAt: json['createdAt'] != null ? DateTime.parse(json['createdAt']) : null,
|
createdAt:
|
||||||
updatedAt: json['updatedAt'] != null ? DateTime.parse(json['updatedAt']) : null,
|
json['createdAt'] != null ? DateTime.parse(json['createdAt']) : null,
|
||||||
|
updatedAt:
|
||||||
|
json['updatedAt'] != null ? DateTime.parse(json['updatedAt']) : null,
|
||||||
type: json['type'],
|
type: json['type'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
19
lib/features/common/bloc/project_cubit.dart
Normal file
19
lib/features/common/bloc/project_cubit.dart
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
|
|
||||||
|
class ProjectCubit extends Cubit<String?> {
|
||||||
|
final FlutterSecureStorage storage;
|
||||||
|
static const String projectKey = "selected_project_uuid";
|
||||||
|
|
||||||
|
ProjectCubit(this.storage) : super(null);
|
||||||
|
|
||||||
|
Future<void> setProjectUUID(String newUUID) async {
|
||||||
|
await storage.write(key: projectKey, value: newUUID);
|
||||||
|
emit(newUUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> clearProjectUUID() async {
|
||||||
|
await storage.delete(key: projectKey);
|
||||||
|
emit(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user