|
| 1 | +import 'package:app_flowy/generated/locale_keys.g.dart'; |
| 2 | +import 'package:app_flowy/startup/plugin/plugin.dart'; |
| 3 | +import 'package:app_flowy/workspace/presentation/home/home_stack.dart'; |
| 4 | +import 'package:app_flowy/workspace/presentation/widgets/left_bar_item.dart'; |
| 5 | +import 'package:easy_localization/easy_localization.dart'; |
| 6 | +import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart'; |
| 7 | +import 'package:flutter/material.dart'; |
| 8 | + |
| 9 | +import '../util.dart'; |
| 10 | + |
| 11 | +class CalendarPluginBuilder extends PluginBuilder { |
| 12 | + @override |
| 13 | + Plugin build(dynamic data) { |
| 14 | + if (data is ViewPB) { |
| 15 | + return CalendarPlugin(pluginType: pluginType, view: data); |
| 16 | + } else { |
| 17 | + throw FlowyPluginException.invalidData; |
| 18 | + } |
| 19 | + } |
| 20 | + |
| 21 | + @override |
| 22 | + String get menuName => LocaleKeys.calendar_menuName.tr(); |
| 23 | + |
| 24 | + @override |
| 25 | + String get menuIcon => "editor/date"; |
| 26 | + |
| 27 | + @override |
| 28 | + PluginType get pluginType => PluginType.calendar; |
| 29 | + |
| 30 | + @override |
| 31 | + ViewDataFormatPB get dataFormatType => ViewDataFormatPB.DatabaseFormat; |
| 32 | + |
| 33 | + @override |
| 34 | + ViewLayoutTypePB? get layoutType => ViewLayoutTypePB.Calendar; |
| 35 | +} |
| 36 | + |
| 37 | +class CalendarPluginConfig implements PluginConfig { |
| 38 | + @override |
| 39 | + bool get creatable => false; |
| 40 | +} |
| 41 | + |
| 42 | +class CalendarPlugin extends Plugin { |
| 43 | + @override |
| 44 | + final ViewPluginNotifier notifier; |
| 45 | + final PluginType _pluginType; |
| 46 | + |
| 47 | + CalendarPlugin({ |
| 48 | + required ViewPB view, |
| 49 | + required PluginType pluginType, |
| 50 | + }) : _pluginType = pluginType, |
| 51 | + notifier = ViewPluginNotifier(view: view); |
| 52 | + |
| 53 | + @override |
| 54 | + PluginDisplay get display => CalendarPluginDisplay(notifier: notifier); |
| 55 | + |
| 56 | + @override |
| 57 | + PluginId get id => notifier.view.id; |
| 58 | + |
| 59 | + @override |
| 60 | + PluginType get ty => _pluginType; |
| 61 | +} |
| 62 | + |
| 63 | +class CalendarPluginDisplay extends PluginDisplay { |
| 64 | + final ViewPluginNotifier notifier; |
| 65 | + CalendarPluginDisplay({required this.notifier, Key? key}); |
| 66 | + |
| 67 | + ViewPB get view => notifier.view; |
| 68 | + |
| 69 | + @override |
| 70 | + Widget get leftBarItem => ViewLeftBarItem(view: view); |
| 71 | + |
| 72 | + @override |
| 73 | + Widget buildWidget(PluginContext context) { |
| 74 | + notifier.isDeleted.addListener(() { |
| 75 | + notifier.isDeleted.value.fold(() => null, (deletedView) { |
| 76 | + if (deletedView.hasIndex()) { |
| 77 | + context.onDeleted(view, deletedView.index); |
| 78 | + } |
| 79 | + }); |
| 80 | + }); |
| 81 | + |
| 82 | + return BlankPage(key: ValueKey(view.id)); |
| 83 | + // return BoardPage(key: ValueKey(view.id), view: view); |
| 84 | + } |
| 85 | + |
| 86 | + @override |
| 87 | + List<NavigationItem> get navigationItems => [this]; |
| 88 | +} |
| 89 | + |
| 90 | +// mark for removal |
| 91 | +class BlankPage extends StatefulWidget { |
| 92 | + const BlankPage({Key? key}) : super(key: key); |
| 93 | + |
| 94 | + @override |
| 95 | + State<BlankPage> createState() => _BlankPageState(); |
| 96 | +} |
| 97 | + |
| 98 | +class _BlankPageState extends State<BlankPage> { |
| 99 | + @override |
| 100 | + Widget build(BuildContext context) { |
| 101 | + return SizedBox.expand( |
| 102 | + child: Container( |
| 103 | + color: Theme.of(context).colorScheme.surface, |
| 104 | + child: Padding( |
| 105 | + padding: const EdgeInsets.all(10), |
| 106 | + child: Container(), |
| 107 | + ), |
| 108 | + ), |
| 109 | + ); |
| 110 | + } |
| 111 | +} |
0 commit comments