use latest version of timline poc
This commit is contained in:
110
packages/z-flutter/lib/state.dart
Normal file
110
packages/z-flutter/lib/state.dart
Normal file
@@ -0,0 +1,110 @@
|
||||
// Bridge data-transfer types deserialized from JSON pushed by the React host.
|
||||
//
|
||||
// The shape is normalized: groups and items are stored as maps keyed by
|
||||
// ID, with groupOrder preserving display ordering.
|
||||
//
|
||||
// Keep in sync with `apps/web/src/lib/flutter-bridge.ts`.
|
||||
|
||||
class TimelineState {
|
||||
final TimelineData timeline;
|
||||
final Map<String, TimelineGroupData> groups;
|
||||
final Map<String, TimelineItemData> items;
|
||||
final List<String> groupOrder;
|
||||
final String? selectedItemId;
|
||||
final bool darkMode;
|
||||
|
||||
TimelineState({
|
||||
required this.timeline,
|
||||
required this.groups,
|
||||
required this.items,
|
||||
required this.groupOrder,
|
||||
this.selectedItemId,
|
||||
this.darkMode = true,
|
||||
});
|
||||
|
||||
factory TimelineState.fromJson(Map<String, dynamic> json) {
|
||||
final rawGroups = json['groups'] as Map<String, dynamic>;
|
||||
final rawItems = json['items'] as Map<String, dynamic>;
|
||||
|
||||
return TimelineState(
|
||||
timeline: TimelineData.fromJson(json['timeline'] as Map<String, dynamic>),
|
||||
groups: rawGroups.map(
|
||||
(k, v) =>
|
||||
MapEntry(k, TimelineGroupData.fromJson(v as Map<String, dynamic>)),
|
||||
),
|
||||
items: rawItems.map(
|
||||
(k, v) =>
|
||||
MapEntry(k, TimelineItemData.fromJson(v as Map<String, dynamic>)),
|
||||
),
|
||||
groupOrder: (json['groupOrder'] as List<dynamic>).cast<String>(),
|
||||
selectedItemId: json['selectedItemId'] as String?,
|
||||
darkMode: json['darkMode'] as bool? ?? true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TimelineData {
|
||||
final String id;
|
||||
final String title;
|
||||
|
||||
TimelineData({required this.id, required this.title});
|
||||
|
||||
factory TimelineData.fromJson(Map<String, dynamic> json) {
|
||||
return TimelineData(
|
||||
id: json['id'] as String,
|
||||
title: json['title'] as String,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TimelineGroupData {
|
||||
final String id;
|
||||
final String title;
|
||||
final int sortOrder;
|
||||
|
||||
TimelineGroupData({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.sortOrder,
|
||||
});
|
||||
|
||||
factory TimelineGroupData.fromJson(Map<String, dynamic> json) {
|
||||
return TimelineGroupData(
|
||||
id: json['id'] as String,
|
||||
title: json['title'] as String,
|
||||
sortOrder: json['sortOrder'] as int,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TimelineItemData {
|
||||
final String id;
|
||||
final String groupId;
|
||||
final String title;
|
||||
final String? description;
|
||||
final String start;
|
||||
final String? end;
|
||||
final int lane;
|
||||
|
||||
TimelineItemData({
|
||||
required this.id,
|
||||
required this.groupId,
|
||||
required this.title,
|
||||
this.description,
|
||||
required this.start,
|
||||
this.end,
|
||||
required this.lane,
|
||||
});
|
||||
|
||||
factory TimelineItemData.fromJson(Map<String, dynamic> json) {
|
||||
return TimelineItemData(
|
||||
id: json['id'] as String,
|
||||
groupId: json['groupId'] as String,
|
||||
title: json['title'] as String,
|
||||
description: json['description'] as String?,
|
||||
start: json['start'] as String,
|
||||
end: json['end'] as String?,
|
||||
lane: json['lane'] as int,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user