trash.dart 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. export "./src/sizes.dart";
  2. export "./src/trash_cell.dart";
  3. export "./src/trash_header.dart";
  4. import 'package:app_flowy/plugin/plugin.dart';
  5. import 'package:app_flowy/startup/startup.dart';
  6. import 'package:app_flowy/startup/tasks/load_plugin.dart';
  7. import 'package:app_flowy/workspace/application/trash/trash_bloc.dart';
  8. import 'package:app_flowy/workspace/presentation/home/home_stack.dart';
  9. import 'package:easy_localization/easy_localization.dart';
  10. import 'package:flowy_infra/image.dart';
  11. import 'package:flowy_infra/theme.dart';
  12. import 'package:flowy_infra_ui/style_widget/scrolling/styled_list.dart';
  13. import 'package:flowy_infra_ui/style_widget/scrolling/styled_scroll_bar.dart';
  14. import 'package:flowy_infra_ui/style_widget/scrolling/styled_scrollview.dart';
  15. import 'package:flowy_infra_ui/style_widget/text.dart';
  16. import 'package:flowy_infra_ui/style_widget/button.dart';
  17. import 'package:flowy_infra_ui/widget/spacing.dart';
  18. import 'package:flutter/material.dart';
  19. import 'package:flutter_bloc/flutter_bloc.dart';
  20. import 'package:styled_widget/styled_widget.dart';
  21. import 'package:app_flowy/generated/locale_keys.g.dart';
  22. import 'src/sizes.dart';
  23. import 'src/trash_cell.dart';
  24. import 'src/trash_header.dart';
  25. class TrashPluginBuilder extends PluginBuilder {
  26. @override
  27. Plugin build(dynamic data) {
  28. return TrashPlugin(pluginType: pluginType);
  29. }
  30. @override
  31. String get menuName => "Trash";
  32. @override
  33. PluginType get pluginType => DefaultPlugin.trash.type();
  34. }
  35. class TrashPluginConfig implements PluginConfig {
  36. @override
  37. bool get creatable => false;
  38. }
  39. class TrashPlugin extends Plugin {
  40. final PluginType _pluginType;
  41. TrashPlugin({required PluginType pluginType}) : _pluginType = pluginType;
  42. @override
  43. void dispose() {}
  44. @override
  45. PluginDisplay get pluginDisplay => TrashPluginDisplay();
  46. @override
  47. PluginId get pluginId => "TrashStack";
  48. @override
  49. PluginType get pluginType => _pluginType;
  50. }
  51. class TrashPluginDisplay extends PluginDisplay {
  52. @override
  53. Widget get leftBarItem => FlowyText.medium(LocaleKeys.trash_text.tr(), fontSize: 12);
  54. @override
  55. Widget? get rightBarItem => null;
  56. @override
  57. Widget buildWidget() => const TrashStackPage(key: ValueKey('TrashStackPage'));
  58. @override
  59. List<NavigationItem> get navigationItems => [this];
  60. }
  61. class TrashStackPage extends StatefulWidget {
  62. const TrashStackPage({Key? key}) : super(key: key);
  63. @override
  64. State<TrashStackPage> createState() => _TrashStackPageState();
  65. }
  66. class _TrashStackPageState extends State<TrashStackPage> {
  67. final ScrollController _scrollController = ScrollController();
  68. @override
  69. Widget build(BuildContext context) {
  70. final theme = context.watch<AppTheme>();
  71. const horizontalPadding = 80.0;
  72. return BlocProvider(
  73. create: (context) => getIt<TrashBloc>()..add(const TrashEvent.initial()),
  74. child: BlocBuilder<TrashBloc, TrashState>(
  75. builder: (context, state) {
  76. return SizedBox.expand(
  77. child: Column(
  78. children: [
  79. _renderTopBar(context, theme, state),
  80. const VSpace(32),
  81. _renderTrashList(context, state),
  82. ],
  83. mainAxisAlignment: MainAxisAlignment.start,
  84. ).padding(horizontal: horizontalPadding, vertical: 48),
  85. );
  86. },
  87. ),
  88. );
  89. }
  90. Widget _renderTrashList(BuildContext context, TrashState state) {
  91. const barSize = 6.0;
  92. return Expanded(
  93. child: ScrollbarListStack(
  94. axis: Axis.vertical,
  95. controller: _scrollController,
  96. scrollbarPadding: EdgeInsets.only(top: TrashSizes.headerHeight),
  97. barSize: barSize,
  98. child: StyledSingleChildScrollView(
  99. controller: ScrollController(),
  100. barSize: barSize,
  101. axis: Axis.horizontal,
  102. child: SizedBox(
  103. width: TrashSizes.totalWidth,
  104. child: ScrollConfiguration(
  105. behavior: const ScrollBehavior().copyWith(scrollbars: false),
  106. child: CustomScrollView(
  107. shrinkWrap: true,
  108. physics: StyledScrollPhysics(),
  109. controller: _scrollController,
  110. slivers: [
  111. _renderListHeader(context, state),
  112. _renderListBody(context, state),
  113. ],
  114. ),
  115. ),
  116. ),
  117. ),
  118. ),
  119. );
  120. }
  121. Widget _renderTopBar(BuildContext context, AppTheme theme, TrashState state) {
  122. return SizedBox(
  123. height: 36,
  124. child: Row(
  125. children: [
  126. FlowyText.semibold(LocaleKeys.trash_text.tr()),
  127. const Spacer(),
  128. SizedBox.fromSize(
  129. size: const Size(102, 30),
  130. child: FlowyButton(
  131. text: FlowyText.medium(LocaleKeys.trash_restoreAll.tr(), fontSize: 12),
  132. icon: svg('editor/restore', color: theme.iconColor),
  133. hoverColor: theme.hover,
  134. onTap: () => context.read<TrashBloc>().add(const TrashEvent.restoreAll()),
  135. ),
  136. ),
  137. const HSpace(6),
  138. SizedBox.fromSize(
  139. size: const Size(102, 30),
  140. child: FlowyButton(
  141. text: FlowyText.medium(LocaleKeys.trash_deleteAll.tr(), fontSize: 12),
  142. icon: svg('editor/delete', color: theme.iconColor),
  143. hoverColor: theme.hover,
  144. onTap: () => context.read<TrashBloc>().add(const TrashEvent.deleteAll()),
  145. ),
  146. )
  147. ],
  148. ),
  149. );
  150. }
  151. Widget _renderListHeader(BuildContext context, TrashState state) {
  152. return SliverPersistentHeader(
  153. delegate: TrashHeaderDelegate(),
  154. floating: true,
  155. pinned: true,
  156. );
  157. }
  158. Widget _renderListBody(BuildContext context, TrashState state) {
  159. return SliverList(
  160. delegate: SliverChildBuilderDelegate(
  161. (BuildContext context, int index) {
  162. final object = state.objects[index];
  163. return SizedBox(
  164. height: 42,
  165. child: TrashCell(
  166. object: object,
  167. onRestore: () {
  168. context.read<TrashBloc>().add(TrashEvent.putback(object.id));
  169. },
  170. onDelete: () => context.read<TrashBloc>().add(TrashEvent.delete(object)),
  171. ),
  172. );
  173. },
  174. childCount: state.objects.length,
  175. addAutomaticKeepAlives: false,
  176. ),
  177. );
  178. }
  179. }
  180. // class TrashScrollbar extends ScrollBehavior {
  181. // @override
  182. // Widget buildScrollbar(BuildContext context, Widget child, ScrollableDetails details) {
  183. // return ScrollbarListStack(
  184. // controller: details.controller,
  185. // axis: Axis.vertical,
  186. // barSize: 6,
  187. // child: child,
  188. // );
  189. // }
  190. // }