mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
connect app_widge with viewlist via provider
This commit is contained in:
parent
23ac4d0249
commit
20ec4c448c
@ -48,7 +48,7 @@ class HomePageStack {
|
|||||||
Widget stackTopBar() {
|
Widget stackTopBar() {
|
||||||
return MultiProvider(
|
return MultiProvider(
|
||||||
providers: [
|
providers: [
|
||||||
ChangeNotifierProvider(create: (_) => _notifier),
|
ChangeNotifierProvider.value(value: _notifier),
|
||||||
],
|
],
|
||||||
child: Consumer(builder: (ctx, PageStackNotifier notifier, child) {
|
child: Consumer(builder: (ctx, PageStackNotifier notifier, child) {
|
||||||
return HomeTopBar(view: notifier.view);
|
return HomeTopBar(view: notifier.view);
|
||||||
@ -59,7 +59,7 @@ class HomePageStack {
|
|||||||
Widget stackWidget() {
|
Widget stackWidget() {
|
||||||
return MultiProvider(
|
return MultiProvider(
|
||||||
providers: [
|
providers: [
|
||||||
ChangeNotifierProvider(create: (_) => _notifier),
|
ChangeNotifierProvider.value(value: _notifier),
|
||||||
],
|
],
|
||||||
child: Consumer(builder: (ctx, PageStackNotifier notifier, child) {
|
child: Consumer(builder: (ctx, PageStackNotifier notifier, child) {
|
||||||
return FadingIndexedStack(
|
return FadingIndexedStack(
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
import 'package:app_flowy/workspace/application/app/app_bloc.dart';
|
import 'package:dartz/dartz.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:expandable/expandable.dart';
|
import 'package:expandable/expandable.dart';
|
||||||
import 'package:flowy_infra_ui/widget/error_page.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/app_create.pb.dart';
|
||||||
import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart';
|
import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.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 {
|
class AppWidgetSize {
|
||||||
static double expandedIconSize = 24;
|
static double expandedIconSize = 24;
|
||||||
@ -22,10 +22,25 @@ class AppWidgetSize {
|
|||||||
expandedIconSize * scale + expandedIconRightSpace;
|
expandedIconSize * scale + expandedIconRightSpace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ViewListData extends ChangeNotifier {
|
||||||
|
List<View>? innerViews;
|
||||||
|
ViewListData();
|
||||||
|
|
||||||
|
set views(List<View> views) {
|
||||||
|
innerViews = views;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<View> get views => innerViews ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
class AppWidgetContext {
|
class AppWidgetContext {
|
||||||
final App app;
|
final App app;
|
||||||
|
final viewListData = ViewListData();
|
||||||
|
|
||||||
AppWidgetContext(this.app);
|
AppWidgetContext(
|
||||||
|
this.app,
|
||||||
|
);
|
||||||
|
|
||||||
Key valueKey() => ValueKey("${app.id}${app.version}");
|
Key valueKey() => ValueKey("${app.id}${app.version}");
|
||||||
}
|
}
|
||||||
@ -92,90 +107,27 @@ class AppWidget extends MenuItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _renderViewList(Option<List<View>> some) {
|
Widget _renderViewList(Option<List<View>> some) {
|
||||||
List<View> views = some.fold(
|
some.fold(
|
||||||
() => List.empty(growable: true),
|
() {
|
||||||
(views) => views,
|
appCtx.viewListData.views = List.empty(growable: true);
|
||||||
|
},
|
||||||
|
(views) {
|
||||||
|
appCtx.viewListData.views = views;
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
return Padding(
|
return MultiProvider(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
providers: [
|
||||||
child: ViewList(views));
|
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
|
@override
|
||||||
MenuItemType get type => MenuItemType.app;
|
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<PopupMenuEntry> menuItemBuilder() {
|
|
||||||
return ViewType.values
|
|
||||||
.where((element) => element != ViewType.Blank)
|
|
||||||
.map((ty) {
|
|
||||||
return PopupMenuItem<ViewType>(
|
|
||||||
value: ty,
|
|
||||||
child: Row(
|
|
||||||
children: <Widget>[Text(ty.name)],
|
|
||||||
));
|
|
||||||
}).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _createView(ViewType viewType, BuildContext context) {
|
|
||||||
context.read<AppBloc>().add(AppEvent.createView("New view", "", viewType));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,29 +1,51 @@
|
|||||||
import 'package:app_flowy/startup/startup.dart';
|
import 'package:app_flowy/workspace/presentation/app/app_widget.dart';
|
||||||
import 'package:app_flowy/workspace/application/view/view_list_bloc.dart';
|
|
||||||
import 'package:app_flowy/workspace/presentation/view/view_widget.dart';
|
|
||||||
import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.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/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.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<View> innerViews;
|
||||||
|
View? _selectedView;
|
||||||
|
ViewListNotifier(this.innerViews);
|
||||||
|
|
||||||
|
set views(List<View> views) => innerViews = views;
|
||||||
|
List<View> 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 {
|
class ViewList extends StatelessWidget {
|
||||||
final List<View> views;
|
final List<View> views;
|
||||||
ViewList(this.views, {Key? key}) : super(key: UniqueKey());
|
const ViewList(this.views, {Key? key}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return ChangeNotifierProxyProvider<ViewListData, ViewListNotifier>(
|
||||||
create: (context) =>
|
create: (_) => ViewListNotifier(
|
||||||
getIt<ViewListBloc>(param1: views)..add(ViewListEvent.initial(views)),
|
Provider.of<ViewListData>(
|
||||||
child: BlocBuilder<ViewListBloc, ViewListState>(
|
context,
|
||||||
builder: (context, state) {
|
listen: false,
|
||||||
return state.views.fold(
|
).views,
|
||||||
() => const SizedBox(),
|
|
||||||
(views) => _renderViews(context, 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(
|
final viewWidget = ViewWidget(
|
||||||
viewCtx: viewCtx,
|
viewCtx: viewCtx,
|
||||||
onOpen: (view) {
|
onOpen: (view) {
|
||||||
context.read<ViewListBloc>().add(ViewListEvent.openView(view));
|
context.read<ViewListNotifier>().openView(view);
|
||||||
final stackView = stackViewFromView(viewCtx.view);
|
final stackView = stackViewFromView(viewCtx.view);
|
||||||
getIt<HomePageStack>().setStackView(stackView);
|
getIt<HomePageStack>().setStackView(stackView);
|
||||||
},
|
},
|
||||||
@ -53,10 +75,11 @@ class ViewList extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool _isViewSelected(BuildContext context, String viewId) {
|
bool _isViewSelected(BuildContext context, String viewId) {
|
||||||
return context
|
final view = context.read<ViewListNotifier>().selectedView;
|
||||||
.read<ViewListBloc>()
|
if (view != null) {
|
||||||
.state
|
return view.id == viewId;
|
||||||
.selectedView
|
} else {
|
||||||
.fold(() => false, (selectedViewId) => viewId == selectedViewId);
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart';
|
import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart';
|
||||||
import 'package:app_flowy/workspace/presentation/widgets/home_top_bar.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:flowy_infra_ui/style_widget/text_button.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
@ -14,7 +13,7 @@ abstract class NaviItem {
|
|||||||
NaviAction get action;
|
NaviAction get action;
|
||||||
}
|
}
|
||||||
|
|
||||||
class NavigationNotifier extends ChangeNotifier {
|
class NavigationNotifier with ChangeNotifier {
|
||||||
PageStackNotifier pageStackNotifier;
|
PageStackNotifier pageStackNotifier;
|
||||||
NavigationNotifier(this.pageStackNotifier);
|
NavigationNotifier(this.pageStackNotifier);
|
||||||
|
|
||||||
@ -26,11 +25,11 @@ class NavigationNotifier extends ChangeNotifier {
|
|||||||
List<NaviItem> get naviItems {
|
List<NaviItem> get naviItems {
|
||||||
List<NaviItem> items = [
|
List<NaviItem> 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)
|
// ViewNaviItemImpl(pageStackNotifier.view)
|
||||||
];
|
];
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
@ -45,11 +45,11 @@ class OverlayScreen extends StatelessWidget {
|
|||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
FlowyOverlay.of(context).insert(
|
FlowyOverlay.of(context).insert(
|
||||||
const FlutterLogo(
|
widget: const FlutterLogo(
|
||||||
size: 200,
|
size: 200,
|
||||||
),
|
),
|
||||||
'overlay_flutter_logo',
|
identifier: 'overlay_flutter_logo',
|
||||||
null,
|
delegate: null,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: const Text('Show Overlay'),
|
child: const Text('Show Overlay'),
|
||||||
|
@ -14,7 +14,7 @@ packages:
|
|||||||
name: async
|
name: async
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.6.1"
|
version: "2.7.0"
|
||||||
boolean_selector:
|
boolean_selector:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -35,7 +35,7 @@ packages:
|
|||||||
name: charcode
|
name: charcode
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.2.0"
|
version: "1.3.1"
|
||||||
clock:
|
clock:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -183,7 +183,7 @@ packages:
|
|||||||
name: meta
|
name: meta
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.0"
|
version: "1.7.0"
|
||||||
nested:
|
nested:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -265,7 +265,7 @@ packages:
|
|||||||
name: test_api
|
name: test_api
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.3.0"
|
version: "0.4.1"
|
||||||
textstyle_extensions:
|
textstyle_extensions:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -14,7 +14,7 @@ packages:
|
|||||||
name: async
|
name: async
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.6.1"
|
version: "2.7.0"
|
||||||
boolean_selector:
|
boolean_selector:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -35,7 +35,7 @@ packages:
|
|||||||
name: charcode
|
name: charcode
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.2.0"
|
version: "1.3.1"
|
||||||
clock:
|
clock:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -169,7 +169,7 @@ packages:
|
|||||||
name: meta
|
name: meta
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.0"
|
version: "1.7.0"
|
||||||
nested:
|
nested:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -251,7 +251,7 @@ packages:
|
|||||||
name: test_api
|
name: test_api
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.3.0"
|
version: "0.4.1"
|
||||||
textstyle_extensions:
|
textstyle_extensions:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
Loading…
Reference in New Issue
Block a user