grid.dart 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import 'package:app_flowy/generated/locale_keys.g.dart';
  2. import 'package:app_flowy/plugins/util.dart';
  3. import 'package:app_flowy/startup/plugin/plugin.dart';
  4. import 'package:app_flowy/workspace/presentation/home/home_stack.dart';
  5. import 'package:app_flowy/workspace/presentation/widgets/left_bar_item.dart';
  6. import 'package:easy_localization/easy_localization.dart';
  7. import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart';
  8. import 'package:flutter/material.dart';
  9. import 'presentation/grid_page.dart';
  10. class GridPluginBuilder implements PluginBuilder {
  11. @override
  12. Plugin build(dynamic data) {
  13. if (data is ViewPB) {
  14. return GridPlugin(pluginType: pluginType, view: data);
  15. } else {
  16. throw FlowyPluginException.invalidData;
  17. }
  18. }
  19. @override
  20. String get menuName => LocaleKeys.grid_menuName.tr();
  21. @override
  22. String get menuIcon => "editor/grid";
  23. @override
  24. PluginType get pluginType => PluginType.grid;
  25. @override
  26. ViewDataFormatPB get dataFormatType => ViewDataFormatPB.DatabaseFormat;
  27. @override
  28. ViewLayoutTypePB? get layoutType => ViewLayoutTypePB.Grid;
  29. }
  30. class GridPluginConfig implements PluginConfig {
  31. @override
  32. bool get creatable => true;
  33. }
  34. class GridPlugin extends Plugin {
  35. @override
  36. final ViewPluginNotifier notifier;
  37. final PluginType _pluginType;
  38. GridPlugin({
  39. required ViewPB view,
  40. required PluginType pluginType,
  41. }) : _pluginType = pluginType,
  42. notifier = ViewPluginNotifier(view: view);
  43. @override
  44. PluginDisplay get display => GridPluginDisplay(notifier: notifier);
  45. @override
  46. PluginId get id => notifier.view.id;
  47. @override
  48. PluginType get ty => _pluginType;
  49. }
  50. class GridPluginDisplay extends PluginDisplay {
  51. final ViewPluginNotifier notifier;
  52. ViewPB get view => notifier.view;
  53. GridPluginDisplay({required this.notifier, Key? key});
  54. @override
  55. Widget get leftBarItem => ViewLeftBarItem(view: view);
  56. @override
  57. Widget buildWidget(PluginContext context) {
  58. notifier.isDeleted.addListener(() {
  59. notifier.isDeleted.value.fold(() => null, (deletedView) {
  60. if (deletedView.hasIndex()) {
  61. context.onDeleted(view, deletedView.index);
  62. }
  63. });
  64. });
  65. return GridPage(key: ValueKey(view.id), view: view);
  66. }
  67. @override
  68. List<NavigationItem> get navigationItems => [this];
  69. }