| 
									
										
										
										
											2023-08-14 13:34:01 -07:00
										 |  |  | import 'package:appflowy/generated/flowy_svgs.g.dart'; | 
					
						
							| 
									
										
										
										
											2023-02-26 16:27:17 +08:00
										 |  |  | import 'package:appflowy/generated/locale_keys.g.dart'; | 
					
						
							|  |  |  | import 'package:appflowy/plugins/trash/src/sizes.dart'; | 
					
						
							|  |  |  | import 'package:appflowy/plugins/trash/src/trash_header.dart'; | 
					
						
							| 
									
										
										
										
											2023-12-19 20:12:37 +05:30
										 |  |  | import 'package:appflowy/workspace/presentation/widgets/dialogs.dart'; | 
					
						
							| 
									
										
										
										
											2023-02-26 16:27:17 +08:00
										 |  |  | import 'package:appflowy/startup/startup.dart'; | 
					
						
							| 
									
										
										
										
											2022-09-21 11:46:32 +08:00
										 |  |  | import 'package:easy_localization/easy_localization.dart'; | 
					
						
							| 
									
										
										
										
											2022-11-19 17:53:30 +08:00
										 |  |  | import 'package:flowy_infra/size.dart'; | 
					
						
							| 
									
										
										
										
											2022-09-21 11:46:32 +08:00
										 |  |  | import 'package:flowy_infra_ui/style_widget/button.dart'; | 
					
						
							|  |  |  | import 'package:flowy_infra_ui/style_widget/scrolling/styled_list.dart'; | 
					
						
							|  |  |  | import 'package:flowy_infra_ui/style_widget/scrolling/styled_scroll_bar.dart'; | 
					
						
							|  |  |  | import 'package:flowy_infra_ui/style_widget/scrolling/styled_scrollview.dart'; | 
					
						
							|  |  |  | import 'package:flowy_infra_ui/style_widget/text.dart'; | 
					
						
							|  |  |  | import 'package:flowy_infra_ui/widget/spacing.dart'; | 
					
						
							|  |  |  | import 'package:flutter/material.dart'; | 
					
						
							|  |  |  | import 'package:flutter_bloc/flutter_bloc.dart'; | 
					
						
							|  |  |  | import 'package:styled_widget/styled_widget.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import 'application/trash_bloc.dart'; | 
					
						
							|  |  |  | import 'src/trash_cell.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TrashPage extends StatefulWidget { | 
					
						
							| 
									
										
										
										
											2023-12-08 20:01:54 +07:00
										 |  |  |   const TrashPage({super.key}); | 
					
						
							| 
									
										
										
										
											2022-09-21 11:46:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   State<TrashPage> createState() => _TrashPageState(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class _TrashPageState extends State<TrashPage> { | 
					
						
							|  |  |  |   final ScrollController _scrollController = ScrollController(); | 
					
						
							| 
									
										
										
										
											2024-02-07 18:38:53 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   void dispose() { | 
					
						
							|  |  |  |     _scrollController.dispose(); | 
					
						
							|  |  |  |     super.dispose(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-21 11:46:32 +08:00
										 |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							|  |  |  |     const horizontalPadding = 80.0; | 
					
						
							|  |  |  |     return BlocProvider( | 
					
						
							|  |  |  |       create: (context) => getIt<TrashBloc>()..add(const TrashEvent.initial()), | 
					
						
							|  |  |  |       child: BlocBuilder<TrashBloc, TrashState>( | 
					
						
							|  |  |  |         builder: (context, state) { | 
					
						
							|  |  |  |           return SizedBox.expand( | 
					
						
							|  |  |  |             child: Column( | 
					
						
							|  |  |  |               children: [ | 
					
						
							| 
									
										
										
										
											2022-11-10 14:22:18 +08:00
										 |  |  |                 _renderTopBar(context, state), | 
					
						
							| 
									
										
										
										
											2022-09-21 11:46:32 +08:00
										 |  |  |                 const VSpace(32), | 
					
						
							|  |  |  |                 _renderTrashList(context, state), | 
					
						
							|  |  |  |               ], | 
					
						
							|  |  |  |             ).padding(horizontal: horizontalPadding, vertical: 48), | 
					
						
							|  |  |  |           ); | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Widget _renderTrashList(BuildContext context, TrashState state) { | 
					
						
							|  |  |  |     const barSize = 6.0; | 
					
						
							|  |  |  |     return Expanded( | 
					
						
							|  |  |  |       child: ScrollbarListStack( | 
					
						
							|  |  |  |         axis: Axis.vertical, | 
					
						
							|  |  |  |         controller: _scrollController, | 
					
						
							|  |  |  |         scrollbarPadding: EdgeInsets.only(top: TrashSizes.headerHeight), | 
					
						
							|  |  |  |         barSize: barSize, | 
					
						
							|  |  |  |         child: StyledSingleChildScrollView( | 
					
						
							|  |  |  |           barSize: barSize, | 
					
						
							|  |  |  |           axis: Axis.horizontal, | 
					
						
							|  |  |  |           child: SizedBox( | 
					
						
							|  |  |  |             width: TrashSizes.totalWidth, | 
					
						
							|  |  |  |             child: ScrollConfiguration( | 
					
						
							|  |  |  |               behavior: const ScrollBehavior().copyWith(scrollbars: false), | 
					
						
							|  |  |  |               child: CustomScrollView( | 
					
						
							|  |  |  |                 shrinkWrap: true, | 
					
						
							|  |  |  |                 physics: StyledScrollPhysics(), | 
					
						
							|  |  |  |                 controller: _scrollController, | 
					
						
							|  |  |  |                 slivers: [ | 
					
						
							|  |  |  |                   _renderListHeader(context, state), | 
					
						
							|  |  |  |                   _renderListBody(context, state), | 
					
						
							|  |  |  |                 ], | 
					
						
							|  |  |  |               ), | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |         ), | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-10 14:22:18 +08:00
										 |  |  |   Widget _renderTopBar(BuildContext context, TrashState state) { | 
					
						
							| 
									
										
										
										
											2022-09-21 11:46:32 +08:00
										 |  |  |     return SizedBox( | 
					
						
							|  |  |  |       height: 36, | 
					
						
							|  |  |  |       child: Row( | 
					
						
							|  |  |  |         crossAxisAlignment: CrossAxisAlignment.stretch, | 
					
						
							|  |  |  |         children: [ | 
					
						
							| 
									
										
										
										
											2022-11-19 17:53:30 +08:00
										 |  |  |           FlowyText.semibold( | 
					
						
							|  |  |  |             LocaleKeys.trash_text.tr(), | 
					
						
							|  |  |  |             fontSize: FontSizes.s16, | 
					
						
							| 
									
										
										
										
											2023-03-29 20:44:37 -05:00
										 |  |  |             color: Theme.of(context).colorScheme.tertiary, | 
					
						
							| 
									
										
										
										
											2022-11-19 17:53:30 +08:00
										 |  |  |           ), | 
					
						
							| 
									
										
										
										
											2022-09-21 11:46:32 +08:00
										 |  |  |           const Spacer(), | 
					
						
							|  |  |  |           IntrinsicWidth( | 
					
						
							|  |  |  |             child: FlowyButton( | 
					
						
							| 
									
										
										
										
											2022-11-19 17:53:30 +08:00
										 |  |  |               text: FlowyText.medium(LocaleKeys.trash_restoreAll.tr()), | 
					
						
							| 
									
										
										
										
											2023-08-14 13:34:01 -07:00
										 |  |  |               leftIcon: const FlowySvg(FlowySvgs.restore_s), | 
					
						
							| 
									
										
										
										
											2023-12-19 20:12:37 +05:30
										 |  |  |               onTap: () { | 
					
						
							|  |  |  |                 NavigatorAlertDialog( | 
					
						
							|  |  |  |                   title: LocaleKeys.trash_confirmRestoreAll_title.tr(), | 
					
						
							|  |  |  |                   confirm: () { | 
					
						
							|  |  |  |                     context | 
					
						
							|  |  |  |                         .read<TrashBloc>() | 
					
						
							|  |  |  |                         .add(const TrashEvent.restoreAll()); | 
					
						
							|  |  |  |                   }, | 
					
						
							|  |  |  |                 ).show(context); | 
					
						
							|  |  |  |               }, | 
					
						
							| 
									
										
										
										
											2022-09-21 11:46:32 +08:00
										 |  |  |             ), | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |           const HSpace(6), | 
					
						
							|  |  |  |           IntrinsicWidth( | 
					
						
							|  |  |  |             child: FlowyButton( | 
					
						
							| 
									
										
										
										
											2022-11-19 17:53:30 +08:00
										 |  |  |               text: FlowyText.medium(LocaleKeys.trash_deleteAll.tr()), | 
					
						
							| 
									
										
										
										
											2023-08-14 13:34:01 -07:00
										 |  |  |               leftIcon: const FlowySvg(FlowySvgs.delete_s), | 
					
						
							| 
									
										
										
										
											2023-12-19 20:12:37 +05:30
										 |  |  |               onTap: () { | 
					
						
							|  |  |  |                 NavigatorAlertDialog( | 
					
						
							|  |  |  |                   title: LocaleKeys.trash_confirmDeleteAll_title.tr(), | 
					
						
							|  |  |  |                   confirm: () { | 
					
						
							|  |  |  |                     context.read<TrashBloc>().add(const TrashEvent.deleteAll()); | 
					
						
							|  |  |  |                   }, | 
					
						
							|  |  |  |                 ).show(context); | 
					
						
							|  |  |  |               }, | 
					
						
							| 
									
										
										
										
											2022-09-21 11:46:32 +08:00
										 |  |  |             ), | 
					
						
							| 
									
										
										
										
											2023-11-14 22:33:07 +08:00
										 |  |  |           ), | 
					
						
							| 
									
										
										
										
											2022-09-21 11:46:32 +08:00
										 |  |  |         ], | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Widget _renderListHeader(BuildContext context, TrashState state) { | 
					
						
							|  |  |  |     return SliverPersistentHeader( | 
					
						
							|  |  |  |       delegate: TrashHeaderDelegate(), | 
					
						
							|  |  |  |       floating: true, | 
					
						
							|  |  |  |       pinned: true, | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Widget _renderListBody(BuildContext context, TrashState state) { | 
					
						
							|  |  |  |     return SliverList( | 
					
						
							|  |  |  |       delegate: SliverChildBuilderDelegate( | 
					
						
							|  |  |  |         (BuildContext context, int index) { | 
					
						
							|  |  |  |           final object = state.objects[index]; | 
					
						
							|  |  |  |           return SizedBox( | 
					
						
							|  |  |  |             height: 42, | 
					
						
							|  |  |  |             child: TrashCell( | 
					
						
							|  |  |  |               object: object, | 
					
						
							|  |  |  |               onRestore: () { | 
					
						
							| 
									
										
										
										
											2023-12-19 20:12:37 +05:30
										 |  |  |                 NavigatorAlertDialog( | 
					
						
							|  |  |  |                   title: LocaleKeys.deletePagePrompt_restore.tr(), | 
					
						
							|  |  |  |                   confirm: () { | 
					
						
							|  |  |  |                     context | 
					
						
							|  |  |  |                         .read<TrashBloc>() | 
					
						
							|  |  |  |                         .add(TrashEvent.putback(object.id)); | 
					
						
							|  |  |  |                   }, | 
					
						
							|  |  |  |                 ).show(context); | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |               onDelete: () { | 
					
						
							|  |  |  |                 NavigatorAlertDialog( | 
					
						
							|  |  |  |                   title: LocaleKeys.deletePagePrompt_deletePermanent.tr(), | 
					
						
							|  |  |  |                   confirm: () { | 
					
						
							|  |  |  |                     context.read<TrashBloc>().add(TrashEvent.delete(object)); | 
					
						
							|  |  |  |                   }, | 
					
						
							|  |  |  |                 ).show(context); | 
					
						
							| 
									
										
										
										
											2022-09-21 11:46:32 +08:00
										 |  |  |               }, | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |           ); | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         childCount: state.objects.length, | 
					
						
							|  |  |  |         addAutomaticKeepAlives: false, | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |