board.dart 2.1 KB

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