From 7246f597afc92e4f9111f5540075cfa16b5e65f0 Mon Sep 17 00:00:00 2001 From: appflowy Date: Sat, 6 Nov 2021 11:29:42 +0800 Subject: [PATCH] [flutter]: question bubble popup --- .../widgets/float_bubble/question_bubble.dart | 66 ++++++++++++++++++- .../widget/app/header/right_click_action.dart | 10 +-- .../widget/app/section/disclosure_action.dart | 3 - .../presentation/widgets/pop_up_action.dart | 8 +-- 4 files changed, 72 insertions(+), 15 deletions(-) diff --git a/app_flowy/lib/workspace/presentation/widgets/float_bubble/question_bubble.dart b/app_flowy/lib/workspace/presentation/widgets/float_bubble/question_bubble.dart index fcbd3d342f..6e87f925d0 100644 --- a/app_flowy/lib/workspace/presentation/widgets/float_bubble/question_bubble.dart +++ b/app_flowy/lib/workspace/presentation/widgets/float_bubble/question_bubble.dart @@ -1,7 +1,10 @@ +import 'package:app_flowy/workspace/presentation/widgets/pop_up_action.dart'; import 'package:flowy_infra/theme.dart'; +import 'package:flowy_infra_ui/flowy_infra_ui.dart'; import 'package:flowy_infra_ui/style_widget/button.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'package:dartz/dartz.dart' as dartz; class QuestionBubble extends StatelessWidget { const QuestionBubble({Key? key}) : super(key: key); @@ -19,8 +22,69 @@ class QuestionBubble extends StatelessWidget { fillColor: theme.selector, mainAxisAlignment: MainAxisAlignment.center, radius: BorderRadius.circular(10), - onPressed: () {}, + onPressed: () { + final actionList = QuestionBubbleActions(onSelected: (action) {}); + actionList.show( + context, + context, + anchorDirection: AnchorDirection.topWithCenterAligned, + ); + }, ), ); } } + +class QuestionBubbleActions with ActionList implements FlowyOverlayDelegate { + final Function(dartz.Option) onSelected; + final _items = QuestionBubbleAction.values.map((action) => QuestionBubbleActionWrapper(action)).toList(); + + QuestionBubbleActions({ + required this.onSelected, + }); + + @override + List get items => _items; + + @override + void Function(dartz.Option p1) get selectCallback => (result) { + result.fold( + () => onSelected(dartz.none()), + (wrapper) => onSelected( + dartz.some(wrapper.inner), + ), + ); + }; + + @override + FlowyOverlayDelegate? get delegate => this; + + @override + void didRemove() { + onSelected(dartz.none()); + } +} + +enum QuestionBubbleAction { + whatsNews, +} + +class QuestionBubbleActionWrapper extends ActionItemData { + final QuestionBubbleAction inner; + + QuestionBubbleActionWrapper(this.inner); + @override + Widget? get icon => null; + + @override + String get name => inner.name; +} + +extension QuestionBubbleExtension on QuestionBubbleAction { + String get name { + switch (this) { + case QuestionBubbleAction.whatsNews: + return "What's new"; + } + } +} diff --git a/app_flowy/lib/workspace/presentation/widgets/menu/widget/app/header/right_click_action.dart b/app_flowy/lib/workspace/presentation/widgets/menu/widget/app/header/right_click_action.dart index feb1ae89c2..9186bdc556 100644 --- a/app_flowy/lib/workspace/presentation/widgets/menu/widget/app/header/right_click_action.dart +++ b/app_flowy/lib/workspace/presentation/widgets/menu/widget/app/header/right_click_action.dart @@ -12,20 +12,16 @@ class AppDisclosureActions with ActionList implement required this.onSelected, }); - @override - String get identifier => "ViewDisclosureActions"; - @override List get items => _items; - @override - double get maxWidth => 162; - @override void Function(dartz.Option p1) get selectCallback => (result) { result.fold( () => onSelected(dartz.none()), - (wrapper) => onSelected(dartz.some(wrapper.inner)), + (wrapper) => onSelected( + dartz.some(wrapper.inner), + ), ); }; diff --git a/app_flowy/lib/workspace/presentation/widgets/menu/widget/app/section/disclosure_action.dart b/app_flowy/lib/workspace/presentation/widgets/menu/widget/app/section/disclosure_action.dart index db0ce49c3a..06f1ba3ad1 100644 --- a/app_flowy/lib/workspace/presentation/widgets/menu/widget/app/section/disclosure_action.dart +++ b/app_flowy/lib/workspace/presentation/widgets/menu/widget/app/section/disclosure_action.dart @@ -34,9 +34,6 @@ class ViewDisclosureButton extends StatelessWidget ); } - @override - String get identifier => "ViewDisclosureActions"; - @override List get items => _items; diff --git a/app_flowy/lib/workspace/presentation/widgets/pop_up_action.dart b/app_flowy/lib/workspace/presentation/widgets/pop_up_action.dart index 0c74c93594..ce22623d7e 100644 --- a/app_flowy/lib/workspace/presentation/widgets/pop_up_action.dart +++ b/app_flowy/lib/workspace/presentation/widgets/pop_up_action.dart @@ -11,9 +11,9 @@ import 'package:dartz/dartz.dart' as dartz; abstract class ActionList { List get items; - String get identifier; + String get identifier => toString(); - double get maxWidth; + double get maxWidth => 162; void Function(dartz.Option) get selectCallback; @@ -47,7 +47,7 @@ abstract class ActionList { } abstract class ActionItemData { - Widget get icon; + Widget? get icon; String get name; } @@ -80,7 +80,7 @@ class ActionItem extends StatelessWidget { height: ActionListSizes.itemHeight, child: Row( children: [ - action.icon, + if (action.icon != null) action.icon!, HSpace(ActionListSizes.itemHPadding), FlowyText.medium( action.name,