2021-07-24 18:55:13 +08:00
|
|
|
import 'package:app_flowy/workspace/application/home/home_bloc.dart';
|
2021-10-11 13:15:41 +08:00
|
|
|
import 'package:app_flowy/workspace/application/home/home_listen_bloc.dart';
|
2021-07-22 17:06:53 +08:00
|
|
|
import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart';
|
2021-10-11 13:15:41 +08:00
|
|
|
import 'package:app_flowy/workspace/presentation/stack_page/home_stack.dart';
|
2021-07-22 17:06:53 +08:00
|
|
|
import 'package:app_flowy/workspace/presentation/widgets/prelude.dart';
|
2021-07-12 23:27:58 +08:00
|
|
|
import 'package:app_flowy/startup/startup.dart';
|
2021-09-12 23:04:34 +08:00
|
|
|
import 'package:flowy_log/flowy_log.dart';
|
2021-07-28 15:13:48 +08:00
|
|
|
import 'package:flowy_infra_ui/style_widget/container.dart';
|
2021-07-13 14:28:01 +08:00
|
|
|
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart';
|
2021-06-19 23:41:19 +08:00
|
|
|
import 'package:flutter/material.dart';
|
2021-07-12 23:27:58 +08:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
|
import 'package:styled_widget/styled_widget.dart';
|
|
|
|
|
|
|
|
|
|
import 'home_layout.dart';
|
2021-06-19 23:41:19 +08:00
|
|
|
|
2021-10-11 13:15:41 +08:00
|
|
|
// [[diagram: Home's widget structure]]
|
|
|
|
|
// 1.start listening user auth state
|
|
|
|
|
// ┌────────────────┐ ┌──────────────┐
|
|
|
|
|
// ┌─▶│ HomeListenBloc │────────▶│IUserListener │
|
|
|
|
|
// │ └────────────────┘ └──────────────┘
|
|
|
|
|
// ┌────────────┐ │
|
|
|
|
|
// │ HomeScreen │──┤
|
|
|
|
|
// └────────────┘ │ ┌──────────────┐
|
|
|
|
|
// │ ┌───▶│ BlocListener │
|
|
|
|
|
// │ │ └──────────────┘
|
|
|
|
|
// │ ┌─────────┐ │ ┌──────────┐
|
|
|
|
|
// └─▶│HomeBloc │────┤ ┌───▶│HomeStack │
|
|
|
|
|
// └─────────┘ │ │ └──────────┘
|
|
|
|
|
// │ ┌──────────────┐ │ ┌──────────┐
|
|
|
|
|
// └──▶│ BlocBuilder │───┼───▶│ HomeMenu │
|
|
|
|
|
// └──────────────┘ │ └──────────┘
|
|
|
|
|
// │ ┌──────────┐
|
|
|
|
|
// 2.1 show login screen if user └───▶│EditPannel│
|
|
|
|
|
// session is invalid └──────────┘
|
|
|
|
|
//
|
|
|
|
|
// 2.2 build home screen
|
|
|
|
|
//
|
|
|
|
|
//
|
2021-06-19 23:41:19 +08:00
|
|
|
class HomeScreen extends StatelessWidget {
|
|
|
|
|
static GlobalKey<ScaffoldState> scaffoldKey = GlobalKey();
|
2021-09-04 16:53:58 +08:00
|
|
|
final UserProfile user;
|
2021-08-30 16:18:58 +08:00
|
|
|
final String workspaceId;
|
|
|
|
|
const HomeScreen(this.user, this.workspaceId, {Key? key}) : super(key: key);
|
2021-06-19 23:41:19 +08:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2021-07-12 23:27:58 +08:00
|
|
|
return MultiBlocProvider(
|
|
|
|
|
providers: [
|
2021-10-11 13:15:41 +08:00
|
|
|
BlocProvider<HomeListenBloc>(
|
|
|
|
|
create: (context) => getIt<HomeListenBloc>(param1: user)..add(const HomeListenEvent.started()),
|
2021-09-08 18:25:32 +08:00
|
|
|
),
|
2021-07-12 23:27:58 +08:00
|
|
|
BlocProvider<HomeBloc>(create: (context) => getIt<HomeBloc>()),
|
|
|
|
|
],
|
|
|
|
|
child: Scaffold(
|
|
|
|
|
key: HomeScreen.scaffoldKey,
|
2021-10-11 13:15:41 +08:00
|
|
|
body: BlocListener<HomeListenBloc, HomeListenState>(
|
2021-09-08 18:25:32 +08:00
|
|
|
listener: (context, state) {
|
|
|
|
|
state.map(
|
|
|
|
|
loading: (_) {},
|
|
|
|
|
unauthorized: (unauthorized) {
|
2021-09-09 15:43:05 +08:00
|
|
|
// TODO: push to login screen when user token was invalid
|
2021-09-11 20:09:46 +08:00
|
|
|
Log.error("Push to login screen when user token was invalid");
|
2021-09-08 18:25:32 +08:00
|
|
|
},
|
2021-07-12 23:27:58 +08:00
|
|
|
);
|
|
|
|
|
},
|
2021-09-08 18:25:32 +08:00
|
|
|
child: BlocBuilder<HomeBloc, HomeState>(
|
|
|
|
|
buildWhen: (previous, current) => previous != current,
|
|
|
|
|
builder: (context, state) {
|
|
|
|
|
return FlowyContainer(
|
|
|
|
|
Theme.of(context).colorScheme.surface,
|
|
|
|
|
// Colors.white,
|
2021-10-10 11:40:45 +08:00
|
|
|
child: _buildBody(state, context.read<HomeBloc>().state.forceCollapse),
|
2021-09-08 18:25:32 +08:00
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
2021-07-12 23:27:58 +08:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-20 23:51:08 +08:00
|
|
|
Widget _buildBody(HomeState state, bool forceCollapse) {
|
2021-07-12 23:27:58 +08:00
|
|
|
return LayoutBuilder(
|
|
|
|
|
builder: (BuildContext context, BoxConstraints constraints) {
|
2021-07-20 23:51:08 +08:00
|
|
|
final layout = HomeLayout(context, constraints, forceCollapse);
|
2021-10-11 13:15:41 +08:00
|
|
|
const homeStack = HomeStack();
|
2021-07-12 23:27:58 +08:00
|
|
|
final menu = _buildHomeMenu(
|
|
|
|
|
layout: layout,
|
|
|
|
|
context: context,
|
|
|
|
|
);
|
|
|
|
|
final editPannel = _buildEditPannel(
|
|
|
|
|
homeState: state,
|
|
|
|
|
layout: layout,
|
|
|
|
|
context: context,
|
|
|
|
|
);
|
2021-10-11 13:15:41 +08:00
|
|
|
return _layoutWidgets(layout: layout, homeStack: homeStack, homeMenu: menu, editPannel: editPannel);
|
2021-07-12 23:27:58 +08:00
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-10 11:40:45 +08:00
|
|
|
Widget _buildHomeMenu({required HomeLayout layout, required BuildContext context}) {
|
2021-07-12 23:27:58 +08:00
|
|
|
final homeBloc = context.read<HomeBloc>();
|
2021-11-05 14:23:30 +08:00
|
|
|
final collapasedNotifier = getIt<HomeStackManager>().collapsedNotifier;
|
|
|
|
|
|
|
|
|
|
HomeMenu homeMenu = HomeMenu(user: user, workspaceId: workspaceId, collapsedNotifier: collapasedNotifier);
|
|
|
|
|
collapasedNotifier.addPublishListener((isCollapsed) {
|
|
|
|
|
homeBloc.add(HomeEvent.forceCollapse(isCollapsed));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
homeMenu.pageContext.addPublishListener((pageContext) {
|
|
|
|
|
getIt<HomeStackManager>().switchStack(pageContext);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return FocusTraversalGroup(child: RepaintBoundary(child: homeMenu));
|
2021-07-12 23:27:58 +08:00
|
|
|
}
|
|
|
|
|
|
2021-10-10 11:40:45 +08:00
|
|
|
Widget _buildEditPannel({required HomeState homeState, required BuildContext context, required HomeLayout layout}) {
|
2021-07-12 23:27:58 +08:00
|
|
|
final homeBloc = context.read<HomeBloc>();
|
|
|
|
|
Widget editPannel = EditPannel(
|
|
|
|
|
context: homeState.editContext,
|
|
|
|
|
onEndEdit: () => homeBloc.add(const HomeEvent.dismissEditPannel()),
|
|
|
|
|
);
|
|
|
|
|
// editPannel = RepaintBoundary(child: editPannel);
|
|
|
|
|
// editPannel = FocusTraversalGroup(child: editPannel);
|
|
|
|
|
return editPannel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _layoutWidgets(
|
2021-10-11 13:15:41 +08:00
|
|
|
{required HomeLayout layout, required Widget homeMenu, required Widget homeStack, required Widget editPannel}) {
|
2021-07-12 23:27:58 +08:00
|
|
|
return Stack(
|
|
|
|
|
children: [
|
|
|
|
|
homeMenu
|
|
|
|
|
.animatedPanelX(
|
|
|
|
|
closeX: -layout.menuWidth,
|
|
|
|
|
isClosed: !layout.showMenu,
|
|
|
|
|
)
|
2021-10-10 11:40:45 +08:00
|
|
|
.positioned(left: 0, top: 0, width: layout.menuWidth, bottom: 0, animate: true)
|
2021-07-12 23:27:58 +08:00
|
|
|
.animate(layout.animDuration, Curves.easeOut),
|
2021-10-11 13:15:41 +08:00
|
|
|
homeStack
|
2021-07-12 23:27:58 +08:00
|
|
|
.constrained(minWidth: 500)
|
2021-10-10 11:40:45 +08:00
|
|
|
.positioned(left: layout.homePageLOffset, right: layout.homePageROffset, bottom: 0, top: 0, animate: true)
|
2021-07-12 23:27:58 +08:00
|
|
|
.animate(layout.animDuration, Curves.easeOut),
|
|
|
|
|
editPannel
|
|
|
|
|
.animatedPanelX(
|
|
|
|
|
duration: layout.animDuration.inMilliseconds * 0.001,
|
|
|
|
|
closeX: layout.editPannelWidth,
|
|
|
|
|
isClosed: !layout.showEditPannel,
|
|
|
|
|
)
|
2021-10-10 11:40:45 +08:00
|
|
|
.positioned(right: 0, top: 0, bottom: 0, width: layout.editPannelWidth),
|
2021-07-12 23:27:58 +08:00
|
|
|
],
|
2021-06-19 23:41:19 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|