diff --git a/lib/presentation/my_page/preparation_spare_time_edit/preparation_spare_time_edit_screen.dart b/lib/presentation/my_page/preparation_spare_time_edit/preparation_spare_time_edit_screen.dart index ba9a7960..2fbf6118 100644 --- a/lib/presentation/my_page/preparation_spare_time_edit/preparation_spare_time_edit_screen.dart +++ b/lib/presentation/my_page/preparation_spare_time_edit/preparation_spare_time_edit_screen.dart @@ -201,7 +201,6 @@ class _PreparationSection extends StatelessWidget { Expanded( child: PreparationFormCreateList( preparationNameState: preparationNameState, - enableDismissible: true, onNameChanged: ({required int index, required String value}) { context.read().add( PreparationFormPreparationStepNameChanged( diff --git a/lib/presentation/schedule_create/schedule_spare_and_preparing_time/preparation_form/components/preparation_form_create_list.dart b/lib/presentation/schedule_create/schedule_spare_and_preparing_time/preparation_form/components/preparation_form_create_list.dart index 280ac666..6a7ca06a 100644 --- a/lib/presentation/schedule_create/schedule_spare_and_preparing_time/preparation_form/components/preparation_form_create_list.dart +++ b/lib/presentation/schedule_create/schedule_spare_and_preparing_time/preparation_form/components/preparation_form_create_list.dart @@ -4,7 +4,6 @@ import 'package:on_time_front/presentation/onboarding/preparation_name_select/co import 'package:on_time_front/presentation/schedule_create/schedule_spare_and_preparing_time/preparation_form/bloc/preparation_form_bloc.dart'; import 'package:on_time_front/presentation/schedule_create/schedule_spare_and_preparing_time/preparation_form/components/preparation_form_list_field.dart'; import 'package:on_time_front/presentation/schedule_create/schedule_spare_and_preparing_time/preparation_form/components/preparation_form_reorderable_list.dart'; -import 'package:on_time_front/presentation/schedule_create/schedule_spare_and_preparing_time/preparation_form/components/preparation_form_reorderable_list_dissmissible.dart'; import 'package:on_time_front/presentation/schedule_create/schedule_spare_and_preparing_time/preparation_form/cubit/preparation_step_form_cubit.dart'; class PreparationFormCreateList extends StatelessWidget { @@ -12,49 +11,32 @@ class PreparationFormCreateList extends StatelessWidget { {super.key, required this.preparationNameState, required this.onNameChanged, - required this.onCreationRequested, - this.enableDismissible = false}); + required this.onCreationRequested}); final PreparationFormState preparationNameState; final void Function({required int index, required String value}) onNameChanged; final VoidCallback onCreationRequested; - final bool enableDismissible; @override Widget build(BuildContext context) { return SingleChildScrollView( child: Column( children: [ - enableDismissible - ? PreparationFormReorderableListDismissible( - preparationStepList: preparationNameState.preparationStepList, - onNameChanged: (index, value) { - onNameChanged(index: index, value: value); - }, - onTimeChanged: (index, value) => context - .read() - .add(PreparationFormPreparationStepTimeChanged( - index: index, preparationStepTime: value)), - onReorder: (oldIndex, newIndex) => context - .read() - .add(PreparationFormPreparationStepOrderChanged( - oldIndex: oldIndex, newIndex: newIndex)), - ) - : PreparationFormReorderableList( - preparationStepList: preparationNameState.preparationStepList, - onNameChanged: (index, value) { - onNameChanged(index: index, value: value); - }, - onTimeChanged: (index, value) => context - .read() - .add(PreparationFormPreparationStepTimeChanged( - index: index, preparationStepTime: value)), - onReorder: (oldIndex, newIndex) => context - .read() - .add(PreparationFormPreparationStepOrderChanged( - oldIndex: oldIndex, newIndex: newIndex)), - ), + PreparationFormReorderableList( + preparationStepList: preparationNameState.preparationStepList, + onNameChanged: (index, value) { + onNameChanged(index: index, value: value); + }, + onTimeChanged: (index, value) => context + .read() + .add(PreparationFormPreparationStepTimeChanged( + index: index, preparationStepTime: value)), + onReorder: (oldIndex, newIndex) => context + .read() + .add(PreparationFormPreparationStepOrderChanged( + oldIndex: oldIndex, newIndex: newIndex)), + ), preparationNameState.status == PreparationFormStatus.adding ? BlocProvider( create: (context) => PreparationStepFormCubit( diff --git a/lib/presentation/schedule_create/schedule_spare_and_preparing_time/preparation_form/components/preparation_form_reorderable_list.dart b/lib/presentation/schedule_create/schedule_spare_and_preparing_time/preparation_form/components/preparation_form_reorderable_list.dart index cd3ac0a4..625b6f26 100644 --- a/lib/presentation/schedule_create/schedule_spare_and_preparing_time/preparation_form/components/preparation_form_reorderable_list.dart +++ b/lib/presentation/schedule_create/schedule_spare_and_preparing_time/preparation_form/components/preparation_form_reorderable_list.dart @@ -1,7 +1,32 @@ import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:flutter_swipe_action_cell/core/cell.dart'; +import 'package:on_time_front/presentation/schedule_create/schedule_spare_and_preparing_time/preparation_form/bloc/preparation_form_bloc.dart'; import 'package:on_time_front/presentation/schedule_create/schedule_spare_and_preparing_time/preparation_form/components/preparation_form_list_field.dart'; import 'package:on_time_front/presentation/schedule_create/schedule_spare_and_preparing_time/preparation_form/cubit/preparation_step_form_cubit.dart'; +class _SwipeActionContent extends StatelessWidget { + const _SwipeActionContent({ + required this.icon, + required this.color, + }); + + final Widget icon; + final Color color; + + @override + Widget build(BuildContext context) { + return Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(12), + color: color, + ), + padding: const EdgeInsets.all(18.0), + child: icon, + ); + } +} + class PreparationFormReorderableList extends StatelessWidget { const PreparationFormReorderableList({ super.key, @@ -40,16 +65,44 @@ class PreparationFormReorderableList extends StatelessWidget { physics: NeverScrollableScrollPhysics(), itemCount: preparationStepList.length, itemBuilder: (context, index) { - return PreparationFormListField( - key: ValueKey(preparationStepList[index].id), - index: index, - preparationStep: preparationStepList[index], - onNameChanged: (value) { - onNameChanged(index, value); - }, - onPreparationTimeChanged: (value) { - onTimeChanged(index, value); - }, + final step = preparationStepList[index]; + final theme = Theme.of(context); + + return SwipeActionCell( + key: ValueKey(step.id), + backgroundColor: Colors.transparent, + trailingActions: [ + SwipeAction( + onTap: (controller) { + if (preparationStepList.length <= 1) return; + context.read().add( + PreparationFormPreparationStepRemoved( + preparationStepId: step.id, + ), + ); + }, + color: Colors.transparent, + content: _SwipeActionContent( + icon: const Icon( + Icons.delete, + color: Colors.white, + size: 24, + ), + color: theme.colorScheme.error, + ), + ), + ], + child: PreparationFormListField( + key: ValueKey('field_${step.id}'), + index: index, + preparationStep: step, + onNameChanged: (value) { + onNameChanged(index, value); + }, + onPreparationTimeChanged: (value) { + onTimeChanged(index, value); + }, + ), ); }, onReorder: (int oldIndex, int newIndex) { diff --git a/lib/presentation/schedule_create/schedule_spare_and_preparing_time/preparation_form/components/preparation_form_reorderable_list_dissmissible.dart b/lib/presentation/schedule_create/schedule_spare_and_preparing_time/preparation_form/components/preparation_form_reorderable_list_dissmissible.dart deleted file mode 100644 index 376df148..00000000 --- a/lib/presentation/schedule_create/schedule_spare_and_preparing_time/preparation_form/components/preparation_form_reorderable_list_dissmissible.dart +++ /dev/null @@ -1,94 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:on_time_front/presentation/schedule_create/schedule_spare_and_preparing_time/preparation_form/bloc/preparation_form_bloc.dart'; -import 'package:on_time_front/presentation/schedule_create/schedule_spare_and_preparing_time/preparation_form/components/preparation_form_list_field.dart'; -import 'package:on_time_front/presentation/schedule_create/schedule_spare_and_preparing_time/preparation_form/cubit/preparation_step_form_cubit.dart'; - -class PreparationFormReorderableListDismissible extends StatelessWidget { - const PreparationFormReorderableListDismissible({ - super.key, - required this.preparationStepList, - required this.onNameChanged, - required this.onTimeChanged, - required this.onReorder, - }); - - final List preparationStepList; - final Function(int index, String value) onNameChanged; - final Function(int index, Duration value) onTimeChanged; - final Function(int oldIndex, int newIndex) onReorder; - - @override - Widget build(BuildContext context) { - Widget proxyDecorator( - Widget child, int index, Animation animation) { - return AnimatedBuilder( - animation: animation, - builder: (BuildContext context, Widget? child) { - return SizedBox( - child: child, - ); - }, - child: child, - ); - } - - return SingleChildScrollView( - child: ReorderableListView.builder( - buildDefaultDragHandles: false, - proxyDecorator: proxyDecorator, - shrinkWrap: true, - padding: EdgeInsets.zero, - physics: NeverScrollableScrollPhysics(), - itemCount: preparationStepList.length, - itemBuilder: (context, index) { - return Dismissible( - key: ValueKey( - 'dismissible_${preparationStepList[index].id}'), - direction: DismissDirection.endToStart, - background: Container( - height: double.infinity, - alignment: Alignment.centerRight, - padding: const EdgeInsets.only(right: 20.0), - color: Colors.red, - child: const Icon( - Icons.delete, - color: Colors.white, - size: 24, - ), - ), - confirmDismiss: (direction) async { - if (preparationStepList.length <= 1) { - return false; - } - return direction == DismissDirection.endToStart; - }, - onDismissed: (direction) { - if (direction == DismissDirection.endToStart) { - context.read().add( - PreparationFormPreparationStepRemoved( - preparationStepId: preparationStepList[index].id, - ), - ); - } - }, - child: PreparationFormListField( - key: ValueKey(preparationStepList[index].id), - index: index, - preparationStep: preparationStepList[index], - onNameChanged: (value) { - onNameChanged(index, value); - }, - onPreparationTimeChanged: (value) { - onTimeChanged(index, value); - }, - ), - ); - }, - onReorder: (int oldIndex, int newIndex) { - onReorder(oldIndex, newIndex); - }, - ), - ); - } -} diff --git a/lib/presentation/schedule_create/schedule_spare_and_preparing_time/screens/schedule_spare_and_preparing_time_form.dart b/lib/presentation/schedule_create/schedule_spare_and_preparing_time/screens/schedule_spare_and_preparing_time_form.dart index 22bc4ddc..4b2f5e15 100644 --- a/lib/presentation/schedule_create/schedule_spare_and_preparing_time/screens/schedule_spare_and_preparing_time_form.dart +++ b/lib/presentation/schedule_create/schedule_spare_and_preparing_time/screens/schedule_spare_and_preparing_time_form.dart @@ -96,11 +96,11 @@ class _ScheduleSpareAndPreparingTimeFormState Padding( padding: const EdgeInsets.only(top: 8.0, left: 16.0), child: MessageBubble( - message: state.getOverlapMessage(context)!, + message: state.getOverlapMessage(context)!, type: state.isOverlapError ? MessageBubbleType.error : MessageBubbleType.warning, - ), + ), ), ], ); diff --git a/lib/presentation/shared/router/go_router.dart b/lib/presentation/shared/router/go_router.dart index 72604b43..485b8432 100644 --- a/lib/presentation/shared/router/go_router.dart +++ b/lib/presentation/shared/router/go_router.dart @@ -113,7 +113,8 @@ GoRouter goRouterConfig(AuthBloc authBloc, ScheduleBloc scheduleBloc) { GoRoute( path: '/preparationEdit', builder: (context, state) => PreparationEditForm( - preparationEntity: state.extra as PreparationEntity)), + preparationEntity: (state.extra as PreparationEntity?) ?? + const PreparationEntity(preparationStepList: []))), GoRoute( path: '/scheduleStart', name: 'scheduleStart',