diff --git a/app_flowy/lib/workspace/domain/page_stack/page_stack.dart b/app_flowy/lib/workspace/domain/page_stack/page_stack.dart index 81c08086b5..a073e7ec1a 100644 --- a/app_flowy/lib/workspace/domain/page_stack/page_stack.dart +++ b/app_flowy/lib/workspace/domain/page_stack/page_stack.dart @@ -48,7 +48,7 @@ class HomePageStack { Widget stackTopBar() { return MultiProvider( providers: [ - ChangeNotifierProvider(create: (_) => _notifier), + ChangeNotifierProvider.value(value: _notifier), ], child: Consumer(builder: (ctx, PageStackNotifier notifier, child) { return HomeTopBar(view: notifier.view); @@ -59,7 +59,7 @@ class HomePageStack { Widget stackWidget() { return MultiProvider( providers: [ - ChangeNotifierProvider(create: (_) => _notifier), + ChangeNotifierProvider.value(value: _notifier), ], child: Consumer(builder: (ctx, PageStackNotifier notifier, child) { return FadingIndexedStack( diff --git a/app_flowy/lib/workspace/presentation/app/app_widget.dart b/app_flowy/lib/workspace/presentation/app/app_widget.dart index 5821b625b1..9d29712e9c 100644 --- a/app_flowy/lib/workspace/presentation/app/app_widget.dart +++ b/app_flowy/lib/workspace/presentation/app/app_widget.dart @@ -1,18 +1,18 @@ -import 'package:app_flowy/workspace/application/app/app_bloc.dart'; -import 'package:app_flowy/workspace/application/app/app_watch_bloc.dart'; -import 'package:app_flowy/workspace/presentation/app/view_list.dart'; -import 'package:app_flowy/workspace/presentation/widgets/menu/menu_list.dart'; -import 'package:app_flowy/startup/startup.dart'; +import 'package:dartz/dartz.dart'; import 'package:expandable/expandable.dart'; import 'package:flowy_infra_ui/widget/error_page.dart'; -import 'package:flowy_infra_ui/widget/spacing.dart'; -import 'package:flowy_infra_ui/style_widget/text_button.dart'; -import 'package:flowy_infra_ui/style_widget/icon_button.dart'; import 'package:flowy_sdk/protobuf/flowy-workspace/app_create.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:dartz/dartz.dart'; + +import 'package:app_flowy/startup/startup.dart'; +import 'package:app_flowy/workspace/application/app/app_bloc.dart'; +import 'package:app_flowy/workspace/application/app/app_watch_bloc.dart'; +import 'package:app_flowy/workspace/presentation/app/view_list.dart'; +import 'package:app_flowy/workspace/presentation/widgets/menu/menu_list.dart'; +import 'package:provider/provider.dart'; +import 'app_header.dart'; class AppWidgetSize { static double expandedIconSize = 24; @@ -22,10 +22,25 @@ class AppWidgetSize { expandedIconSize * scale + expandedIconRightSpace; } +class ViewListData extends ChangeNotifier { + List? innerViews; + ViewListData(); + + set views(List views) { + innerViews = views; + notifyListeners(); + } + + List get views => innerViews ?? []; +} + class AppWidgetContext { final App app; + final viewListData = ViewListData(); - AppWidgetContext(this.app); + AppWidgetContext( + this.app, + ); Key valueKey() => ValueKey("${app.id}${app.version}"); } @@ -92,90 +107,27 @@ class AppWidget extends MenuItem { } Widget _renderViewList(Option> some) { - List views = some.fold( - () => List.empty(growable: true), - (views) => views, + some.fold( + () { + appCtx.viewListData.views = List.empty(growable: true); + }, + (views) { + appCtx.viewListData.views = views; + }, ); - return Padding( - padding: const EdgeInsets.symmetric(vertical: 8), - child: ViewList(views)); + return MultiProvider( + providers: [ + ChangeNotifierProvider.value(value: appCtx.viewListData), + ], + child: Consumer(builder: (context, ViewListData notifier, child) { + return Padding( + padding: const EdgeInsets.symmetric(vertical: 8), + child: ViewList(notifier.views)); + }), + ); } @override MenuItemType get type => MenuItemType.app; } - -class AppHeader extends StatelessWidget { - final App app; - const AppHeader( - this.app, { - Key? key, - }) : super(key: key); - - @override - Widget build(BuildContext context) { - return Row( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - InkWell( - onTap: () { - ExpandableController.of(context, - rebuildOnChange: false, required: true) - ?.toggle(); - }, - child: ExpandableIcon( - theme: ExpandableThemeData( - expandIcon: Icons.arrow_drop_up, - collapseIcon: Icons.arrow_drop_down, - iconColor: Colors.black, - iconSize: AppWidgetSize.expandedIconSize, - iconPadding: EdgeInsets.zero, - hasIcon: false, - ), - ), - ), - HSpace(AppWidgetSize.expandedIconRightSpace), - Expanded( - child: FlowyTextButton( - app.name, - onPressed: () { - debugPrint('show app document'); - }, - ), - ), - // StyledIconButton( - // icon: const Icon(Icons.add), - // onPressed: () { - // debugPrint('add view'); - // }, - // ), - PopupMenuButton( - iconSize: 20, - tooltip: 'create new view', - icon: const Icon(Icons.add), - padding: EdgeInsets.zero, - onSelected: (viewType) => - _createView(viewType as ViewType, context), - itemBuilder: (context) => menuItemBuilder()) - ], - ); - } - - List menuItemBuilder() { - return ViewType.values - .where((element) => element != ViewType.Blank) - .map((ty) { - return PopupMenuItem( - value: ty, - child: Row( - children: [Text(ty.name)], - )); - }).toList(); - } - - void _createView(ViewType viewType, BuildContext context) { - context.read().add(AppEvent.createView("New view", "", viewType)); - } -} diff --git a/app_flowy/lib/workspace/presentation/app/view_list.dart b/app_flowy/lib/workspace/presentation/app/view_list.dart index d765037d91..7dd61bc579 100644 --- a/app_flowy/lib/workspace/presentation/app/view_list.dart +++ b/app_flowy/lib/workspace/presentation/app/view_list.dart @@ -1,29 +1,51 @@ -import 'package:app_flowy/startup/startup.dart'; -import 'package:app_flowy/workspace/application/view/view_list_bloc.dart'; -import 'package:app_flowy/workspace/presentation/view/view_widget.dart'; +import 'package:app_flowy/workspace/presentation/app/app_widget.dart'; import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart'; -import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:provider/provider.dart'; +import 'package:app_flowy/startup/startup.dart'; +import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; +import 'package:app_flowy/workspace/presentation/view/view_widget.dart'; + +class ViewListNotifier with ChangeNotifier { + List innerViews; + View? _selectedView; + ViewListNotifier(this.innerViews); + + set views(List views) => innerViews = views; + List get views => innerViews; + + void openView(View view) { + _selectedView = view; + notifyListeners(); + } + + View? get selectedView => _selectedView; + + void update(ViewListData notifier) { + innerViews = notifier.views; + notifyListeners(); + } +} class ViewList extends StatelessWidget { final List views; - ViewList(this.views, {Key? key}) : super(key: UniqueKey()); + const ViewList(this.views, {Key? key}) : super(key: key); @override Widget build(BuildContext context) { - return BlocProvider( - create: (context) => - getIt(param1: views)..add(ViewListEvent.initial(views)), - child: BlocBuilder( - builder: (context, state) { - return state.views.fold( - () => const SizedBox(), - (views) => _renderViews(context, views), - ); - }, + return ChangeNotifierProxyProvider( + create: (_) => ViewListNotifier( + Provider.of( + context, + listen: false, + ).views, ), + update: (_, notifier, controller) => controller!..update(notifier), + child: Consumer(builder: (context, ViewListNotifier notifier, child) { + return _renderViews(context, notifier.views); + }), ); } @@ -35,7 +57,7 @@ class ViewList extends StatelessWidget { final viewWidget = ViewWidget( viewCtx: viewCtx, onOpen: (view) { - context.read().add(ViewListEvent.openView(view)); + context.read().openView(view); final stackView = stackViewFromView(viewCtx.view); getIt().setStackView(stackView); }, @@ -53,10 +75,11 @@ class ViewList extends StatelessWidget { } bool _isViewSelected(BuildContext context, String viewId) { - return context - .read() - .state - .selectedView - .fold(() => false, (selectedViewId) => viewId == selectedViewId); + final view = context.read().selectedView; + if (view != null) { + return view.id == viewId; + } else { + return false; + } } } diff --git a/app_flowy/lib/workspace/presentation/home/navigation_list.dart b/app_flowy/lib/workspace/presentation/home/navigation_list.dart index 9b96ec02f4..0a758aafeb 100644 --- a/app_flowy/lib/workspace/presentation/home/navigation_list.dart +++ b/app_flowy/lib/workspace/presentation/home/navigation_list.dart @@ -1,6 +1,5 @@ import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; import 'package:app_flowy/workspace/presentation/widgets/home_top_bar.dart'; -import 'package:flowy_infra_ui/style_widget/text.dart'; import 'package:flowy_infra_ui/style_widget/text_button.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; @@ -14,7 +13,7 @@ abstract class NaviItem { NaviAction get action; } -class NavigationNotifier extends ChangeNotifier { +class NavigationNotifier with ChangeNotifier { PageStackNotifier pageStackNotifier; NavigationNotifier(this.pageStackNotifier); @@ -26,11 +25,11 @@ class NavigationNotifier extends ChangeNotifier { List get naviItems { List items = [ ViewNaviItemImpl(pageStackNotifier.view), - ViewNaviItemImpl(pageStackNotifier.view), - ViewNaviItemImpl(pageStackNotifier.view), - ViewNaviItemImpl(pageStackNotifier.view), - ViewNaviItemImpl(pageStackNotifier.view), - ViewNaviItemImpl(pageStackNotifier.view) + // ViewNaviItemImpl(pageStackNotifier.view), + // ViewNaviItemImpl(pageStackNotifier.view), + // ViewNaviItemImpl(pageStackNotifier.view), + // ViewNaviItemImpl(pageStackNotifier.view), + // ViewNaviItemImpl(pageStackNotifier.view) ]; return items; } diff --git a/app_flowy/packages/flowy_infra_ui/example/lib/overlay/overlay_screen.dart b/app_flowy/packages/flowy_infra_ui/example/lib/overlay/overlay_screen.dart index d2f12ecec8..b6a62f64cd 100644 --- a/app_flowy/packages/flowy_infra_ui/example/lib/overlay/overlay_screen.dart +++ b/app_flowy/packages/flowy_infra_ui/example/lib/overlay/overlay_screen.dart @@ -45,11 +45,11 @@ class OverlayScreen extends StatelessWidget { ElevatedButton( onPressed: () { FlowyOverlay.of(context).insert( - const FlutterLogo( + widget: const FlutterLogo( size: 200, ), - 'overlay_flutter_logo', - null, + identifier: 'overlay_flutter_logo', + delegate: null, ); }, child: const Text('Show Overlay'), diff --git a/app_flowy/packages/flowy_infra_ui/example/pubspec.lock b/app_flowy/packages/flowy_infra_ui/example/pubspec.lock index 1112e4e628..eb9c1f5d57 100644 --- a/app_flowy/packages/flowy_infra_ui/example/pubspec.lock +++ b/app_flowy/packages/flowy_infra_ui/example/pubspec.lock @@ -14,7 +14,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.6.1" + version: "2.7.0" boolean_selector: dependency: transitive description: @@ -35,7 +35,7 @@ packages: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" clock: dependency: transitive description: @@ -183,7 +183,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.7.0" nested: dependency: transitive description: @@ -265,7 +265,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.3.0" + version: "0.4.1" textstyle_extensions: dependency: transitive description: diff --git a/app_flowy/packages/flowy_infra_ui/pubspec.lock b/app_flowy/packages/flowy_infra_ui/pubspec.lock index 7d9d69a09c..7c78eced5a 100644 --- a/app_flowy/packages/flowy_infra_ui/pubspec.lock +++ b/app_flowy/packages/flowy_infra_ui/pubspec.lock @@ -14,7 +14,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.6.1" + version: "2.7.0" boolean_selector: dependency: transitive description: @@ -35,7 +35,7 @@ packages: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" clock: dependency: transitive description: @@ -169,7 +169,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.7.0" nested: dependency: transitive description: @@ -251,7 +251,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.3.0" + version: "0.4.1" textstyle_extensions: dependency: "direct main" description: