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() {
|
||||
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(
|
||||
|
@ -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<View>? innerViews;
|
||||
ViewListData();
|
||||
|
||||
set views(List<View> views) {
|
||||
innerViews = views;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
List<View> 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<List<View>> some) {
|
||||
List<View> 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<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/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<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 {
|
||||
final List<View> 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<ViewListBloc>(param1: views)..add(ViewListEvent.initial(views)),
|
||||
child: BlocBuilder<ViewListBloc, ViewListState>(
|
||||
builder: (context, state) {
|
||||
return state.views.fold(
|
||||
() => const SizedBox(),
|
||||
(views) => _renderViews(context, views),
|
||||
);
|
||||
},
|
||||
return ChangeNotifierProxyProvider<ViewListData, ViewListNotifier>(
|
||||
create: (_) => ViewListNotifier(
|
||||
Provider.of<ViewListData>(
|
||||
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<ViewListBloc>().add(ViewListEvent.openView(view));
|
||||
context.read<ViewListNotifier>().openView(view);
|
||||
final stackView = stackViewFromView(viewCtx.view);
|
||||
getIt<HomePageStack>().setStackView(stackView);
|
||||
},
|
||||
@ -53,10 +75,11 @@ class ViewList extends StatelessWidget {
|
||||
}
|
||||
|
||||
bool _isViewSelected(BuildContext context, String viewId) {
|
||||
return context
|
||||
.read<ViewListBloc>()
|
||||
.state
|
||||
.selectedView
|
||||
.fold(() => false, (selectedViewId) => viewId == selectedViewId);
|
||||
final view = context.read<ViewListNotifier>().selectedView;
|
||||
if (view != null) {
|
||||
return view.id == viewId;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<NaviItem> get naviItems {
|
||||
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)
|
||||
];
|
||||
return items;
|
||||
}
|
||||
|
@ -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'),
|
||||
|
@ -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:
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user