11library document_plugin;
22
33import 'package:app_flowy/generated/locale_keys.g.dart' ;
4+ import 'package:app_flowy/plugins/util.dart' ;
45import 'package:app_flowy/startup/plugin/plugin.dart' ;
56import 'package:app_flowy/startup/startup.dart' ;
67import 'package:app_flowy/workspace/application/appearance.dart' ;
7- import 'package:app_flowy/workspace/application/view/view_listener.dart' ;
88import 'package:app_flowy/plugins/doc/application/share_bloc.dart' ;
99import 'package:app_flowy/workspace/presentation/home/home_stack.dart' ;
1010import 'package:app_flowy/workspace/presentation/home/toast.dart' ;
@@ -14,7 +14,6 @@ import 'package:app_flowy/workspace/presentation/widgets/pop_up_action.dart';
1414import 'package:clipboard/clipboard.dart' ;
1515import 'package:dartz/dartz.dart' as dartz;
1616import 'package:easy_localization/easy_localization.dart' ;
17- import 'package:flowy_infra/notifier.dart' ;
1817import 'package:flowy_infra/size.dart' ;
1918import 'package:flowy_infra_ui/flowy_infra_ui.dart' ;
2019import 'package:flowy_infra_ui/widget/rounded_button.dart' ;
@@ -48,63 +47,51 @@ class DocumentPluginBuilder extends PluginBuilder {
4847 ViewDataTypePB get dataType => ViewDataTypePB .Text ;
4948}
5049
51- class DocumentPlugin implements Plugin {
52- late ViewPB _view;
53- ViewListener ? _listener;
50+ class DocumentPlugin extends Plugin <int > {
5451 late PluginType _pluginType;
5552
56- DocumentPlugin (
57- {required PluginType pluginType, required ViewPB view, Key ? key})
58- : _view = view {
59- _pluginType = pluginType;
60- _listener = getIt <ViewListener >(param1: view);
61- _listener? .start (onViewUpdated: (result) {
62- result.fold (
63- (newView) {
64- _view = newView;
65- display.notifier! .value = _view.hashCode;
66- },
67- (error) {},
68- );
69- });
70- }
71-
7253 @override
73- void dispose () {
74- _listener? .stop ();
75- _listener = null ;
54+ final ViewPluginNotifier notifier;
55+
56+ DocumentPlugin ({
57+ required PluginType pluginType,
58+ required ViewPB view,
59+ Key ? key,
60+ }) : notifier = ViewPluginNotifier (view: view) {
61+ _pluginType = pluginType;
7662 }
7763
7864 @override
79- PluginDisplay < int > get display => DocumentPluginDisplay (view : _view );
65+ PluginDisplay get display => DocumentPluginDisplay (notifier : notifier );
8066
8167 @override
8268 PluginType get ty => _pluginType;
8369
8470 @override
85- PluginId get id => _view .id;
71+ PluginId get id => notifier.view .id;
8672}
8773
88- class DocumentPluginDisplay extends PluginDisplay < int > with NavigationItem {
89- final PublishNotifier < int > _displayNotifier = PublishNotifier < int >() ;
90- final ViewPB _view ;
74+ class DocumentPluginDisplay extends PluginDisplay with NavigationItem {
75+ final ViewPluginNotifier notifier ;
76+ ViewPB get view => notifier.view ;
9177
92- DocumentPluginDisplay ({required ViewPB view , Key ? key}) : _view = view ;
78+ DocumentPluginDisplay ({required this .notifier , Key ? key});
9379
9480 @override
95- Widget buildWidget () => DocumentPage (view: _view, key: ValueKey (_view.id));
81+ Widget buildWidget (PluginContext context) => DocumentPage (
82+ view: view,
83+ onDeleted: () => context.onDeleted (view),
84+ key: ValueKey (view.id),
85+ );
9686
9787 @override
98- Widget get leftBarItem => ViewLeftBarItem (view: _view );
88+ Widget get leftBarItem => ViewLeftBarItem (view: view );
9989
10090 @override
101- Widget ? get rightBarItem => DocumentShareButton (view: _view );
91+ Widget ? get rightBarItem => DocumentShareButton (view: view );
10292
10393 @override
10494 List <NavigationItem > get navigationItems => [this ];
105-
106- @override
107- PublishNotifier <int >? get notifier => _displayNotifier;
10895}
10996
11097class DocumentShareButton extends StatelessWidget {
0 commit comments