mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 00:05:16 +00:00
Make it easy to cache new data
This commit is contained in:
19
lib/models/cache_model.dart
Normal file
19
lib/models/cache_model.dart
Normal file
@ -0,0 +1,19 @@
|
||||
import 'package:comunic/helpers/database/database_contract.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
/// Cache base model
|
||||
///
|
||||
/// @author Pierre HUBERT
|
||||
|
||||
abstract class CacheModel {
|
||||
final int id;
|
||||
|
||||
const CacheModel({@required this.id}) : assert(id != null);
|
||||
|
||||
/// Initialize a CacheModel from a map
|
||||
CacheModel.fromMap(Map<String, dynamic> map)
|
||||
: id = map[BaseTableContract.C_ID];
|
||||
|
||||
/// Convert the object to a map
|
||||
Map<String, dynamic> toMap();
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
import 'package:comunic/enums/user_page_visibility.dart';
|
||||
import 'package:comunic/helpers/database/database_contract.dart';
|
||||
import 'package:comunic/models/cache_model.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
/// Single user information
|
||||
///
|
||||
/// @author Pierre HUBERT
|
||||
|
||||
class User {
|
||||
final int id;
|
||||
class User extends CacheModel {
|
||||
final String firstName;
|
||||
final String lastName;
|
||||
final UserPageVisibility pageVisibility;
|
||||
@ -15,7 +15,7 @@ class User {
|
||||
final String accountImageURL;
|
||||
|
||||
const User({
|
||||
@required this.id,
|
||||
@required int id,
|
||||
@required this.firstName,
|
||||
@required this.lastName,
|
||||
@required this.pageVisibility,
|
||||
@ -25,7 +25,8 @@ class User {
|
||||
assert(firstName != null),
|
||||
assert(lastName != null),
|
||||
assert(pageVisibility != null),
|
||||
assert(accountImageURL != null);
|
||||
assert(accountImageURL != null),
|
||||
super(id: id);
|
||||
|
||||
/// Get user full name
|
||||
String get fullName => firstName + " " + lastName;
|
||||
@ -42,11 +43,13 @@ class User {
|
||||
}
|
||||
|
||||
User.fromMap(Map<String, dynamic> map)
|
||||
: this.id = map[UserTableContract.C_ID],
|
||||
this.firstName = map[UserTableContract.C_FIRST_NAME],
|
||||
: this.firstName = map[UserTableContract.C_FIRST_NAME],
|
||||
this.lastName = map[UserTableContract.C_LAST_NAME],
|
||||
this.pageVisibility =
|
||||
userPageVisibilityFromString(map[UserTableContract.C_VISIBILITY]),
|
||||
this.virtualDirectory = map[UserTableContract.C_VIRTUAL_DIRECTORY],
|
||||
this.accountImageURL = map[UserTableContract.C_ACCOUNT_IMAGE_URL];
|
||||
this.accountImageURL = map[UserTableContract.C_ACCOUNT_IMAGE_URL],
|
||||
super.fromMap(map);
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user