trash.dart 6.4 KB

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