trash.dart 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. export "./src/sizes.dart";
  2. export "./src/trash_cell.dart";
  3. export "./src/trash_header.dart";
  4. import 'package:app_flowy/startup/plugin/plugin.dart';
  5. import 'package:app_flowy/startup/startup.dart';
  6. import 'package:app_flowy/plugins/trash/application/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 => "TrashPB";
  31. @override
  32. PluginType get pluginType => PluginType.trash;
  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 =>
  51. FlowyText.medium(LocaleKeys.trash_text.tr(), fontSize: 12);
  52. @override
  53. Widget? get rightBarItem => null;
  54. @override
  55. Widget buildWidget(PluginContext context) => const TrashPage(
  56. key: ValueKey('TrashPage'),
  57. );
  58. @override
  59. List<NavigationItem> get navigationItems => [this];
  60. }
  61. class TrashPage extends StatefulWidget {
  62. const TrashPage({Key? key}) : super(key: key);
  63. @override
  64. State<TrashPage> createState() => _TrashPageState();
  65. }
  66. class _TrashPageState extends State<TrashPage> {
  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. mainAxisAlignment: MainAxisAlignment.start,
  79. children: [
  80. _renderTopBar(context, theme, state),
  81. const VSpace(32),
  82. _renderTrashList(context, state),
  83. ],
  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. crossAxisAlignment: CrossAxisAlignment.stretch,
  126. children: [
  127. FlowyText.semibold(LocaleKeys.trash_text.tr()),
  128. const Spacer(),
  129. IntrinsicWidth(
  130. child: FlowyButton(
  131. text: FlowyText.medium(LocaleKeys.trash_restoreAll.tr(),
  132. fontSize: 12),
  133. leftIcon: svgWidget('editor/restore', color: theme.iconColor),
  134. hoverColor: theme.hover,
  135. onTap: () => context.read<TrashBloc>().add(
  136. const TrashEvent.restoreAll(),
  137. ),
  138. ),
  139. ),
  140. const HSpace(6),
  141. IntrinsicWidth(
  142. child: FlowyButton(
  143. text: FlowyText.medium(LocaleKeys.trash_deleteAll.tr(),
  144. fontSize: 12),
  145. leftIcon: svgWidget('editor/delete', color: theme.iconColor),
  146. hoverColor: theme.hover,
  147. onTap: () =>
  148. context.read<TrashBloc>().add(const TrashEvent.deleteAll()),
  149. ),
  150. )
  151. ],
  152. ),
  153. );
  154. }
  155. Widget _renderListHeader(BuildContext context, TrashState state) {
  156. return SliverPersistentHeader(
  157. delegate: TrashHeaderDelegate(),
  158. floating: true,
  159. pinned: true,
  160. );
  161. }
  162. Widget _renderListBody(BuildContext context, TrashState state) {
  163. return SliverList(
  164. delegate: SliverChildBuilderDelegate(
  165. (BuildContext context, int index) {
  166. final object = state.objects[index];
  167. return SizedBox(
  168. height: 42,
  169. child: TrashCell(
  170. object: object,
  171. onRestore: () {
  172. context.read<TrashBloc>().add(TrashEvent.putback(object.id));
  173. },
  174. onDelete: () =>
  175. context.read<TrashBloc>().add(TrashEvent.delete(object)),
  176. ),
  177. );
  178. },
  179. childCount: state.objects.length,
  180. addAutomaticKeepAlives: false,
  181. ),
  182. );
  183. }
  184. }
  185. // class TrashScrollbar extends ScrollBehavior {
  186. // @override
  187. // Widget buildScrollbar(BuildContext context, Widget child, ScrollableDetails details) {
  188. // return ScrollbarListStack(
  189. // controller: details.controller,
  190. // axis: Axis.vertical,
  191. // barSize: 6,
  192. // child: child,
  193. // );
  194. // }
  195. // }