show app list on home screen

This commit is contained in:
appflowy 2021-07-22 12:23:14 +08:00
parent 9b9d462f36
commit 83778635ae
7 changed files with 50 additions and 103 deletions

View File

@ -16,12 +16,7 @@ class AppBloc extends Bloc<AppEvent, AppState> {
AppEvent event,
) async* {
yield* event.map(
initial: (e) async* {
iAppImpl.startWatching(
updatedCallback: (name, desc) {},
addViewCallback: (views) {},
);
},
initial: (e) async* {},
viewsReceived: (e) async* {
yield state;
},

View File

@ -15,7 +15,7 @@ class AppWatchBloc extends Bloc<AppWatchEvent, AppWatchState> {
Stream<AppWatchState> mapEventToState(
AppWatchEvent event,
) async* {
yield* event.map(started: (_) {
yield* event.map(started: (_) async* {
watcher.startWatching(
addViewCallback: (viewsOrFail) => _handleViewsOrFail(viewsOrFail),
);

View File

@ -1,3 +1,5 @@
import 'package:app_flowy/home/application/app/app_bloc.dart';
import 'package:app_flowy/home/application/app/app_watch_bloc.dart';
import 'package:app_flowy/home/application/menu/menu_bloc.dart';
import 'package:app_flowy/home/application/menu/menu_watch.dart';
import 'package:app_flowy/home/infrastructure/i_app_impl.dart';
@ -36,6 +38,10 @@ class HomeDepsResolver {
getIt.registerFactoryParam<MenuWatchBloc, String, void>((workspaceId, _) =>
MenuWatchBloc(getIt<IWorkspaceWatch>(param1: workspaceId)));
getIt.registerFactoryParam<AppBloc, String, void>(
(appId, _) => AppBloc(getIt<IApp>(param1: appId)));
getIt.registerFactoryParam<AppWatchBloc, String, void>(
(appId, _) => AppWatchBloc(getIt<IAppWatch>(param1: appId)));
// AppWatchBloc
}
}

View File

@ -1,77 +0,0 @@
import 'package:app_flowy/home/application/app/app_bloc.dart';
import 'package:app_flowy/startup/startup.dart';
// ignore: import_of_legacy_library_into_null_safe
import 'package:expandable/expandable.dart';
import 'package:flowy_infra/flowy_logger.dart';
import 'package:flowy_sdk/protobuf/flowy-workspace/app_create.pb.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flowy_infra_ui/widget/error_page.dart';
import 'app_widget.dart';
// class AppList extends StatelessWidget {
// const AppList({Key? key}) : super(key: key);
// @override
// Widget build(BuildContext context) {
// return MultiBlocProvider(
// providers: [
// BlocProvider(
// create: (context) => getIt<AppBloc>()..add(const AppEvent.initial()),
// ),
// ],
// child: BlocBuilder<AppBloc, AppState>(
// buildWhen: (p, c) => p.apps != c.apps,
// builder: (context, state) {
// Log.info('AppList build');
// if (state.isLoading) {
// return const Center(
// child: CircularProgressIndicator.adaptive(),
// );
// }
// return state.apps.fold(
// () => state.successOrFailure.fold(
// (_) => const Text('You have no apps, create one?'),
// (error) => FlowyErrorPage(error.toString()),
// ),
// (apps) => _buildBody(apps),
// );
// },
// ),
// );
// }
class AppList extends StatelessWidget {
final List<App> apps;
const AppList({required this.apps, Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ExpandableTheme(
data: const ExpandableThemeData(
iconColor: Colors.blue,
useInkWell: true,
),
child: Expanded(
child: ListView(
physics: const BouncingScrollPhysics(),
children: apps.map((app) => AppWidget(app)).toList(),
),
));
}
// Widget _buildBody(List<App> apps) {
// return ExpandableTheme(
// data: const ExpandableThemeData(
// iconColor: Colors.blue,
// useInkWell: true,
// ),
// child: Expanded(
// child: ListView(
// physics: const BouncingScrollPhysics(),
// children: apps.map((app) => AppWidget(app)).toList(),
// ),
// ));
// }
}

View File

@ -1,4 +1,5 @@
import 'package:app_flowy/home/application/app/app_bloc.dart';
import 'package:app_flowy/home/application/app/app_watch_bloc.dart';
import 'package:app_flowy/home/presentation/widgets/menu/menu_size.dart';
import 'package:app_flowy/startup/startup.dart';
import 'package:expandable/expandable.dart';
@ -15,23 +16,40 @@ class AppWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
// return MultiBlocProvider(
// providers: [
// BlocProvider<AppBloc>(create: (context) => getIt<AppBloc>()),
// ],
// child: BlocBuilder<AppBloc, AppState>(
// builder: (context, state) {
// // final child = state.map(
// // initial: (_) => const CircularProgressIndicator.adaptive(),
// // loadViews: (s) => ViewList(s.views),
// // successOrFailure: (s) => FlowyErrorPage(s.error),
// // );
return MultiBlocProvider(
providers: [
BlocProvider<AppBloc>(
create: (context) => getIt<AppBloc>(param1: app.id)),
BlocProvider<AppWatchBloc>(
create: (context) => getIt<AppWatchBloc>(param1: app.id)),
],
child: BlocBuilder<AppWatchBloc, AppWatchState>(
builder: (context, state) {
final child = state.map(
initial: (_) => BlocBuilder<AppBloc, AppState>(
builder: (context, state) {
return Container();
},
),
loadViews: (s) {
return Container();
// final child = state.map(
// initial: (_) => const CircularProgressIndicator.adaptive(),
// loadViews: (s) => ViewList(s.views),
// successOrFailure: (s) => FlowyErrorPage(s.error),
// );
// return expandableWrapper(context, Container());
// },
// ),
// );
return Container();
// return expandableWrapper(context, Container());
},
loadFail: (s) {
return FlowyErrorPage(s.error.toString());
},
);
return expandableWrapper(context, child);
},
),
);
}
ExpandableNotifier expandableWrapper(BuildContext context, Widget child) {

View File

@ -77,9 +77,13 @@ class HomeMenu extends StatelessWidget {
Widget _renderAppList(BuildContext context) {
return BlocBuilder<MenuWatchBloc, MenuWatchState>(
builder: (context, state) => state.map(
initial: (_) => AppList(apps: context.read<MenuBloc>().state.apps),
loadApps: (event) => AppList(apps: some(event.apps)),
loadFail: (error) => FlowyErrorPage(error.toString()),
initial: (_) => BlocBuilder<MenuBloc, MenuState>(
builder: (context, state) {
return AppList(apps: state.apps);
},
),
loadApps: (s) => AppList(apps: some(s.apps)),
loadFail: (s) => FlowyErrorPage(s.error.toString()),
),
);
}