Implement offline mode
This commit is contained in:
@@ -13,23 +13,35 @@ enum ChangeType {
|
||||
/// Represents a single pending change to be synced with the server.
|
||||
///
|
||||
/// Changes are stored locally when offline and applied once
|
||||
/// the device regains connectivity.
|
||||
/// the device regains connectivity. Each change has a [createdAt] timestamp
|
||||
/// that the server uses to resolve conflicts between devices.
|
||||
class Change {
|
||||
final ChangeType type;
|
||||
final String sheetUuid;
|
||||
final String value;
|
||||
final DateTime createdAt;
|
||||
|
||||
Change({
|
||||
required this.type,
|
||||
required this.sheetUuid,
|
||||
required this.value,
|
||||
});
|
||||
DateTime? createdAt,
|
||||
}) : createdAt = createdAt ?? DateTime.now();
|
||||
|
||||
/// Serializes this change to a map for storage.
|
||||
Map<String, dynamic> toMap() => {
|
||||
'type': type.index,
|
||||
'sheetUuid': sheetUuid,
|
||||
'value': value,
|
||||
'createdAt': createdAt.toIso8601String(),
|
||||
};
|
||||
|
||||
/// Serializes this change to JSON for API requests.
|
||||
Map<String, dynamic> toJson() => {
|
||||
'type': type.name,
|
||||
'sheetUuid': sheetUuid,
|
||||
'value': value,
|
||||
'createdAt': createdAt.toIso8601String(),
|
||||
};
|
||||
|
||||
/// Deserializes a change from a stored map.
|
||||
@@ -41,6 +53,9 @@ class Change {
|
||||
type: ChangeType.values[map['type']],
|
||||
sheetUuid: map['sheetUuid'],
|
||||
value: map['value'],
|
||||
createdAt: map['createdAt'] != null
|
||||
? DateTime.parse(map['createdAt'])
|
||||
: DateTime.now(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user