|
@@ -1,14 +1,14 @@
|
|
import 'package:app_flowy/startup/plugin/plugin.dart';
|
|
import 'package:app_flowy/startup/plugin/plugin.dart';
|
|
|
|
+import 'package:app_flowy/workspace/presentation/widgets/pop_up_action.dart';
|
|
|
|
+import 'package:appflowy_popover/appflowy_popover.dart';
|
|
import 'package:flowy_infra/image.dart';
|
|
import 'package:flowy_infra/image.dart';
|
|
-import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
|
|
|
-import 'package:flowy_infra_ui/style_widget/hover.dart';
|
|
|
|
import 'package:flowy_infra_ui/style_widget/icon_button.dart';
|
|
import 'package:flowy_infra_ui/style_widget/icon_button.dart';
|
|
-import 'package:flowy_infra_ui/style_widget/text.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:styled_widget/styled_widget.dart';
|
|
import 'package:styled_widget/styled_widget.dart';
|
|
|
|
|
|
class AddButton extends StatelessWidget {
|
|
class AddButton extends StatelessWidget {
|
|
final Function(PluginBuilder) onSelected;
|
|
final Function(PluginBuilder) onSelected;
|
|
|
|
+
|
|
const AddButton({
|
|
const AddButton({
|
|
Key? key,
|
|
Key? key,
|
|
required this.onSelected,
|
|
required this.onSelected,
|
|
@@ -16,91 +16,47 @@ class AddButton extends StatelessWidget {
|
|
|
|
|
|
@override
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Widget build(BuildContext context) {
|
|
- return FlowyIconButton(
|
|
|
|
- width: 22,
|
|
|
|
- onPressed: () {
|
|
|
|
- ActionList(
|
|
|
|
- anchorContext: context,
|
|
|
|
- onSelected: onSelected,
|
|
|
|
- ).show(context);
|
|
|
|
- },
|
|
|
|
- icon: svgWidget(
|
|
|
|
- "home/add",
|
|
|
|
- color: Theme.of(context).colorScheme.onSurface,
|
|
|
|
- ).padding(horizontal: 3, vertical: 3),
|
|
|
|
|
|
+ final List<PopoverAction> actions = [];
|
|
|
|
+ actions.addAll(
|
|
|
|
+ pluginBuilders()
|
|
|
|
+ .map((pluginBuilder) =>
|
|
|
|
+ AddButtonActionWrapper(pluginBuilder: pluginBuilder))
|
|
|
|
+ .toList(),
|
|
);
|
|
);
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-class ActionList {
|
|
|
|
- final Function(PluginBuilder) onSelected;
|
|
|
|
- final BuildContext anchorContext;
|
|
|
|
- final String _identifier = 'DisclosureButtonActionList';
|
|
|
|
-
|
|
|
|
- const ActionList({required this.anchorContext, required this.onSelected});
|
|
|
|
|
|
|
|
- void show(BuildContext buildContext) {
|
|
|
|
- final items = pluginBuilders().map(
|
|
|
|
- (pluginBuilder) {
|
|
|
|
- return CreateItem(
|
|
|
|
- pluginBuilder: pluginBuilder,
|
|
|
|
- onSelected: (builder) {
|
|
|
|
- onSelected(builder);
|
|
|
|
- FlowyOverlay.of(buildContext).remove(_identifier);
|
|
|
|
- },
|
|
|
|
|
|
+ return PopoverActionList<PopoverAction>(
|
|
|
|
+ direction: PopoverDirection.bottomWithLeftAligned,
|
|
|
|
+ actions: actions,
|
|
|
|
+ buildChild: (controller) {
|
|
|
|
+ return FlowyIconButton(
|
|
|
|
+ width: 22,
|
|
|
|
+ onPressed: () => controller.show(),
|
|
|
|
+ icon: svgWidget(
|
|
|
|
+ "home/add",
|
|
|
|
+ color: Theme.of(context).colorScheme.onSurface,
|
|
|
|
+ ).padding(horizontal: 3, vertical: 3),
|
|
);
|
|
);
|
|
},
|
|
},
|
|
- ).toList();
|
|
|
|
|
|
+ onSelected: (action, controller) {
|
|
|
|
+ if (action is AddButtonActionWrapper) {
|
|
|
|
+ onSelected(action.pluginBuilder);
|
|
|
|
+ }
|
|
|
|
|
|
- ListOverlay.showWithAnchor(
|
|
|
|
- buildContext,
|
|
|
|
- identifier: _identifier,
|
|
|
|
- itemCount: items.length,
|
|
|
|
- itemBuilder: (context, index) => items[index],
|
|
|
|
- anchorContext: anchorContext,
|
|
|
|
- anchorDirection: AnchorDirection.bottomRight,
|
|
|
|
- constraints: BoxConstraints(
|
|
|
|
- minWidth: 120,
|
|
|
|
- maxWidth: 280,
|
|
|
|
- minHeight: items.length * (CreateItem.height),
|
|
|
|
- maxHeight: items.length * (CreateItem.height),
|
|
|
|
- ),
|
|
|
|
|
|
+ controller.close();
|
|
|
|
+ },
|
|
);
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-class CreateItem extends StatelessWidget {
|
|
|
|
- static const double height = 30;
|
|
|
|
- static const double verticalPadding = 6;
|
|
|
|
-
|
|
|
|
|
|
+class AddButtonActionWrapper extends ActionCell {
|
|
final PluginBuilder pluginBuilder;
|
|
final PluginBuilder pluginBuilder;
|
|
- final Function(PluginBuilder) onSelected;
|
|
|
|
- const CreateItem({
|
|
|
|
- Key? key,
|
|
|
|
- required this.pluginBuilder,
|
|
|
|
- required this.onSelected,
|
|
|
|
- }) : super(key: key);
|
|
|
|
|
|
+
|
|
|
|
+ AddButtonActionWrapper({required this.pluginBuilder});
|
|
|
|
|
|
@override
|
|
@override
|
|
- Widget build(BuildContext context) {
|
|
|
|
- return FlowyHover(
|
|
|
|
- child: GestureDetector(
|
|
|
|
- behavior: HitTestBehavior.opaque,
|
|
|
|
- onTap: () => onSelected(pluginBuilder),
|
|
|
|
- child: ConstrainedBox(
|
|
|
|
- constraints: const BoxConstraints(
|
|
|
|
- minWidth: 120,
|
|
|
|
- minHeight: CreateItem.height,
|
|
|
|
- ),
|
|
|
|
- child: Align(
|
|
|
|
- alignment: Alignment.centerLeft,
|
|
|
|
- child: FlowyText.medium(
|
|
|
|
- pluginBuilder.menuName,
|
|
|
|
- fontSize: 12,
|
|
|
|
- ).padding(horizontal: 10),
|
|
|
|
- ),
|
|
|
|
- ),
|
|
|
|
- ),
|
|
|
|
- );
|
|
|
|
- }
|
|
|
|
|
|
+ Widget? icon(Color iconColor) =>
|
|
|
|
+ svgWidget(pluginBuilder.menuIcon, color: iconColor);
|
|
|
|
+
|
|
|
|
+ @override
|
|
|
|
+ String get name => pluginBuilder.menuName;
|
|
}
|
|
}
|