AppFlowy/frontend/app_flowy/lib/plugins/grid/grid.dart

86 lines
2.2 KiB
Dart
Raw Normal View History

2022-05-17 18:25:35 +00:00
import 'package:app_flowy/generated/locale_keys.g.dart';
import 'package:app_flowy/plugins/util.dart';
import 'package:app_flowy/startup/plugin/plugin.dart';
2022-03-04 00:22:49 +00:00
import 'package:app_flowy/workspace/presentation/home/home_stack.dart';
import 'package:app_flowy/workspace/presentation/widgets/left_bar_item.dart';
2022-05-17 18:25:35 +00:00
import 'package:easy_localization/easy_localization.dart';
2022-07-04 07:00:54 +00:00
import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart';
2022-03-04 00:22:49 +00:00
import 'package:flutter/material.dart';
import 'presentation/grid_page.dart';
2022-03-04 00:22:49 +00:00
2022-03-06 01:03:02 +00:00
class GridPluginBuilder implements PluginBuilder {
2022-03-04 00:22:49 +00:00
@override
Plugin build(dynamic data) {
2022-07-19 06:11:29 +00:00
if (data is ViewPB) {
2022-03-04 00:22:49 +00:00
return GridPlugin(pluginType: pluginType, view: data);
} else {
throw FlowyPluginException.invalidData;
}
}
@override
2022-05-17 18:25:35 +00:00
String get menuName => LocaleKeys.grid_menuName.tr();
2022-03-04 00:22:49 +00:00
@override
PluginType get pluginType => PluginType.grid;
2022-03-06 01:03:02 +00:00
@override
2022-08-10 09:59:28 +00:00
ViewDataTypePB get dataType => ViewDataTypePB.Database;
@override
ViewLayoutTypePB? get subDataType => ViewLayoutTypePB.Grid;
2022-03-04 00:22:49 +00:00
}
class GridPluginConfig implements PluginConfig {
@override
2022-04-08 06:31:33 +00:00
bool get creatable => true;
2022-03-04 00:22:49 +00:00
}
class GridPlugin extends Plugin {
@override
final ViewPluginNotifier notifier;
2022-03-04 00:22:49 +00:00
final PluginType _pluginType;
GridPlugin({
2022-07-19 06:11:29 +00:00
required ViewPB view,
2022-03-04 00:22:49 +00:00
required PluginType pluginType,
}) : _pluginType = pluginType,
notifier = ViewPluginNotifier(view: view);
2022-03-04 00:22:49 +00:00
@override
PluginDisplay get display => GridPluginDisplay(notifier: notifier);
2022-03-04 00:22:49 +00:00
@override
PluginId get id => notifier.view.id;
2022-03-04 00:22:49 +00:00
@override
PluginType get ty => _pluginType;
}
class GridPluginDisplay extends PluginDisplay {
final ViewPluginNotifier notifier;
ViewPB get view => notifier.view;
GridPluginDisplay({required this.notifier, Key? key});
2022-03-04 00:22:49 +00:00
@override
Widget get leftBarItem => ViewLeftBarItem(view: view);
2022-03-04 00:22:49 +00:00
@override
Widget buildWidget(PluginContext context) {
notifier.isDeleted.addListener(() {
notifier.isDeleted.value.fold(() => null, (deletedView) {
if (deletedView.hasIndex()) {
context.onDeleted(view, deletedView.index);
}
});
});
return GridPage(key: ValueKey(view.id), view: view);
}
2022-03-04 00:22:49 +00:00
@override
List<NavigationItem> get navigationItems => [this];
}