| 
									
										
										
										
											2022-03-01 16:05:45 +08:00
										 |  |  | export "./src/sizes.dart"; | 
					
						
							|  |  |  | export "./src/trash_cell.dart"; | 
					
						
							|  |  |  | export "./src/trash_header.dart"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-09 10:35:27 +08:00
										 |  |  | import 'package:app_flowy/startup/plugin/plugin.dart'; | 
					
						
							| 
									
										
										
										
											2021-10-14 14:34:22 +08:00
										 |  |  | import 'package:app_flowy/startup/startup.dart'; | 
					
						
							| 
									
										
										
										
											2022-08-09 10:35:27 +08:00
										 |  |  | import 'package:app_flowy/plugins/trash/application/trash_bloc.dart'; | 
					
						
							| 
									
										
										
										
											2022-03-01 16:05:45 +08:00
										 |  |  | import 'package:app_flowy/workspace/presentation/home/home_stack.dart'; | 
					
						
							| 
									
										
										
										
											2021-12-07 23:01:23 +05:30
										 |  |  | import 'package:easy_localization/easy_localization.dart'; | 
					
						
							| 
									
										
										
										
											2021-10-13 23:11:45 +08:00
										 |  |  | import 'package:flowy_infra/image.dart'; | 
					
						
							|  |  |  | import 'package:flowy_infra/theme.dart'; | 
					
						
							| 
									
										
										
										
											2021-10-14 18:11:59 +08:00
										 |  |  | 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'; | 
					
						
							| 
									
										
										
										
											2021-10-13 23:11:45 +08:00
										 |  |  | import 'package:flowy_infra_ui/style_widget/text.dart'; | 
					
						
							|  |  |  | import 'package:flowy_infra_ui/style_widget/button.dart'; | 
					
						
							|  |  |  | import 'package:flowy_infra_ui/widget/spacing.dart'; | 
					
						
							|  |  |  | import 'package:flutter/material.dart'; | 
					
						
							| 
									
										
										
										
											2021-10-14 14:34:22 +08:00
										 |  |  | import 'package:flutter_bloc/flutter_bloc.dart'; | 
					
						
							| 
									
										
										
										
											2021-10-13 23:11:45 +08:00
										 |  |  | import 'package:styled_widget/styled_widget.dart'; | 
					
						
							| 
									
										
										
										
											2021-12-07 23:01:23 +05:30
										 |  |  | import 'package:app_flowy/generated/locale_keys.g.dart'; | 
					
						
							| 
									
										
										
										
											2021-10-13 23:11:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-01 16:05:45 +08:00
										 |  |  | import 'src/sizes.dart'; | 
					
						
							|  |  |  | import 'src/trash_cell.dart'; | 
					
						
							|  |  |  | import 'src/trash_header.dart'; | 
					
						
							| 
									
										
										
										
											2021-10-14 14:34:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-01 10:25:21 +08:00
										 |  |  | class TrashPluginBuilder extends PluginBuilder { | 
					
						
							| 
									
										
										
										
											2022-02-28 22:38:53 +08:00
										 |  |  |   @override | 
					
						
							|  |  |  |   Plugin build(dynamic data) { | 
					
						
							|  |  |  |     return TrashPlugin(pluginType: pluginType); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-10-13 23:11:45 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							| 
									
										
										
										
											2022-07-19 14:11:29 +08:00
										 |  |  |   String get menuName => "TrashPB"; | 
					
						
							| 
									
										
										
										
											2021-10-13 23:11:45 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							| 
									
										
										
										
											2022-08-18 19:32:08 +08:00
										 |  |  |   PluginType get pluginType => PluginType.trash; | 
					
						
							| 
									
										
										
										
											2022-02-28 22:38:53 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-01 11:22:39 +08:00
										 |  |  | class TrashPluginConfig implements PluginConfig { | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   bool get creatable => false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-01 16:05:45 +08:00
										 |  |  | class TrashPlugin extends Plugin { | 
					
						
							| 
									
										
										
										
											2022-03-01 10:25:21 +08:00
										 |  |  |   final PluginType _pluginType; | 
					
						
							| 
									
										
										
										
											2022-02-28 22:38:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-01 10:25:21 +08:00
										 |  |  |   TrashPlugin({required PluginType pluginType}) : _pluginType = pluginType; | 
					
						
							| 
									
										
										
										
											2021-11-09 23:13:04 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-13 23:11:45 +08:00
										 |  |  |   @override | 
					
						
							| 
									
										
										
										
											2022-03-02 11:38:22 +08:00
										 |  |  |   PluginDisplay get display => TrashPluginDisplay(); | 
					
						
							| 
									
										
										
										
											2021-10-13 23:11:45 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							| 
									
										
										
										
											2022-03-02 11:38:22 +08:00
										 |  |  |   PluginId get id => "TrashStack"; | 
					
						
							| 
									
										
										
										
											2021-10-13 23:11:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-28 21:55:22 +08:00
										 |  |  |   @override | 
					
						
							| 
									
										
										
										
											2022-03-02 11:38:22 +08:00
										 |  |  |   PluginType get ty => _pluginType; | 
					
						
							| 
									
										
										
										
											2022-02-28 22:38:53 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TrashPluginDisplay extends PluginDisplay { | 
					
						
							|  |  |  |   @override | 
					
						
							| 
									
										
										
										
											2022-08-09 10:35:27 +08:00
										 |  |  |   Widget get leftBarItem => | 
					
						
							|  |  |  |       FlowyText.medium(LocaleKeys.trash_text.tr(), fontSize: 12); | 
					
						
							| 
									
										
										
										
											2022-02-28 22:38:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   Widget? get rightBarItem => null; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							| 
									
										
										
										
											2022-03-04 08:22:49 +08:00
										 |  |  |   Widget buildWidget() => const TrashPage(key: ValueKey('TrashPage')); | 
					
						
							| 
									
										
										
										
											2022-02-28 22:38:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   List<NavigationItem> get navigationItems => [this]; | 
					
						
							| 
									
										
										
										
											2021-10-13 23:11:45 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-04 08:22:49 +08:00
										 |  |  | class TrashPage extends StatefulWidget { | 
					
						
							|  |  |  |   const TrashPage({Key? key}) : super(key: key); | 
					
						
							| 
									
										
										
										
											2021-10-13 23:11:45 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							| 
									
										
										
										
											2022-03-04 08:22:49 +08:00
										 |  |  |   State<TrashPage> createState() => _TrashPageState(); | 
					
						
							| 
									
										
										
										
											2021-10-13 23:11:45 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-04 08:22:49 +08:00
										 |  |  | class _TrashPageState extends State<TrashPage> { | 
					
						
							| 
									
										
										
										
											2021-10-14 18:11:59 +08:00
										 |  |  |   final ScrollController _scrollController = ScrollController(); | 
					
						
							| 
									
										
										
										
											2021-10-13 23:11:45 +08:00
										 |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							|  |  |  |     final theme = context.watch<AppTheme>(); | 
					
						
							| 
									
										
										
										
											2021-10-14 22:58:20 +08:00
										 |  |  |     const horizontalPadding = 80.0; | 
					
						
							| 
									
										
										
										
											2021-10-18 18:40:15 +08:00
										 |  |  |     return BlocProvider( | 
					
						
							|  |  |  |       create: (context) => getIt<TrashBloc>()..add(const TrashEvent.initial()), | 
					
						
							|  |  |  |       child: BlocBuilder<TrashBloc, TrashState>( | 
					
						
							|  |  |  |         builder: (context, state) { | 
					
						
							|  |  |  |           return SizedBox.expand( | 
					
						
							|  |  |  |             child: Column( | 
					
						
							| 
									
										
										
										
											2022-08-31 09:19:31 +08:00
										 |  |  |               mainAxisAlignment: MainAxisAlignment.start, | 
					
						
							| 
									
										
										
										
											2021-10-18 18:40:15 +08:00
										 |  |  |               children: [ | 
					
						
							|  |  |  |                 _renderTopBar(context, theme, state), | 
					
						
							|  |  |  |                 const VSpace(32), | 
					
						
							|  |  |  |                 _renderTrashList(context, state), | 
					
						
							|  |  |  |               ], | 
					
						
							|  |  |  |             ).padding(horizontal: horizontalPadding, vertical: 48), | 
					
						
							|  |  |  |           ); | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       ), | 
					
						
							| 
									
										
										
										
											2021-10-14 22:58:20 +08:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-18 18:40:15 +08:00
										 |  |  |   Widget _renderTrashList(BuildContext context, TrashState state) { | 
					
						
							| 
									
										
										
										
											2021-10-14 22:58:20 +08:00
										 |  |  |     const barSize = 6.0; | 
					
						
							|  |  |  |     return Expanded( | 
					
						
							|  |  |  |       child: ScrollbarListStack( | 
					
						
							|  |  |  |         axis: Axis.vertical, | 
					
						
							|  |  |  |         controller: _scrollController, | 
					
						
							|  |  |  |         scrollbarPadding: EdgeInsets.only(top: TrashSizes.headerHeight), | 
					
						
							|  |  |  |         barSize: barSize, | 
					
						
							|  |  |  |         child: StyledSingleChildScrollView( | 
					
						
							|  |  |  |           controller: ScrollController(), | 
					
						
							| 
									
										
										
										
											2021-10-28 15:22:18 +08:00
										 |  |  |           barSize: barSize, | 
					
						
							| 
									
										
										
										
											2021-10-14 22:58:20 +08:00
										 |  |  |           axis: Axis.horizontal, | 
					
						
							|  |  |  |           child: SizedBox( | 
					
						
							|  |  |  |             width: TrashSizes.totalWidth, | 
					
						
							| 
									
										
										
										
											2021-10-15 13:10:52 +08:00
										 |  |  |             child: ScrollConfiguration( | 
					
						
							|  |  |  |               behavior: const ScrollBehavior().copyWith(scrollbars: false), | 
					
						
							|  |  |  |               child: CustomScrollView( | 
					
						
							|  |  |  |                 shrinkWrap: true, | 
					
						
							|  |  |  |                 physics: StyledScrollPhysics(), | 
					
						
							|  |  |  |                 controller: _scrollController, | 
					
						
							|  |  |  |                 slivers: [ | 
					
						
							| 
									
										
										
										
											2021-10-18 18:40:15 +08:00
										 |  |  |                   _renderListHeader(context, state), | 
					
						
							|  |  |  |                   _renderListBody(context, state), | 
					
						
							| 
									
										
										
										
											2021-10-15 13:10:52 +08:00
										 |  |  |                 ], | 
					
						
							|  |  |  |               ), | 
					
						
							| 
									
										
										
										
											2021-10-14 14:34:22 +08:00
										 |  |  |             ), | 
					
						
							|  |  |  |           ), | 
					
						
							| 
									
										
										
										
											2021-10-14 22:58:20 +08:00
										 |  |  |         ), | 
					
						
							|  |  |  |       ), | 
					
						
							| 
									
										
										
										
											2021-10-13 23:11:45 +08:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-18 18:40:15 +08:00
										 |  |  |   Widget _renderTopBar(BuildContext context, AppTheme theme, TrashState state) { | 
					
						
							| 
									
										
										
										
											2021-10-13 23:11:45 +08:00
										 |  |  |     return SizedBox( | 
					
						
							|  |  |  |       height: 36, | 
					
						
							|  |  |  |       child: Row( | 
					
						
							|  |  |  |         children: [ | 
					
						
							| 
									
										
										
										
											2021-12-07 23:01:23 +05:30
										 |  |  |           FlowyText.semibold(LocaleKeys.trash_text.tr()), | 
					
						
							| 
									
										
										
										
											2021-10-13 23:11:45 +08:00
										 |  |  |           const Spacer(), | 
					
						
							|  |  |  |           SizedBox.fromSize( | 
					
						
							|  |  |  |             size: const Size(102, 30), | 
					
						
							|  |  |  |             child: FlowyButton( | 
					
						
							| 
									
										
										
										
											2022-08-09 10:35:27 +08:00
										 |  |  |               text: FlowyText.medium(LocaleKeys.trash_restoreAll.tr(), | 
					
						
							|  |  |  |                   fontSize: 12), | 
					
						
							| 
									
										
										
										
											2022-04-03 10:53:24 +08:00
										 |  |  |               leftIcon: svgWidget('editor/restore', color: theme.iconColor), | 
					
						
							| 
									
										
										
										
											2021-10-13 23:11:45 +08:00
										 |  |  |               hoverColor: theme.hover, | 
					
						
							| 
									
										
										
										
											2022-08-09 10:35:27 +08:00
										 |  |  |               onTap: () => | 
					
						
							|  |  |  |                   context.read<TrashBloc>().add(const TrashEvent.restoreAll()), | 
					
						
							| 
									
										
										
										
											2021-10-13 23:11:45 +08:00
										 |  |  |             ), | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |           const HSpace(6), | 
					
						
							|  |  |  |           SizedBox.fromSize( | 
					
						
							|  |  |  |             size: const Size(102, 30), | 
					
						
							|  |  |  |             child: FlowyButton( | 
					
						
							| 
									
										
										
										
											2022-08-09 10:35:27 +08:00
										 |  |  |               text: FlowyText.medium(LocaleKeys.trash_deleteAll.tr(), | 
					
						
							|  |  |  |                   fontSize: 12), | 
					
						
							| 
									
										
										
										
											2022-04-03 10:53:24 +08:00
										 |  |  |               leftIcon: svgWidget('editor/delete', color: theme.iconColor), | 
					
						
							| 
									
										
										
										
											2021-10-13 23:11:45 +08:00
										 |  |  |               hoverColor: theme.hover, | 
					
						
							| 
									
										
										
										
											2022-08-09 10:35:27 +08:00
										 |  |  |               onTap: () => | 
					
						
							|  |  |  |                   context.read<TrashBloc>().add(const TrashEvent.deleteAll()), | 
					
						
							| 
									
										
										
										
											2021-10-13 23:11:45 +08:00
										 |  |  |             ), | 
					
						
							|  |  |  |           ) | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-18 18:40:15 +08:00
										 |  |  |   Widget _renderListHeader(BuildContext context, TrashState state) { | 
					
						
							| 
									
										
										
										
											2021-10-14 14:34:22 +08:00
										 |  |  |     return SliverPersistentHeader( | 
					
						
							|  |  |  |       delegate: TrashHeaderDelegate(), | 
					
						
							| 
									
										
										
										
											2021-10-13 23:11:45 +08:00
										 |  |  |       floating: true, | 
					
						
							| 
									
										
										
										
											2021-10-14 14:34:22 +08:00
										 |  |  |       pinned: true, | 
					
						
							| 
									
										
										
										
											2021-10-13 23:11:45 +08:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-18 18:40:15 +08:00
										 |  |  |   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: () { | 
					
						
							|  |  |  |                 context.read<TrashBloc>().add(TrashEvent.putback(object.id)); | 
					
						
							| 
									
										
										
										
											2021-10-14 14:34:22 +08:00
										 |  |  |               }, | 
					
						
							| 
									
										
										
										
											2022-08-09 10:35:27 +08:00
										 |  |  |               onDelete: () => | 
					
						
							|  |  |  |                   context.read<TrashBloc>().add(TrashEvent.delete(object)), | 
					
						
							| 
									
										
										
										
											2021-10-13 23:11:45 +08:00
										 |  |  |             ), | 
					
						
							|  |  |  |           ); | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2021-10-18 18:40:15 +08:00
										 |  |  |         childCount: state.objects.length, | 
					
						
							|  |  |  |         addAutomaticKeepAlives: false, | 
					
						
							| 
									
										
										
										
											2021-10-13 23:11:45 +08:00
										 |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2021-10-15 13:10:52 +08:00
										 |  |  | // class TrashScrollbar extends ScrollBehavior {
 | 
					
						
							|  |  |  | //   @override
 | 
					
						
							|  |  |  | //   Widget buildScrollbar(BuildContext context, Widget child, ScrollableDetails details) {
 | 
					
						
							|  |  |  | //     return ScrollbarListStack(
 | 
					
						
							|  |  |  | //       controller: details.controller,
 | 
					
						
							|  |  |  | //       axis: Axis.vertical,
 | 
					
						
							|  |  |  | //       barSize: 6,
 | 
					
						
							|  |  |  | //       child: child,
 | 
					
						
							|  |  |  | //     );
 | 
					
						
							|  |  |  | //   }
 | 
					
						
							|  |  |  | // }
 |