2021-09-07 09:12:03 +00:00
|
|
|
import 'package:app_flowy/startup/startup.dart';
|
|
|
|
import 'package:app_flowy/workspace/application/workspace/welcome_bloc.dart';
|
2021-11-05 08:23:44 +00:00
|
|
|
import 'package:flowy_infra/theme.dart';
|
2021-09-06 08:18:34 +00:00
|
|
|
import 'package:flowy_infra_ui/style_widget/scrolling/styled_list.dart';
|
2021-10-13 15:11:45 +00:00
|
|
|
import 'package:flowy_infra_ui/style_widget/button.dart';
|
2021-09-06 08:18:34 +00:00
|
|
|
import 'package:flowy_infra_ui/widget/error_page.dart';
|
2021-11-08 02:25:10 +00:00
|
|
|
import 'package:flowy_sdk/protobuf/flowy-workspace-infra/workspace_create.pb.dart';
|
2021-06-19 15:41:19 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2021-09-06 08:18:34 +00:00
|
|
|
import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart';
|
2021-06-19 15:41:19 +00:00
|
|
|
|
|
|
|
class WelcomeScreen extends StatelessWidget {
|
2021-09-06 08:18:34 +00:00
|
|
|
final UserRepo repo;
|
|
|
|
const WelcomeScreen({
|
|
|
|
Key? key,
|
|
|
|
required this.repo,
|
|
|
|
}) : super(key: key);
|
2021-06-19 15:41:19 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return BlocProvider(
|
2021-10-13 15:11:45 +00:00
|
|
|
create: (_) => getIt<WelcomeBloc>(param1: repo.user)..add(const WelcomeEvent.initial()),
|
2021-09-07 09:12:03 +00:00
|
|
|
child: BlocBuilder<WelcomeBloc, WelcomeState>(
|
2021-09-06 08:18:34 +00:00
|
|
|
builder: (context, state) {
|
|
|
|
return Scaffold(
|
|
|
|
body: Padding(
|
|
|
|
padding: const EdgeInsets.all(60.0),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
_renderBody(state),
|
|
|
|
_renderCreateButton(context),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2021-06-19 15:41:19 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-09-07 09:12:03 +00:00
|
|
|
Widget _renderBody(WelcomeState state) {
|
2021-09-06 08:18:34 +00:00
|
|
|
final body = state.successOrFailure.fold(
|
|
|
|
(_) => _renderList(state.workspaces),
|
|
|
|
(error) => FlowyErrorPage(error.toString()),
|
|
|
|
);
|
|
|
|
return body;
|
2021-07-12 15:27:58 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 08:18:34 +00:00
|
|
|
Widget _renderCreateButton(BuildContext context) {
|
2021-11-05 08:23:44 +00:00
|
|
|
final theme = context.watch<AppTheme>();
|
|
|
|
|
2021-09-06 08:18:34 +00:00
|
|
|
return SizedBox(
|
|
|
|
width: 200,
|
|
|
|
height: 40,
|
|
|
|
child: FlowyTextButton(
|
|
|
|
"Create workspace",
|
|
|
|
fontSize: 14,
|
2021-11-05 08:23:44 +00:00
|
|
|
hoverColor: theme.bg3,
|
2021-09-06 08:18:34 +00:00
|
|
|
onPressed: () {
|
2021-10-13 15:11:45 +00:00
|
|
|
context.read<WelcomeBloc>().add(const WelcomeEvent.createWorkspace("workspace", ""));
|
2021-09-06 08:18:34 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
2021-07-12 15:27:58 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 08:18:34 +00:00
|
|
|
Widget _renderList(List<Workspace> workspaces) {
|
|
|
|
return Expanded(
|
|
|
|
child: StyledListView(
|
|
|
|
itemBuilder: (BuildContext context, int index) {
|
|
|
|
final workspace = workspaces[index];
|
|
|
|
return WorkspaceItem(
|
|
|
|
workspace: workspace,
|
|
|
|
onPressed: (workspace) => _handleOnPress(context, workspace),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
itemCount: workspaces.length,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _handleOnPress(BuildContext context, Workspace workspace) {
|
2021-09-07 09:12:03 +00:00
|
|
|
context.read<WelcomeBloc>().add(WelcomeEvent.openWorkspace(workspace));
|
2021-07-12 15:27:58 +00:00
|
|
|
|
2021-09-06 08:18:34 +00:00
|
|
|
Navigator.of(context).pop(workspace.id);
|
2021-07-12 15:27:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-06 08:18:34 +00:00
|
|
|
class WorkspaceItem extends StatelessWidget {
|
|
|
|
final Workspace workspace;
|
|
|
|
final void Function(Workspace workspace) onPressed;
|
2021-10-13 15:11:45 +00:00
|
|
|
const WorkspaceItem({Key? key, required this.workspace, required this.onPressed}) : super(key: key);
|
2021-09-06 08:18:34 +00:00
|
|
|
|
2021-07-12 15:27:58 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-11-05 08:23:44 +00:00
|
|
|
final theme = context.watch<AppTheme>();
|
|
|
|
|
2021-09-06 08:18:34 +00:00
|
|
|
return SizedBox(
|
|
|
|
height: 46,
|
|
|
|
child: FlowyTextButton(
|
|
|
|
workspace.name,
|
2021-11-05 08:23:44 +00:00
|
|
|
hoverColor: theme.bg3,
|
2021-09-06 08:18:34 +00:00
|
|
|
fontSize: 14,
|
|
|
|
onPressed: () => onPressed(workspace),
|
2021-07-12 15:27:58 +00:00
|
|
|
),
|
|
|
|
);
|
2021-06-19 15:41:19 +00:00
|
|
|
}
|
|
|
|
}
|