grid.dart 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 subDataType => 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. if (notifier.isDeleted.value) {
  58. context.onDeleted(view);
  59. }
  60. });
  61. return GridPage(key: ValueKey(view.id), view: view);
  62. }
  63. @override
  64. List<NavigationItem> get navigationItems => [this];
  65. }