chore: open next page when current page get deleted

This commit is contained in:
appflowy
2022-09-22 13:08:48 +08:00
parent bdf4e60b48
commit 37f85cebde
25 changed files with 312 additions and 178 deletions

View File

@ -1,10 +1,10 @@
library document_plugin;
import 'package:app_flowy/generated/locale_keys.g.dart';
import 'package:app_flowy/plugins/util.dart';
import 'package:app_flowy/startup/plugin/plugin.dart';
import 'package:app_flowy/startup/startup.dart';
import 'package:app_flowy/workspace/application/appearance.dart';
import 'package:app_flowy/workspace/application/view/view_listener.dart';
import 'package:app_flowy/plugins/doc/application/share_bloc.dart';
import 'package:app_flowy/workspace/presentation/home/home_stack.dart';
import 'package:app_flowy/workspace/presentation/home/toast.dart';
@ -14,7 +14,6 @@ import 'package:app_flowy/workspace/presentation/widgets/pop_up_action.dart';
import 'package:clipboard/clipboard.dart';
import 'package:dartz/dartz.dart' as dartz;
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/notifier.dart';
import 'package:flowy_infra/size.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/widget/rounded_button.dart';
@ -48,63 +47,51 @@ class DocumentPluginBuilder extends PluginBuilder {
ViewDataTypePB get dataType => ViewDataTypePB.Text;
}
class DocumentPlugin implements Plugin {
late ViewPB _view;
ViewListener? _listener;
class DocumentPlugin extends Plugin<int> {
late PluginType _pluginType;
DocumentPlugin(
{required PluginType pluginType, required ViewPB view, Key? key})
: _view = view {
@override
final ViewPluginNotifier notifier;
DocumentPlugin({
required PluginType pluginType,
required ViewPB view,
Key? key,
}) : notifier = ViewPluginNotifier(view: view) {
_pluginType = pluginType;
_listener = getIt<ViewListener>(param1: view);
_listener?.start(onViewUpdated: (result) {
result.fold(
(newView) {
_view = newView;
display.notifier!.value = _view.hashCode;
},
(error) {},
);
});
}
@override
void dispose() {
_listener?.stop();
_listener = null;
}
@override
PluginDisplay<int> get display => DocumentPluginDisplay(view: _view);
PluginDisplay get display => DocumentPluginDisplay(notifier: notifier);
@override
PluginType get ty => _pluginType;
@override
PluginId get id => _view.id;
PluginId get id => notifier.view.id;
}
class DocumentPluginDisplay extends PluginDisplay<int> with NavigationItem {
final PublishNotifier<int> _displayNotifier = PublishNotifier<int>();
final ViewPB _view;
class DocumentPluginDisplay extends PluginDisplay with NavigationItem {
final ViewPluginNotifier notifier;
ViewPB get view => notifier.view;
DocumentPluginDisplay({required ViewPB view, Key? key}) : _view = view;
DocumentPluginDisplay({required this.notifier, Key? key});
@override
Widget buildWidget() => DocumentPage(view: _view, key: ValueKey(_view.id));
Widget buildWidget(PluginContext context) => DocumentPage(
view: view,
onDeleted: () => context.onDeleted(view),
key: ValueKey(view.id),
);
@override
Widget get leftBarItem => ViewLeftBarItem(view: _view);
Widget get leftBarItem => ViewLeftBarItem(view: view);
@override
Widget? get rightBarItem => DocumentShareButton(view: _view);
Widget? get rightBarItem => DocumentShareButton(view: view);
@override
List<NavigationItem> get navigationItems => [this];
@override
PublishNotifier<int>? get notifier => _displayNotifier;
}
class DocumentShareButton extends StatelessWidget {

View File

@ -14,9 +14,14 @@ import 'application/doc_bloc.dart';
import 'styles.dart';
class DocumentPage extends StatefulWidget {
final VoidCallback onDeleted;
final ViewPB view;
DocumentPage({Key? key, required this.view}) : super(key: ValueKey(view.id));
DocumentPage({
required this.view,
required this.onDeleted,
Key? key,
}) : super(key: ValueKey(view.id));
@override
State<DocumentPage> createState() => _DocumentPageState();
@ -49,7 +54,8 @@ class _DocumentPageState extends State<DocumentPage> {
finish: (result) => result.successOrFail.fold(
(_) {
if (state.forceClose) {
return _renderAppPage();
widget.onDeleted();
return const SizedBox();
} else {
return _renderDocument(context, state);
}
@ -134,10 +140,4 @@ class _DocumentPageState extends State<DocumentPage> {
),
);
}
Widget _renderAppPage() {
return Container(
color: Colors.black,
);
}
}