view_ext.dart 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import 'package:appflowy/plugins/database_view/database_view.dart';
  2. import 'package:appflowy/startup/plugin/plugin.dart';
  3. import 'package:flowy_infra/image.dart';
  4. import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
  5. import 'package:flutter/material.dart';
  6. enum FlowyPlugin {
  7. editor,
  8. kanban,
  9. }
  10. extension FlowyPluginExtension on FlowyPlugin {
  11. String displayName() {
  12. switch (this) {
  13. case FlowyPlugin.editor:
  14. return "Doc";
  15. case FlowyPlugin.kanban:
  16. return "Kanban";
  17. default:
  18. return "";
  19. }
  20. }
  21. bool enable() {
  22. switch (this) {
  23. case FlowyPlugin.editor:
  24. return true;
  25. case FlowyPlugin.kanban:
  26. return false;
  27. default:
  28. return false;
  29. }
  30. }
  31. }
  32. extension ViewExtension on ViewPB {
  33. Widget renderThumbnail({Color? iconColor}) {
  34. String thumbnail = "file_icon";
  35. final Widget widget = FlowySvg(name: thumbnail);
  36. return widget;
  37. }
  38. PluginType get pluginType {
  39. switch (layout) {
  40. case ViewLayoutPB.Board:
  41. return PluginType.board;
  42. case ViewLayoutPB.Calendar:
  43. return PluginType.calendar;
  44. case ViewLayoutPB.Document:
  45. return PluginType.editor;
  46. case ViewLayoutPB.Grid:
  47. return PluginType.grid;
  48. }
  49. throw UnimplementedError;
  50. }
  51. Plugin plugin() {
  52. switch (layout) {
  53. case ViewLayoutPB.Board:
  54. case ViewLayoutPB.Calendar:
  55. case ViewLayoutPB.Grid:
  56. return DatabaseViewPlugin(view: this);
  57. case ViewLayoutPB.Document:
  58. return makePlugin(pluginType: pluginType, data: this);
  59. }
  60. throw UnimplementedError;
  61. }
  62. }