grid.dart 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. PluginType get pluginType => PluginType.grid;
  23. @override
  24. ViewDataTypePB get dataType => ViewDataTypePB.Database;
  25. @override
  26. ViewLayoutTypePB? get layoutType => ViewLayoutTypePB.Grid;
  27. }
  28. class GridPluginConfig implements PluginConfig {
  29. @override
  30. bool get creatable => true;
  31. }
  32. class GridPlugin extends Plugin {
  33. @override
  34. final ViewPluginNotifier notifier;
  35. final PluginType _pluginType;
  36. GridPlugin({
  37. required ViewPB view,
  38. required PluginType pluginType,
  39. }) : _pluginType = pluginType,
  40. notifier = ViewPluginNotifier(view: view);
  41. @override
  42. PluginDisplay get display => GridPluginDisplay(notifier: notifier);
  43. @override
  44. PluginId get id => notifier.view.id;
  45. @override
  46. PluginType get ty => _pluginType;
  47. }
  48. class GridPluginDisplay extends PluginDisplay {
  49. final ViewPluginNotifier notifier;
  50. ViewPB get view => notifier.view;
  51. GridPluginDisplay({required this.notifier, Key? key});
  52. @override
  53. Widget get leftBarItem => ViewLeftBarItem(view: view);
  54. @override
  55. Widget buildWidget(PluginContext context) {
  56. notifier.isDeleted.addListener(() {
  57. notifier.isDeleted.value.fold(() => null, (deletedView) {
  58. if (deletedView.hasIndex()) {
  59. context.onDeleted(view, deletedView.index);
  60. }
  61. });
  62. });
  63. return GridPage(key: ValueKey(view.id), view: view);
  64. }
  65. @override
  66. List<NavigationItem> get navigationItems => [this];
  67. }