따라서
FutureBuilder는 삭제를 전달하는데 시간이 걸리므로 onDismissed 보다 confirmDismiss 사용이 적합합니다.
StreamBuilder는 즉각 삭제되므로 onDismissed 사용이 적합합니다.
child: StreamBuilder<List<ScheduleWithCategory>>(
stream: GetIt.I<AppDatabase>().streamSchedules(
selectedDay,
),
builder: (context, snapshot) {
final schedules = snapshot.data!;
return ListView.separated(
itemCount: schedules.length,
itemBuilder: (BuildContext context, int index) {
final scheduleWithCategory = schedules[index];
final schedule = scheduleWithCategory.schedule;
final category = scheduleWithCategory.category;
return Dismissible(
key: ObjectKey(schedule.id),
direction: DismissDirection.endToStart,
// confirmDismiss: (DismissDirection direction) async {
// await GetIt.I<AppDatabase>().removeSchedule(
// schedule.id,
// );
//
// return true;
// },
onDismissed: (DismissDirection direction) {
GetIt.I<AppDatabase>().removeSchedule(
schedule.id,
);
},
Database : drifit.dart 파일의 정렬 코드
OrderingTerm 함수를 사용하여 table의 startTime을 오름차순으로 정렬합니다.
Stream<List<ScheduleWithCategory>> streamSchedules(
DateTime date,
) =>
(select(scheduleTable)
..where(
(table) => table.date.equals(date),
)
..orderBy([
(table) => OrderingTerm(
expression: table.startTime,
mode: OrderingMode.asc,
),
//중복값이 있을 때
(table) => OrderingTerm(
expression: table.endTime,
mode: OrderingMode.asc,
),
]))
.watch();