void onSavePressed() async {
// when formKey is created
// but didn't bond with Form widget
if (formKey.currentState == null) {
return;
}
// this function initiate all validator under Form Widget
// it return true only when all the validator returns null
if (formKey.currentState!.validate()) {
print("No Error");
formKey.currentState!.save();
if (widget.scheduleId == null) { // create
final key =
await GetIt.I<LocalDatabase>().createSchedule(SchedulesCompanion(
date: Value(widget.selectedDay),
startTime: Value(startTime!),
endTime: Value(endTime!),
content: Value(content!),
colorId: Value(selectedColorId!),
));
} else { // update
await GetIt.I<LocalDatabase>().updateScheduleById(
widget.scheduleId!,
SchedulesCompanion(
date: Value(widget.selectedDay),
startTime: Value(startTime!),
endTime: Value(endTime!),
content: Value(content!),
colorId: Value(selectedColorId!),
),
);
}
} else {
print("Error");
}
}
Dart
복사

.png&blockId=68e444ea-f2de-4bba-98b8-f691f9e9969c)
.png&blockId=68e444ea-f2de-4bba-98b8-f691f9e9969c&width=256)