board.dart 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import 'package:app_flowy/plugins/util.dart';
  2. import 'package:app_flowy/workspace/presentation/home/home_stack.dart';
  3. import 'package:app_flowy/workspace/presentation/widgets/left_bar_item.dart';
  4. import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart';
  5. import 'package:app_flowy/startup/plugin/plugin.dart';
  6. import 'package:flutter/material.dart';
  7. import 'presentation/board_page.dart';
  8. class BoardPluginBuilder implements PluginBuilder {
  9. @override
  10. Plugin build(dynamic data) {
  11. if (data is ViewPB) {
  12. return BoardPlugin(pluginType: pluginType, view: data);
  13. } else {
  14. throw FlowyPluginException.invalidData;
  15. }
  16. }
  17. @override
  18. String get menuName => "Board";
  19. @override
  20. String get menuIcon => "editor/board";
  21. @override
  22. PluginType get pluginType => PluginType.board;
  23. @override
  24. ViewDataFormatPB get dataFormatType => ViewDataFormatPB.DatabaseFormat;
  25. @override
  26. ViewLayoutTypePB? get layoutType => ViewLayoutTypePB.Board;
  27. }
  28. class BoardPluginConfig implements PluginConfig {
  29. @override
  30. bool get creatable => true;
  31. }
  32. class BoardPlugin extends Plugin {
  33. @override
  34. final ViewPluginNotifier notifier;
  35. final PluginType _pluginType;
  36. BoardPlugin({
  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. GridPluginDisplay({required this.notifier, Key? key});
  51. ViewPB get view => notifier.view;
  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 BoardPage(key: ValueKey(view.id), view: view);
  64. }
  65. @override
  66. List<NavigationItem> get navigationItems => [this];
  67. }