Feature/Basic App (#1) Basic App Structure Consists of Time Progress Dashboard, Time Progress Detail View and Time Progress Creator. All of these have an AppDrawer with a Link To the Dashboard and all your Track Time Progresses, also an About Button. Commits: * Undetailed Commit more work * Changed isEditing ? in Detail Screen and Extracted FAB row to widget * Extracted Progress Detail Fab Row and Progress Detail select Date Btn to widgets * Create Progress Detail Widgets Folder * Extracted Edit Dates Row Widget * Extracted Functions from ui * Made some fields private * LoadTimerProgressList if unloaded function * Created App Yes No Dialog Widget * Using Yes No Dialog in Detail Screen * Created TimeProgress Initial Default factory * Renamed to Time Progress Tracker * Added About Button in App Drawer * Code cleanup * Code clean up and fixed Bug with null as string in Repository Signed-off-by Andreas Fahrecker <AndreasFahrecker@gmail.com>
78 lines
1.9 KiB
Dart
78 lines
1.9 KiB
Dart
import 'package:meta/meta.dart';
|
|
import 'package:time_progress_tracker/persistence/time_progress_entity.dart';
|
|
import 'package:time_progress_tracker/uuid.dart';
|
|
|
|
@immutable
|
|
class TimeProgress {
|
|
final String id;
|
|
final String name;
|
|
final DateTime startTime;
|
|
final DateTime endTime;
|
|
|
|
TimeProgress(this.name, this.startTime, this.endTime, {String id})
|
|
: id = id ?? Uuid().generateV4();
|
|
|
|
factory TimeProgress.initialDefault() {
|
|
int thisYear = DateTime.now().year;
|
|
return TimeProgress("", DateTime(thisYear - 1), DateTime(thisYear + 1));
|
|
}
|
|
|
|
TimeProgress copyWith(
|
|
{String id, String name, DateTime startTime, DateTime endTime}) {
|
|
return TimeProgress(
|
|
name ?? this.name,
|
|
startTime ?? this.startTime,
|
|
endTime ?? this.endTime,
|
|
id: id ?? this.id,
|
|
);
|
|
}
|
|
|
|
int daysBehind() {
|
|
return DateTime.now().difference(startTime).inDays;
|
|
}
|
|
|
|
int daysLeft() {
|
|
return endTime.difference(DateTime.now()).inDays;
|
|
}
|
|
|
|
int allDays() {
|
|
return endTime.difference(startTime).inDays;
|
|
}
|
|
|
|
double percentDone() {
|
|
return this.daysBehind() / (this.allDays() / 100) / 100;
|
|
}
|
|
|
|
@override
|
|
int get hashCode =>
|
|
id.hashCode ^ name.hashCode ^ startTime.hashCode ^ endTime.hashCode;
|
|
|
|
@override
|
|
bool operator ==(Object other) =>
|
|
identical(this, other) ||
|
|
other is TimeProgress &&
|
|
runtimeType == other.runtimeType &&
|
|
id == other.id &&
|
|
name == other.name &&
|
|
startTime == other.startTime &&
|
|
endTime == other.endTime;
|
|
|
|
@override
|
|
String toString() {
|
|
return "TimeProgress{id: $id, name: $name, startTime: $startTime, endTime: $endTime}";
|
|
}
|
|
|
|
TimeProgressEntity toEntity() {
|
|
return TimeProgressEntity(id, name, startTime, endTime);
|
|
}
|
|
|
|
static TimeProgress fromEntity(TimeProgressEntity entity) {
|
|
return TimeProgress(
|
|
entity.name,
|
|
entity.startTime,
|
|
entity.endTime,
|
|
id: entity.id ?? Uuid().generateV4(),
|
|
);
|
|
}
|
|
}
|