Fixed Remaining Problems

This commit is contained in:
2024-03-15 21:09:16 +01:00
parent 3085a295e5
commit 421d19f91f
27 changed files with 120 additions and 112 deletions

View File

@ -1,5 +1,5 @@
class TimeProgressInvalidNameException implements Exception {
final invalidName;
final String invalidName;
TimeProgressInvalidNameException(this.invalidName);
@ -7,8 +7,8 @@ class TimeProgressInvalidNameException implements Exception {
}
class TimeProgressStartTimeIsNotBeforeEndTimeException implements Exception {
final startTime;
final endTime;
final DateTime startTime;
final DateTime endTime;
TimeProgressStartTimeIsNotBeforeEndTimeException(
this.startTime, this.endTime);

View File

@ -8,9 +8,9 @@ class AppSettings {
final Duration duration;
const AppSettings({
this.doneColor,
this.leftColor,
this.duration,
required this.doneColor,
required this.leftColor,
required this.duration,
});
factory AppSettings.defaults() => const AppSettings(
@ -20,9 +20,9 @@ class AppSettings {
);
AppSettings copyWith({
Color doneColor,
Color leftColor,
Duration duration,
Color? doneColor,
Color? leftColor,
Duration? duration,
}) =>
AppSettings(
doneColor: doneColor ?? this.doneColor,

View File

@ -12,18 +12,20 @@ class AppState {
{this.hasProgressesLoaded = false,
this.hasSettingsLoaded = false,
this.timeProgressList = const [],
this.appSettings});
required this.appSettings});
factory AppState.initial() =>
AppState(hasProgressesLoaded: false, appSettings: AppSettings.defaults());
AppState copyWith({
bool hasLoaded,
List<TimeProgress> timeProgressList,
bool? hasLoaded,
List<TimeProgress>? timeProgressList,
AppSettings? appSettings,
}) {
return AppState(
hasProgressesLoaded: hasLoaded ?? hasProgressesLoaded,
timeProgressList: timeProgressList ?? this.timeProgressList,
appSettings: appSettings ?? this.appSettings,
);
}

View File

@ -10,7 +10,7 @@ class TimeProgress {
final DateTime startTime;
final DateTime endTime;
TimeProgress(this.name, this.startTime, this.endTime, {String id})
TimeProgress(this.name, this.startTime, this.endTime, {String? id})
: id = id ?? Uuid().generateV4();
factory TimeProgress.initialDefault() {
@ -23,7 +23,7 @@ class TimeProgress {
TimeProgress("", DateTime.now(), DateTime.now().add(duration));
TimeProgress copyWith(
{String id, String name, DateTime startTime, DateTime endTime}) =>
{String? id, String? name, DateTime? startTime, DateTime? endTime}) =>
TimeProgress(
name ?? this.name,
startTime ?? this.startTime,
@ -83,21 +83,22 @@ class TimeProgress {
throw TimeProgressInvalidNameException(name);
}
if (!TimeProgress.areTimesValid(startTime, endTime)) {
throw TimeProgressStartTimeIsNotBeforeEndTimeException(startTime, endTime);
throw TimeProgressStartTimeIsNotBeforeEndTimeException(
startTime, endTime);
}
return TimeProgressEntity(id, name, startTime, endTime);
}
static TimeProgress fromEntity(TimeProgressEntity entity) =>
TimeProgress(entity.name, entity.startTime, entity.endTime,
id: entity.id ?? Uuid().generateV4());
id: entity.id);
static bool isValid(TimeProgress tp) =>
TimeProgress.isNameValid(tp.name) &&
TimeProgress.areTimesValid(tp.startTime, tp.endTime);
static bool isNameValid(String name) =>
name != null && name != "" && name.length > 2 && name.length < 21;
name != "" && name.length > 2 && name.length < 21;
static bool areTimesValid(DateTime startTime, DateTime endTime) =>
startTime.isBefore(endTime);