2021-07-24 18:55:13 +08:00
|
|
|
import 'package:app_flowy/startup/startup.dart';
|
2022-02-05 11:15:24 +08:00
|
|
|
import 'package:app_flowy/workspace/application/appearance.dart';
|
2022-08-09 10:35:27 +08:00
|
|
|
import 'package:app_flowy/plugins/doc/presentation/banner.dart';
|
|
|
|
import 'package:app_flowy/plugins/doc/presentation/toolbar/tool_bar.dart';
|
2021-10-26 22:38:47 +08:00
|
|
|
import 'package:flowy_infra_ui/style_widget/scrolling/styled_scroll_bar.dart';
|
|
|
|
import 'package:flowy_infra_ui/widget/spacing.dart';
|
2021-10-31 19:48:20 +08:00
|
|
|
import 'package:flutter_quill/flutter_quill.dart' as quill;
|
2021-10-19 13:56:11 +08:00
|
|
|
import 'package:flowy_infra_ui/widget/error_page.dart';
|
2022-07-04 15:00:54 +08:00
|
|
|
import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart';
|
2021-07-24 14:05:49 +08:00
|
|
|
import 'package:flutter/material.dart';
|
2021-07-24 18:55:13 +08:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2022-02-05 11:15:24 +08:00
|
|
|
import 'package:provider/provider.dart';
|
2022-08-09 10:35:27 +08:00
|
|
|
import 'application/doc_bloc.dart';
|
2021-10-27 17:46:50 +08:00
|
|
|
import 'styles.dart';
|
2021-10-22 23:49:56 +08:00
|
|
|
|
2022-02-23 22:17:47 +08:00
|
|
|
class DocumentPage extends StatefulWidget {
|
2022-07-19 14:11:29 +08:00
|
|
|
final ViewPB view;
|
2021-07-24 14:05:49 +08:00
|
|
|
|
2022-02-23 22:17:47 +08:00
|
|
|
DocumentPage({Key? key, required this.view}) : super(key: ValueKey(view.id));
|
2021-07-24 14:05:49 +08:00
|
|
|
|
2021-10-08 16:58:58 +08:00
|
|
|
@override
|
2022-02-23 22:17:47 +08:00
|
|
|
State<DocumentPage> createState() => _DocumentPageState();
|
2021-10-08 16:58:58 +08:00
|
|
|
}
|
|
|
|
|
2022-02-23 22:17:47 +08:00
|
|
|
class _DocumentPageState extends State<DocumentPage> {
|
|
|
|
late DocumentBloc documentBloc;
|
2021-10-26 22:38:47 +08:00
|
|
|
final scrollController = ScrollController();
|
2021-10-08 16:58:58 +08:00
|
|
|
final FocusNode _focusNode = FocusNode();
|
|
|
|
|
2021-10-19 13:56:11 +08:00
|
|
|
@override
|
|
|
|
void initState() {
|
2022-08-09 10:35:27 +08:00
|
|
|
documentBloc = getIt<DocumentBloc>(param1: super.widget.view)
|
|
|
|
..add(const DocumentEvent.initial());
|
2021-10-19 13:56:11 +08:00
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
2021-07-24 18:55:13 +08:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-10-19 13:56:11 +08:00
|
|
|
return MultiBlocProvider(
|
|
|
|
providers: [
|
2022-02-23 22:17:47 +08:00
|
|
|
BlocProvider<DocumentBloc>.value(value: documentBloc),
|
2021-10-19 13:56:11 +08:00
|
|
|
],
|
2022-08-09 10:35:27 +08:00
|
|
|
child:
|
|
|
|
BlocBuilder<DocumentBloc, DocumentState>(builder: (context, state) {
|
2022-02-23 22:17:47 +08:00
|
|
|
return state.loadingState.map(
|
2021-11-03 13:52:33 +08:00
|
|
|
// loading: (_) => const FlowyProgressIndicator(),
|
2022-08-09 10:35:27 +08:00
|
|
|
loading: (_) =>
|
|
|
|
SizedBox.expand(child: Container(color: Colors.transparent)),
|
2021-10-19 13:56:11 +08:00
|
|
|
finish: (result) => result.successOrFail.fold(
|
2021-10-31 20:27:37 +08:00
|
|
|
(_) {
|
|
|
|
if (state.forceClose) {
|
|
|
|
return _renderAppPage();
|
|
|
|
} else {
|
2022-02-23 22:17:47 +08:00
|
|
|
return _renderDocument(context, state);
|
2021-10-31 20:27:37 +08:00
|
|
|
}
|
|
|
|
},
|
2021-10-19 13:56:11 +08:00
|
|
|
(err) => FlowyErrorPage(err.toString()),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}),
|
2021-07-24 14:05:49 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-10-08 16:58:58 +08:00
|
|
|
@override
|
|
|
|
Future<void> dispose() async {
|
2022-02-23 22:17:47 +08:00
|
|
|
documentBloc.close();
|
2022-03-29 22:58:38 +08:00
|
|
|
_focusNode.dispose();
|
2021-10-08 16:58:58 +08:00
|
|
|
super.dispose();
|
2021-10-19 13:56:11 +08:00
|
|
|
}
|
|
|
|
|
2022-02-23 22:17:47 +08:00
|
|
|
Widget _renderDocument(BuildContext context, DocumentState state) {
|
2021-10-31 19:48:20 +08:00
|
|
|
quill.QuillController controller = quill.QuillController(
|
2022-02-23 22:17:47 +08:00
|
|
|
document: context.read<DocumentBloc>().document,
|
2021-10-19 13:56:11 +08:00
|
|
|
selection: const TextSelection.collapsed(offset: 0),
|
|
|
|
);
|
|
|
|
return Column(
|
|
|
|
children: [
|
2021-10-31 19:48:20 +08:00
|
|
|
if (state.isDeleted) _renderBanner(context),
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
_renderEditor(controller),
|
|
|
|
const VSpace(10),
|
|
|
|
_renderToolbar(controller),
|
|
|
|
const VSpace(10),
|
|
|
|
],
|
2022-03-07 20:51:13 +08:00
|
|
|
),
|
2021-10-31 19:48:20 +08:00
|
|
|
),
|
2021-10-19 13:56:11 +08:00
|
|
|
],
|
2021-10-31 19:48:20 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _renderBanner(BuildContext context) {
|
2022-02-23 22:17:47 +08:00
|
|
|
return DocumentBanner(
|
2022-08-09 10:35:27 +08:00
|
|
|
onRestore: () =>
|
|
|
|
context.read<DocumentBloc>().add(const DocumentEvent.restorePage()),
|
|
|
|
onDelete: () => context
|
|
|
|
.read<DocumentBloc>()
|
|
|
|
.add(const DocumentEvent.deletePermanently()),
|
2021-10-31 19:48:20 +08:00
|
|
|
);
|
2021-10-08 16:58:58 +08:00
|
|
|
}
|
|
|
|
|
2021-10-31 19:48:20 +08:00
|
|
|
Widget _renderEditor(quill.QuillController controller) {
|
|
|
|
final editor = quill.QuillEditor(
|
2021-07-24 14:05:49 +08:00
|
|
|
controller: controller,
|
|
|
|
focusNode: _focusNode,
|
|
|
|
scrollable: true,
|
2021-11-23 12:22:43 +05:30
|
|
|
paintCursorAboveText: true,
|
2021-10-25 19:25:58 +08:00
|
|
|
autoFocus: controller.document.isEmpty(),
|
2021-07-24 14:05:49 +08:00
|
|
|
expands: false,
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
|
|
|
readOnly: false,
|
|
|
|
scrollBottomInset: 0,
|
2021-10-26 22:38:47 +08:00
|
|
|
scrollController: scrollController,
|
2021-10-27 17:46:50 +08:00
|
|
|
customStyles: customStyles(context),
|
2021-07-24 14:05:49 +08:00
|
|
|
);
|
2021-10-26 22:38:47 +08:00
|
|
|
|
2021-07-26 16:35:51 +08:00
|
|
|
return Expanded(
|
2021-10-26 22:38:47 +08:00
|
|
|
child: ScrollbarListStack(
|
|
|
|
axis: Axis.vertical,
|
|
|
|
controller: scrollController,
|
|
|
|
barSize: 6.0,
|
2021-10-27 16:57:23 +08:00
|
|
|
child: SizedBox.expand(child: editor),
|
2021-10-26 22:38:47 +08:00
|
|
|
),
|
2021-07-26 16:35:51 +08:00
|
|
|
);
|
2021-07-24 14:05:49 +08:00
|
|
|
}
|
|
|
|
|
2021-10-31 19:48:20 +08:00
|
|
|
Widget _renderToolbar(quill.QuillController controller) {
|
2022-02-05 11:15:24 +08:00
|
|
|
return ChangeNotifierProvider.value(
|
|
|
|
value: Provider.of<AppearanceSettingModel>(context, listen: true),
|
|
|
|
child: EditorToolbar.basic(
|
|
|
|
controller: controller,
|
|
|
|
),
|
2021-07-24 14:05:49 +08:00
|
|
|
);
|
|
|
|
}
|
2021-10-31 20:27:37 +08:00
|
|
|
|
|
|
|
Widget _renderAppPage() {
|
|
|
|
return Container(
|
|
|
|
color: Colors.black,
|
|
|
|
);
|
|
|
|
}
|
2021-07-24 14:05:49 +08:00
|
|
|
}
|