Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
feat(flutter_desktop): AI chat refer to UI (#6930)
Richard Shiue3b568872670c
diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_side_panel_bloc.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_side_panel_bloc.dartdeleted file mode 100644index 18786c4165..0000000000--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_side_panel_bloc.dart+++ /dev/null@@ -1,75 +0,0 @@-import 'package:appflowy/plugins/ai_chat/application/chat_entity.dart';-import 'package:appflowy/workspace/application/view/view_service.dart';-import 'package:appflowy_backend/log.dart';-import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';-import 'package:appflowy_result/appflowy_result.dart';-import 'package:flutter_bloc/flutter_bloc.dart';-import 'package:freezed_annotation/freezed_annotation.dart';--part 'chat_side_panel_bloc.freezed.dart';--class ChatSidePanelBloc extends Bloc<ChatSidePanelEvent, ChatSidePanelState> {- ChatSidePanelBloc({- required this.chatId,- }) : super(const ChatSidePanelState()) {- on<ChatSidePanelEvent>(- (event, emit) async {- await event.when(- selectedMetadata: (ChatMessageRefSource metadata) async {- emit(- state.copyWith(- metadata: metadata,- indicator: const ChatSidePanelIndicator.loading(),- ),- );- await ViewBackendService.getView(metadata.id).fold(- (view) {- if (!isClosed) {- add(ChatSidePanelEvent.open(view));- }- },- (err) => Log.error("Failed to get view: $err"),- );- },- close: () {- emit(state.copyWith(metadata: null, isShowPanel: false));- },- open: (ViewPB view) {- emit(- state.copyWith(- indicator: ChatSidePanelIndicator.ready(view),- isShowPanel: true,- ),- );- },- );- },- );- }-- final String chatId;-}--@freezed-class ChatSidePanelEvent with _$ChatSidePanelEvent {- const factory ChatSidePanelEvent.selectedMetadata(- ChatMessageRefSource metadata,- ) = _SelectedMetadata;- const factory ChatSidePanelEvent.close() = _Close;- const factory ChatSidePanelEvent.open(ViewPB view) = _Open;-}--@freezed-class ChatSidePanelState with _$ChatSidePanelState {- const factory ChatSidePanelState({- ChatMessageRefSource? metadata,- @Default(ChatSidePanelIndicator.loading()) ChatSidePanelIndicator indicator,- @Default(false) bool isShowPanel,- }) = _ChatSidePanelState;-}--@freezed-class ChatSidePanelIndicator with _$ChatSidePanelIndicator {- const factory ChatSidePanelIndicator.ready(ViewPB view) = _Ready;- const factory ChatSidePanelIndicator.loading() = _Loading;-}diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/chat.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/chat.dartindex 568f31b714..72e6b8256a 100644--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/chat.dart+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/chat.dart@@ -110,7 +110,7 @@ class AIChatPagePluginWidgetBuilder extends PluginWidgetBuilderreturn const SizedBox();}- return BlocProvider<ViewInfoBloc>.value(+ return BlocProvider.value(value: bloc,child: AIChatPage(userProfile: context.userProfile!,diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/chat_page.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/chat_page.dartindex 144c378d70..9c6ccc688d 100644--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/chat_page.dart+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/chat_page.dart@@ -6,9 +6,14 @@ import 'package:appflowy/plugins/ai_chat/application/chat_entity.dart';import 'package:appflowy/plugins/ai_chat/application/ai_prompt_input_bloc.dart';import 'package:appflowy/plugins/ai_chat/application/chat_message_stream.dart';import 'package:appflowy/plugins/ai_chat/presentation/chat_related_question.dart';+import 'package:appflowy/startup/startup.dart';+import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';+import 'package:appflowy/workspace/application/view/view_ext.dart';+import 'package:appflowy/workspace/application/view/view_service.dart';import 'package:appflowy_backend/log.dart';import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';+import 'package:appflowy_result/appflowy_result.dart';import 'package:desktop_drop/desktop_drop.dart';import 'package:easy_localization/easy_localization.dart';import 'package:flowy_infra_ui/flowy_infra_ui.dart';@@ -18,16 +23,13 @@ import 'package:flutter_chat_core/flutter_chat_core.dart';import 'package:flutter_chat_ui/flutter_chat_ui.dart'hide ChatAnimatedListReversed;import 'package:string_validator/string_validator.dart';-import 'package:styled_widget/styled_widget.dart';import 'package:universal_platform/universal_platform.dart';import 'package:url_launcher/url_launcher.dart';import 'application/chat_member_bloc.dart';-import 'application/chat_side_panel_bloc.dart';import 'presentation/animated_chat_list.dart';import 'presentation/chat_input/desktop_ai_prompt_input.dart';import 'presentation/chat_input/mobile_ai_prompt_input.dart';-import 'presentation/chat_side_panel.dart';import 'presentation/chat_welcome_page.dart';import 'presentation/layout_define.dart';import 'presentation/message/ai_text_message.dart';@@ -70,7 +72,6 @@ class AIChatPage extends StatelessWidget {/// [AIPromptInputBloc] is used to handle the user promptBlocProvider(create: (_) => AIPromptInputBloc()),- BlocProvider(create: (_) => ChatSidePanelBloc(chatId: view.id)),BlocProvider(create: (_) => ChatMemberBloc()),],child: Builder(@@ -107,110 +108,50 @@ class _ChatContentPage extends StatelessWidget {@overrideWidget build(BuildContext context) {- if (UniversalPlatform.isDesktop) {- return BlocSelector<ChatSidePanelBloc, ChatSidePanelState, bool>(- selector: (state) => state.isShowPanel,- builder: (context, isShowPanel) {- return LayoutBuilder(- builder: (BuildContext context, BoxConstraints constraints) {- final sidePanelRatio = isShowPanel ? 0.33 : 0.0;- final chatWidth = constraints.maxWidth * (1 - sidePanelRatio);- final sidePanelWidth =- constraints.maxWidth * sidePanelRatio - 1.0;-- return Row(- children: [- Center(- child: buildChatWidget(context)- .constrained(- maxWidth: 784,- )- .padding(horizontal: 60)- .animate(- const Duration(milliseconds: 200),- Curves.easeOut,- ),- ).constrained(width: chatWidth),- if (isShowPanel) ...[- const VerticalDivider(- width: 1.0,- thickness: 1.0,- ),- buildChatSidePanel()- .constrained(width: sidePanelWidth)- .animate(- const Duration(milliseconds: 200),- Curves.easeOut,+ return Center(+ child: Container(+ constraints: const BoxConstraints(maxWidth: 784),+ margin: UniversalPlatform.isDesktop+ ? const EdgeInsets.symmetric(horizontal: 60.0)+ : null,+ child: ScrollConfiguration(+ behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false),+ child: BlocBuilder<ChatBloc, ChatState>(+ builder: (context, state) {+ return state.loadingState.when(+ loading: () {+ return const Center(+ child: CircularProgressIndicator.adaptive(),+ );+ },+ finish: (_) {+ final chatController =+ context.read<ChatBloc>().chatController;+ return Column(+ children: [+ Expanded(+ child: Chat(+ chatController: chatController,+ user: User(id: userProfile.id.toString()),+ darkTheme: ChatTheme.fromThemeData(Theme.of(context)),+ theme: ChatTheme.fromThemeData(Theme.of(context)),+ builders: Builders(+ inputBuilder: (_) => const SizedBox.shrink(),+ textMessageBuilder: _buildTextMessage,+ chatMessageBuilder: _buildChatMessage,+ scrollToBottomBuilder: _buildScrollToBottom,+ chatAnimatedListBuilder: _buildChatAnimatedList,+ ),),- ],- ],- );- },- );- },- );- } else {- return Row(- mainAxisAlignment: MainAxisAlignment.center,- children: [- Flexible(- child: ConstrainedBox(- constraints: const BoxConstraints(maxWidth: 784),- child: buildChatWidget(context),- ),- ),- ],- );- }- }-- Widget buildChatSidePanel() {- return BlocBuilder<ChatSidePanelBloc, ChatSidePanelState>(- builder: (context, state) {- if (state.metadata == null) {- return const SizedBox.shrink();- }- return const ChatSidePanel();- },- );- }-- Widget buildChatWidget(BuildContext context) {- return ScrollConfiguration(- behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false),- child: BlocBuilder<ChatBloc, ChatState>(- builder: (context, state) {- return state.loadingState.when(- loading: () {- return const Center(- child: CircularProgressIndicator.adaptive(),- );- },- finish: (_) {- final chatController = context.read<ChatBloc>().chatController;- return Column(- children: [- Expanded(- child: Chat(- chatController: chatController,- user: User(id: userProfile.id.toString()),- darkTheme: ChatTheme.fromThemeData(Theme.of(context)),- theme: ChatTheme.fromThemeData(Theme.of(context)),- builders: Builders(- inputBuilder: (_) => const SizedBox.shrink(),- textMessageBuilder: _buildTextMessage,- chatMessageBuilder: _buildChatMessage,- scrollToBottomBuilder: _buildScrollToBottom,- chatAnimatedListBuilder: _buildChatAnimatedList,),- ),- ),- _buildInput(context),- ],+ _buildInput(context),+ ],+ );+ },);},- );- },+ ),+ ),),);}@@ -278,27 +219,7 @@ class _ChatContentPage extends StatelessWidget {chatId: view.id,refSourceJsonString: refSourceJsonString,isLastMessage: isLastMessage,- onSelectedMetadata: (metadata) async {- if (isURL(metadata.name)) {- late Uri uri;-- try {- uri = Uri.parse(metadata.name);- // `Uri` identifies `localhost` as a scheme- if (!uri.hasScheme || uri.scheme == 'localhost') {- uri = Uri.parse("http://${metadata.name}");- await InternetAddress.lookup(uri.host);- }- await launchUrl(uri);- } catch (err) {- Log.error("failed to open url $err");- }- } else {- context- .read<ChatSidePanelBloc>()- .add(ChatSidePanelEvent.selectedMetadata(metadata));- }- },+ onSelectedMetadata: _onSelectMetadata,);},);@@ -375,9 +296,9 @@ class _ChatContentPage extends StatelessWidget {);},isStreaming: !canSendMessage,- onStopStreaming: () {- context.read<ChatBloc>().add(const ChatEvent.stopStream());- },+ onStopStreaming: () => context+ .read<ChatBloc>()+ .add(const ChatEvent.stopStream()),): MobileAIPromptInput(chatId: view.id,@@ -390,12 +311,40 @@ class _ChatContentPage extends StatelessWidget {);},isStreaming: !canSendMessage,- onStopStreaming: () {- context.read<ChatBloc>().add(const ChatEvent.stopStream());- },+ onStopStreaming: () => context+ .read<ChatBloc>()+ .add(const ChatEvent.stopStream()),);},),);}++ void _onSelectMetadata(ChatMessageRefSource metadata) async {+ if (isURL(metadata.name)) {+ late Uri uri;+ try {+ uri = Uri.parse(metadata.name);+ // `Uri` identifies `localhost` as a scheme+ if (!uri.hasScheme || uri.scheme == 'localhost') {+ uri = Uri.parse("http://${metadata.name}");+ await InternetAddress.lookup(uri.host);+ }+ await launchUrl(uri);+ } catch (err) {+ Log.error("failed to open url $err");+ }+ } else {+ await ViewBackendService.getView(metadata.id).fold(+ (sidebarView) {+ getIt<TabsBloc>().add(+ TabsEvent.openSecondaryPlugin(+ plugin: sidebarView.plugin(),+ ),+ );+ },+ (err) => Log.error("Failed to get view: $err"),+ );+ }+ }}diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_side_panel.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_side_panel.dartdeleted file mode 100644index 7904b44437..0000000000--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_side_panel.dart+++ /dev/null@@ -1,50 +0,0 @@-import 'package:appflowy/generated/flowy_svgs.g.dart';-import 'package:appflowy/plugins/ai_chat/application/chat_side_panel_bloc.dart';-import 'package:appflowy/startup/plugin/plugin.dart';-import 'package:appflowy/workspace/application/view/view_ext.dart';-import 'package:flowy_infra_ui/flowy_infra_ui.dart';-import 'package:flutter/material.dart';-import 'package:flutter_bloc/flutter_bloc.dart';--class ChatSidePanel extends StatelessWidget {- const ChatSidePanel({super.key});-- @override- Widget build(BuildContext context) {- return BlocBuilder<ChatSidePanelBloc, ChatSidePanelState>(- builder: (context, state) {- return state.indicator.when(- loading: () {- return const CircularProgressIndicator.adaptive();- },- ready: (view) {- final plugin = view.plugin();- plugin.init();-- final pluginContext = PluginContext();- final child = plugin.widgetBuilder- .buildWidget(context: pluginContext, shrinkWrap: false);- return Column(- crossAxisAlignment: CrossAxisAlignment.start,- children: [- Padding(- padding: const EdgeInsets.all(8.0),- child: FlowyIconButton(- icon: const FlowySvg(FlowySvgs.show_menu_s),- onPressed: () {- context- .read<ChatSidePanelBloc>()- .add(const ChatSidePanelEvent.close());- },- ),- ),- const VSpace(6),- Expanded(child: child),- ],- );- },- );- },- );- }-}diff --git a/frontend/appflowy_flutter/lib/workspace/application/tabs/tabs_bloc.dart b/frontend/appflowy_flutter/lib/workspace/application/tabs/tabs_bloc.dartindex d9f5571f91..a437c9747c 100644--- a/frontend/appflowy_flutter/lib/workspace/application/tabs/tabs_bloc.dart+++ b/frontend/appflowy_flutter/lib/workspace/application/tabs/tabs_bloc.dart@@ -57,10 +57,12 @@ class TabsBloc extends Bloc<TabsEvent, TabsState> {_setLatestOpenView();},openTab: (Plugin plugin, ViewPB view) {+ state.currentPageManager.hideSecondaryPlugin();emit(state.openView(plugin));_setLatestOpenView(view);},openPlugin: (Plugin plugin, ViewPB? view, bool setLatest) {+ state.currentPageManager.hideSecondaryPlugin();emit(state.openPlugin(plugin: plugin, setLatest: setLatest));if (setLatest) {_setLatestOpenView(view);@@ -151,6 +153,23 @@ class TabsBloc extends Bloc<TabsEvent, TabsState> {);}},+ openSecondaryPlugin: (plugin, view) {+ state.currentPageManager.setSecondaryPlugin(plugin);+ },+ closeSecondaryPlugin: () {+ final pageManager = state.currentPageManager;+ pageManager.hideSecondaryPlugin();+ },+ expandSecondaryPlugin: () {+ final pageManager = state.currentPageManager;+ pageManager.setPlugin(+ pageManager.secondaryNotifier.plugin,+ true,+ false,+ );+ pageManager.hideSecondaryPlugin();+ _setLatestOpenView();+ },switchWorkspace: (workspaceId) {final pluginId = state.currentPageManager.plugin.id;@@ -237,6 +256,12 @@ class TabsEvent with _$TabsEvent {ViewPB? view,@Default(true) bool setLatest,}) = _OpenPlugin;+ const factory TabsEvent.openSecondaryPlugin({+ required Plugin plugin,+ ViewPB? view,+ }) = _OpenSecondaryPlugin;+ const factory TabsEvent.closeSecondaryPlugin() = _CloseSecondaryPlugin;+ const factory TabsEvent.expandSecondaryPlugin() = _ExpandSecondaryPlugin;const factory TabsEvent.switchWorkspace(String workspaceId) =_SwitchWorkspace;}diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/home_stack.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/home_stack.dartindex 0e63792faa..4261865e5e 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/home_stack.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/home_stack.dart@@ -1,4 +1,6 @@+import 'dart:async';import 'dart:io';+import 'dart:math';import 'package:flutter/material.dart';import 'package:flutter/scheduler.dart';@@ -25,6 +27,7 @@ import 'package:flowy_infra_ui/style_widget/hover.dart';import 'package:flutter_bloc/flutter_bloc.dart';import 'package:provider/provider.dart';import 'package:time/time.dart';+import 'package:universal_platform/universal_platform.dart';import 'home_layout.dart';@@ -58,13 +61,9 @@ class _HomeStackState extends State<HomeStack> {return BlocProvider<TabsBloc>.value(value: getIt<TabsBloc>(),child: BlocBuilder<TabsBloc, TabsState>(- buildWhen: (prev, curr) =>- prev.currentIndex != curr.currentIndex &&- prev.currentPageManager.plugin.id !=- curr.currentPageManager.plugin.id,builder: (context, state) => Column(children: [- if (Platform.isWindows)+ if (UniversalPlatform.isWindows)Column(mainAxisSize: MainAxisSize.min,children: [@@ -92,17 +91,32 @@ class _HomeStackState extends State<HomeStack> {index: selectedIndex,children: state.pageManagers.map(- (pm) => Column(- children: [- pm.stackTopBar(layout: widget.layout),- Expanded(- child: PageStack(- pageManager: pm,- delegate: widget.delegate,- userProfile: widget.userProfile,- ),- ),- ],+ (pm) => LayoutBuilder(+ builder: (context, constraints) {+ return Row(+ children: [+ Expanded(+ child: Column(+ children: [+ pm.stackTopBar(layout: widget.layout),+ Expanded(+ child: PageStack(+ pageManager: pm,+ delegate: widget.delegate,+ userProfile: widget.userProfile,+ ),+ ),+ ],+ ),+ ),+ SecondaryView(+ pageManager: pm,+ adaptedPercentageWidth:+ constraints.maxWidth * 3 / 7,+ ),+ ],+ );+ },),).toList(),@@ -195,6 +209,241 @@ class _PageStackState extends State<PageStack>bool get wantKeepAlive => true;}+class SecondaryView extends StatefulWidget {+ const SecondaryView({+ super.key,+ required this.pageManager,+ required this.adaptedPercentageWidth,+ });++ final PageManager pageManager;+ final double adaptedPercentageWidth;++ @override+ State<SecondaryView> createState() => _SecondaryViewState();+}++class _SecondaryViewState extends State<SecondaryView>+ with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin {+ late final ValueNotifier<double> widthNotifier;++ late final AnimationController animationController;+ late Animation<double> widthAnimation;+ late final Animation<Offset> offsetAnimation;++ CurvedAnimation get curveAnimation => CurvedAnimation(+ parent: animationController,+ curve: Curves.easeOut,+ );++ @override+ void initState() {+ super.initState();+ widget.pageManager.showSecondaryPluginNotifier+ .addListener(onShowSecondaryChanged);+ final width = widget.pageManager.showSecondaryPluginNotifier.value+ ? max(450.0, widget.adaptedPercentageWidth)+ : 0.0;+ widthNotifier = ValueNotifier<double>(width)+ ..addListener(updateWidthAnimation);++ animationController = AnimationController(+ duration: const Duration(milliseconds: 300),+ vsync: this,+ );++ widthAnimation = Tween<double>(+ begin: 0.0,+ end: width,+ ).animate(curveAnimation);+ offsetAnimation = Tween<Offset>(+ begin: const Offset(1.0, 0.0),+ end: Offset.zero,+ ).animate(curveAnimation);+ }++ @override+ void dispose() {+ widget.pageManager.showSecondaryPluginNotifier+ .removeListener(onShowSecondaryChanged);+ widthNotifier.dispose();+ super.dispose();+ }++ void onShowSecondaryChanged() async {+ if (widget.pageManager.showSecondaryPluginNotifier.value) {+ widthNotifier.value = max(450.0, widget.adaptedPercentageWidth);+ updateWidthAnimation();+ await animationController.forward();+ } else {+ updateWidthAnimation();+ await animationController.reverse();+ setState(() => widthNotifier.value = 0.0);+ }+ }++ void updateWidthAnimation() {+ widthAnimation = Tween<double>(+ begin: 0.0,+ end: widthNotifier.value,+ ).animate(curveAnimation);+ }++ @override+ Widget build(BuildContext context) {+ super.build(context);+ return Container(+ color: Theme.of(context).colorScheme.surface,+ child: FocusTraversalGroup(+ child: ValueListenableBuilder(+ valueListenable: widthNotifier,+ builder: (context, value, child) {+ return AnimatedBuilder(+ animation: Listenable.merge([+ widthAnimation,+ offsetAnimation,+ ]),+ builder: (context, child) {+ return Container(+ width: widthAnimation.value,+ alignment: Alignment(+ offsetAnimation.value.dx,+ offsetAnimation.value.dy,+ ),+ child: OverflowBox(+ alignment: AlignmentDirectional.centerStart,+ maxWidth: value,+ child: SecondaryViewResizer(+ pageManager: widget.pageManager,+ notifier: widthNotifier,+ child: Column(+ children: [+ widget.pageManager.stackSecondaryTopBar(value),+ Expanded(+ child:+ widget.pageManager.stackSecondaryWidget(value),+ ),+ ],+ ),+ ),+ ),+ );+ },+ );+ },+ ),+ ),+ );+ }++ @override+ bool get wantKeepAlive => true;+}++class SecondaryViewResizer extends StatefulWidget {+ const SecondaryViewResizer({+ super.key,+ required this.pageManager,+ required this.notifier,+ required this.child,+ });++ final PageManager pageManager;+ final ValueNotifier<double> notifier;+ final Widget child;++ @override+ State<SecondaryViewResizer> createState() => _SecondaryViewResizerState();+}++class _SecondaryViewResizerState extends State<SecondaryViewResizer> {+ final overlayController = OverlayPortalController();+ final layerLink = LayerLink();++ bool isHover = false;+ bool isDragging = false;+ Timer? showHoverTimer;++ @override+ void initState() {+ super.initState();+ overlayController.show();+ }++ @override+ Widget build(BuildContext context) {+ return OverlayPortal(+ controller: overlayController,+ overlayChildBuilder: (context) {+ return CompositedTransformFollower(+ showWhenUnlinked: false,+ link: layerLink,+ targetAnchor: Alignment.center,+ followerAnchor: Alignment.center,+ child: Center(+ child: MouseRegion(+ cursor: SystemMouseCursors.resizeLeftRight,+ onEnter: (_) {+ showHoverTimer = Timer(const Duration(milliseconds: 500), () {+ setState(() => isHover = true);+ });+ },+ onExit: (_) {+ showHoverTimer?.cancel();+ setState(() => isHover = false);+ },+ child: GestureDetector(+ behavior: HitTestBehavior.opaque,+ onHorizontalDragStart: (_) => setState(() => isDragging = true),+ onHorizontalDragUpdate: (details) {+ final newWidth = MediaQuery.sizeOf(context).width -+ details.globalPosition.dx;+ if (newWidth >= 450.0) {+ widget.notifier.value = newWidth;+ }+ },+ onHorizontalDragEnd: (_) => setState(() => isDragging = false),+ child: TweenAnimationBuilder(+ tween: ColorTween(+ end: isHover || isDragging+ ? Theme.of(context).colorScheme.primary+ : Colors.transparent,+ ),+ duration: const Duration(milliseconds: 100),+ builder: (context, color, child) {+ return SizedBox(+ width: 11,+ child: Center(+ child: Container(+ color: color,+ width: 2,+ ),+ ),+ );+ },+ ),+ ),+ ),+ ),+ );+ },+ child: Row(+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ CompositedTransformTarget(+ link: layerLink,+ child: Container(+ width: 1,+ color: Theme.of(context).dividerColor,+ ),+ ),+ Flexible(child: widget.child),+ ],+ ),+ );+ }+}+class FadingIndexedStack extends StatefulWidget {const FadingIndexedStack({super.key,@@ -267,8 +516,9 @@ class PageNotifier extends ChangeNotifier {/// This is the only place where the plugin is set./// No need compare the old plugin with the new plugin. Just set it.void setPlugin(Plugin newPlugin, bool setLatest) {- _plugin.dispose();- newPlugin.init();+ if (newPlugin.id != plugin.id) {+ _plugin.dispose();+ }// Set the plugin view as the latest view.if (setLatest) {@@ -287,24 +537,37 @@ class PageManager {PageManager();final PageNotifier _notifier = PageNotifier();+ final PageNotifier _secondaryNotifier = PageNotifier();PageNotifier get notifier => _notifier;+ PageNotifier get secondaryNotifier => _secondaryNotifier;bool isPinned = false;- Widget title() {- return _notifier.plugin.widgetBuilder.leftBarItem;- }+ final showSecondaryPluginNotifier = ValueNotifier(false);Plugin get plugin => _notifier.plugin;- void setPlugin(Plugin newPlugin, bool setLatest) {+ void setPlugin(Plugin newPlugin, bool setLatest, [bool init = true]) {+ if (init) {+ newPlugin.init();+ }_notifier.setPlugin(newPlugin, setLatest);}+ void setSecondaryPlugin(Plugin newPlugin) {+ newPlugin.init();+ _secondaryNotifier.setPlugin(newPlugin, false);+ showSecondaryPluginNotifier.value = true;+ }++ void hideSecondaryPlugin() {+ showSecondaryPluginNotifier.value = false;+ }+Widget stackTopBar({required HomeLayout layout}) {- return MultiProvider(- providers: [ChangeNotifierProvider.value(value: _notifier)],+ return ChangeNotifierProvider.value(+ value: _notifier,child: Selector<PageNotifier, Widget>(selector: (context, notifier) => notifier.titleWidget,builder: (_, __, child) => MoveWindowDetector(@@ -318,10 +581,10 @@ class PageManager {required UserProfilePB userProfile,required Function(ViewPB, int?) onDeleted,}) {- return MultiProvider(- providers: [ChangeNotifierProvider.value(value: _notifier)],- child: Consumer(- builder: (_, PageNotifier notifier, __) {+ return ChangeNotifierProvider.value(+ value: _notifier,+ child: Consumer<PageNotifier>(+ builder: (_, notifier, __) {return FadingIndexedStack(index: getIt<PluginSandbox>().indexOf(notifier.plugin.pluginType),children: getIt<PluginSandbox>().supportPluginTypes.map(@@ -351,8 +614,59 @@ class PageManager {);}+ Widget stackSecondaryWidget(double width) {+ return ValueListenableBuilder(+ valueListenable: showSecondaryPluginNotifier,+ builder: (context, value, child) {+ if (width == 0.0) {+ return const SizedBox.shrink();+ }++ return child!;+ },+ child: ChangeNotifierProvider.value(+ value: _secondaryNotifier,+ child: Selector<PageNotifier, PluginWidgetBuilder>(+ selector: (context, notifier) => notifier.plugin.widgetBuilder,+ builder: (_, widgetBuilder, __) {+ return widgetBuilder.buildWidget(+ context: PluginContext(),+ shrinkWrap: false,+ );+ },+ ),+ ),+ );+ }++ Widget stackSecondaryTopBar(double width) {+ return ValueListenableBuilder(+ valueListenable: showSecondaryPluginNotifier,+ builder: (context, value, child) {+ if (width == 0.0) {+ return const SizedBox.shrink();+ }++ return child!;+ },+ child: ChangeNotifierProvider.value(+ value: _secondaryNotifier,+ child: Selector<PageNotifier, PluginWidgetBuilder>(+ selector: (context, notifier) => notifier.plugin.widgetBuilder,+ builder: (_, widgetBuilder, __) {+ return const MoveWindowDetector(+ child: HomeSecondaryTopBar(),+ );+ },+ ),+ ),+ );+ }+void dispose() {_notifier.dispose();+ _secondaryNotifier.dispose();+ showSecondaryPluginNotifier.dispose();}}@@ -403,3 +717,63 @@ class _HomeTopBarState extends State<HomeTopBar>@overridebool get wantKeepAlive => true;}++class HomeSecondaryTopBar extends StatelessWidget {+ const HomeSecondaryTopBar({super.key});++ @override+ Widget build(BuildContext context) {+ return Container(+ decoration: BoxDecoration(+ color: Theme.of(context).colorScheme.surface,+ ),+ height: HomeSizes.topBarHeight + HomeInsets.topBarTitleVerticalPadding,+ child: Padding(+ padding: const EdgeInsets.symmetric(+ horizontal: HomeInsets.topBarTitleHorizontalPadding,+ vertical: HomeInsets.topBarTitleVerticalPadding,+ ),+ child: Row(+ children: [+ FlowyIconButton(+ width: 24,+ radius: const BorderRadius.all(Radius.circular(8.0)),+ icon: const FlowySvg(+ FlowySvgs.show_menu_s,+ size: Size.square(16),+ ),+ onPressed: () {+ getIt<TabsBloc>().add(const TabsEvent.closeSecondaryPlugin());+ },+ ),+ const HSpace(8.0),+ FlowyIconButton(+ width: 24,+ radius: const BorderRadius.all(Radius.circular(8.0)),+ icon: const FlowySvg(+ FlowySvgs.full_view_s,+ size: Size.square(16),+ ),+ onPressed: () {+ getIt<TabsBloc>().add(const TabsEvent.expandSecondaryPlugin());+ },+ ),+ Expanded(+ child: Align(+ alignment: AlignmentDirectional.centerEnd,+ child: ChangeNotifierProvider.value(+ value: Provider.of<PageNotifier>(context, listen: false),+ child: Consumer(+ builder: (_, PageNotifier notifier, __) =>+ notifier.plugin.widgetBuilder.rightBarItem ??+ const SizedBox.shrink(),+ ),+ ),+ ),+ ),+ ],+ ),+ ),+ );+ }+}diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/tabs/tabs_manager.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/tabs/tabs_manager.dartindex 08d9a478c1..38ede2421e 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/tabs/tabs_manager.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/tabs/tabs_manager.dart@@ -13,55 +13,50 @@ class TabsManager extends StatelessWidget {@overrideWidget build(BuildContext context) {- return BlocProvider<TabsBloc>.value(- value: context.read<TabsBloc>(),- child: BlocListener<TabsBloc, TabsState>(- listenWhen: (prev, curr) =>- prev.currentIndex != curr.currentIndex || prev.pages != curr.pages,- listener: (context, state) => onIndexChanged(state.currentIndex),- child: BlocBuilder<TabsBloc, TabsState>(- builder: (context, state) {- if (state.pages == 1) {- return const SizedBox.shrink();- }+ return BlocConsumer<TabsBloc, TabsState>(+ listenWhen: (prev, curr) =>+ prev.currentIndex != curr.currentIndex || prev.pages != curr.pages,+ listener: (context, state) => onIndexChanged(state.currentIndex),+ builder: (context, state) {+ if (state.pages == 1) {+ return const SizedBox.shrink();+ }- final isAllPinned = state.isAllPinned;+ final isAllPinned = state.isAllPinned;- return Container(- alignment: Alignment.bottomLeft,- height: HomeSizes.tabBarHeight,- decoration: BoxDecoration(- color: Theme.of(context).colorScheme.surfaceContainerHighest,- ),- child: MoveWindowDetector(- child: Row(- children: state.pageManagers.map<Widget>((pm) {- return Flexible(- child: ConstrainedBox(- constraints: const BoxConstraints(- maxWidth: HomeSizes.tabBarWidth,- ),- child: FlowyTab(- key: ValueKey('tab-${pm.plugin.id}'),- pageManager: pm,- isCurrent: state.currentPageManager == pm,- isAllPinned: isAllPinned,- onTap: () {- if (state.currentPageManager != pm) {- final index = state.pageManagers.indexOf(pm);- onIndexChanged(index);- }- },- ),- ),- );- }).toList(),- ),- ),- );- },- ),- ),+ return Container(+ alignment: Alignment.bottomLeft,+ height: HomeSizes.tabBarHeight,+ decoration: BoxDecoration(+ color: Theme.of(context).colorScheme.surfaceContainerHighest,+ ),+ child: MoveWindowDetector(+ child: Row(+ children: state.pageManagers.map((pm) {+ return Flexible(+ child: ConstrainedBox(+ constraints: const BoxConstraints(+ maxWidth: HomeSizes.tabBarWidth,+ ),+ child: FlowyTab(+ key: ValueKey('tab-${pm.plugin.id}'),+ pageManager: pm,+ isCurrent: state.currentPageManager == pm,+ isAllPinned: isAllPinned,+ onTap: () {+ if (state.currentPageManager != pm) {+ final index = state.pageManagers.indexOf(pm);+ onIndexChanged(index);+ }+ },+ ),+ ),+ );+ }).toList(),+ ),+ ),+ );+ },);}}