mirror of
https://github.com/Iconica-Development/flutter_availability.git
synced 2025-05-19 05:03:44 +02:00
fix: preserve userid when switching to template viewmodels
This commit is contained in:
parent
c7c985be00
commit
498e51cfc0
2 changed files with 16 additions and 2 deletions
|
@ -7,6 +7,7 @@ class DayTemplateViewModel {
|
|||
const DayTemplateViewModel({
|
||||
this.data = const DayTemplateDataViewModel(),
|
||||
this.id,
|
||||
this.userId,
|
||||
this.name,
|
||||
this.color,
|
||||
});
|
||||
|
@ -18,6 +19,7 @@ class DayTemplateViewModel {
|
|||
var data = template.templateData as DayTemplateData;
|
||||
return DayTemplateViewModel(
|
||||
id: template.id,
|
||||
userId: template.userId,
|
||||
name: template.name,
|
||||
color: template.color,
|
||||
data: DayTemplateDataViewModel.fromDayTemplateData(data),
|
||||
|
@ -27,6 +29,9 @@ class DayTemplateViewModel {
|
|||
/// The identifier for this template
|
||||
final String? id;
|
||||
|
||||
/// The user id for which the template is created
|
||||
final String? userId;
|
||||
|
||||
/// The name by which the template can be visually identified
|
||||
final String? name;
|
||||
|
||||
|
@ -46,7 +51,7 @@ class DayTemplateViewModel {
|
|||
/// Convert to [AvailabilityTemplateModel] for saving
|
||||
AvailabilityTemplateModel toTemplate() => AvailabilityTemplateModel(
|
||||
id: id,
|
||||
userId: "",
|
||||
userId: userId ?? "",
|
||||
name: name!,
|
||||
color: color!,
|
||||
templateType: AvailabilityTemplateType.day,
|
||||
|
@ -56,12 +61,14 @@ class DayTemplateViewModel {
|
|||
/// Create a copy with new values
|
||||
DayTemplateViewModel copyWith({
|
||||
String? id,
|
||||
String? userId,
|
||||
String? name,
|
||||
int? color,
|
||||
DayTemplateDataViewModel? data,
|
||||
}) =>
|
||||
DayTemplateViewModel(
|
||||
id: id ?? this.id,
|
||||
userId: userId ?? this.userId,
|
||||
name: name ?? this.name,
|
||||
color: color ?? this.color,
|
||||
data: data ?? this.data,
|
||||
|
|
|
@ -6,6 +6,7 @@ class WeekTemplateViewModel {
|
|||
/// Constructor
|
||||
const WeekTemplateViewModel({
|
||||
this.data = const {},
|
||||
this.userId,
|
||||
this.id,
|
||||
this.name,
|
||||
this.color,
|
||||
|
@ -18,6 +19,7 @@ class WeekTemplateViewModel {
|
|||
var data = template.templateData as WeekTemplateData;
|
||||
return WeekTemplateViewModel(
|
||||
id: template.id,
|
||||
userId: template.userId,
|
||||
name: template.name,
|
||||
color: template.color,
|
||||
data: {
|
||||
|
@ -34,6 +36,9 @@ class WeekTemplateViewModel {
|
|||
/// The identifier for this template
|
||||
final String? id;
|
||||
|
||||
/// The user id for which the template is created
|
||||
final String? userId;
|
||||
|
||||
/// The name by which the template can be visually identified
|
||||
final String? name;
|
||||
|
||||
|
@ -55,7 +60,7 @@ class WeekTemplateViewModel {
|
|||
/// Convert to [AvailabilityTemplateModel] for saving
|
||||
AvailabilityTemplateModel toTemplate() => AvailabilityTemplateModel(
|
||||
id: id,
|
||||
userId: "",
|
||||
userId: userId ?? "",
|
||||
name: name!,
|
||||
color: color!,
|
||||
templateType: AvailabilityTemplateType.week,
|
||||
|
@ -70,12 +75,14 @@ class WeekTemplateViewModel {
|
|||
/// Create a copy with new values
|
||||
WeekTemplateViewModel copyWith({
|
||||
String? id,
|
||||
String? userId,
|
||||
String? name,
|
||||
int? color,
|
||||
Map<WeekDay, DayTemplateDataViewModel>? data,
|
||||
}) =>
|
||||
WeekTemplateViewModel(
|
||||
id: id ?? this.id,
|
||||
userId: userId ?? this.userId,
|
||||
name: name ?? this.name,
|
||||
color: color ?? this.color,
|
||||
data: data ?? this.data,
|
||||
|
|
Loading…
Reference in a new issue