trash.dart 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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() => const TrashPage(key: ValueKey('TrashPage'));
  56. @override
  57. List<NavigationItem> get navigationItems => [this];
  58. }
  59. class TrashPage extends StatefulWidget {
  60. const TrashPage({Key? key}) : super(key: key);
  61. @override
  62. State<TrashPage> createState() => _TrashPageState();
  63. }
  64. class _TrashPageState extends State<TrashPage> {
  65. final ScrollController _scrollController = ScrollController();
  66. @override
  67. Widget build(BuildContext context) {
  68. final theme = context.watch<AppTheme>();
  69. const horizontalPadding = 80.0;
  70. return BlocProvider(
  71. create: (context) => getIt<TrashBloc>()..add(const TrashEvent.initial()),
  72. child: BlocBuilder<TrashBloc, TrashState>(
  73. builder: (context, state) {
  74. return SizedBox.expand(
  75. child: Column(
  76. children: [
  77. _renderTopBar(context, theme, state),
  78. const VSpace(32),
  79. _renderTrashList(context, state),
  80. ],
  81. mainAxisAlignment: MainAxisAlignment.start,
  82. ).padding(horizontal: horizontalPadding, vertical: 48),
  83. );
  84. },
  85. ),
  86. );
  87. }
  88. Widget _renderTrashList(BuildContext context, TrashState state) {
  89. const barSize = 6.0;
  90. return Expanded(
  91. child: ScrollbarListStack(
  92. axis: Axis.vertical,
  93. controller: _scrollController,
  94. scrollbarPadding: EdgeInsets.only(top: TrashSizes.headerHeight),
  95. barSize: barSize,
  96. child: StyledSingleChildScrollView(
  97. controller: ScrollController(),
  98. barSize: barSize,
  99. axis: Axis.horizontal,
  100. child: SizedBox(
  101. width: TrashSizes.totalWidth,
  102. child: ScrollConfiguration(
  103. behavior: const ScrollBehavior().copyWith(scrollbars: false),
  104. child: CustomScrollView(
  105. shrinkWrap: true,
  106. physics: StyledScrollPhysics(),
  107. controller: _scrollController,
  108. slivers: [
  109. _renderListHeader(context, state),
  110. _renderListBody(context, state),
  111. ],
  112. ),
  113. ),
  114. ),
  115. ),
  116. ),
  117. );
  118. }
  119. Widget _renderTopBar(BuildContext context, AppTheme theme, TrashState state) {
  120. return SizedBox(
  121. height: 36,
  122. child: Row(
  123. children: [
  124. FlowyText.semibold(LocaleKeys.trash_text.tr()),
  125. const Spacer(),
  126. SizedBox.fromSize(
  127. size: const Size(102, 30),
  128. child: FlowyButton(
  129. text: FlowyText.medium(LocaleKeys.trash_restoreAll.tr(),
  130. fontSize: 12),
  131. leftIcon: svgWidget('editor/restore', color: theme.iconColor),
  132. hoverColor: theme.hover,
  133. onTap: () =>
  134. 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(),
  142. fontSize: 12),
  143. leftIcon: svgWidget('editor/delete', color: theme.iconColor),
  144. hoverColor: theme.hover,
  145. onTap: () =>
  146. context.read<TrashBloc>().add(const TrashEvent.deleteAll()),
  147. ),
  148. )
  149. ],
  150. ),
  151. );
  152. }
  153. Widget _renderListHeader(BuildContext context, TrashState state) {
  154. return SliverPersistentHeader(
  155. delegate: TrashHeaderDelegate(),
  156. floating: true,
  157. pinned: true,
  158. );
  159. }
  160. Widget _renderListBody(BuildContext context, TrashState state) {
  161. return SliverList(
  162. delegate: SliverChildBuilderDelegate(
  163. (BuildContext context, int index) {
  164. final object = state.objects[index];
  165. return SizedBox(
  166. height: 42,
  167. child: TrashCell(
  168. object: object,
  169. onRestore: () {
  170. context.read<TrashBloc>().add(TrashEvent.putback(object.id));
  171. },
  172. onDelete: () =>
  173. context.read<TrashBloc>().add(TrashEvent.delete(object)),
  174. ),
  175. );
  176. },
  177. childCount: state.objects.length,
  178. addAutomaticKeepAlives: false,
  179. ),
  180. );
  181. }
  182. }
  183. // class TrashScrollbar extends ScrollBehavior {
  184. // @override
  185. // Widget buildScrollbar(BuildContext context, Widget child, ScrollableDetails details) {
  186. // return ScrollbarListStack(
  187. // controller: details.controller,
  188. // axis: Axis.vertical,
  189. // barSize: 6,
  190. // child: child,
  191. // );
  192. // }
  193. // }