fix: height for calendar view in document (#3073)

This commit is contained in:
Richard Shiue 2023-08-02 18:07:44 +08:00 committed by GitHub
parent f0d2cf7da3
commit ff79635b2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 49 additions and 29 deletions

View File

@ -46,7 +46,8 @@ class BlankPagePluginWidgetBuilder extends PluginWidgetBuilder
Widget tabBarItem(String pluginId) => leftBarItem;
@override
Widget buildWidget({PluginContext? context}) => const BlankPage();
Widget buildWidget({PluginContext? context, required bool shrinkWrap}) =>
const BlankPage();
@override
List<NavigationItem> get navigationItems => [this];

View File

@ -35,6 +35,7 @@ class BoardPageTabBarBuilderImpl implements DatabaseTabBarItemBuilder {
BuildContext context,
ViewPB view,
DatabaseController controller,
bool shrinkWrap,
) {
return BoardPage(
key: _makeValueKey(controller),

View File

@ -27,11 +27,13 @@ class CalendarPageTabBarBuilderImpl implements DatabaseTabBarItemBuilder {
BuildContext context,
ViewPB view,
DatabaseController controller,
bool shrinkWrap,
) {
return CalendarPage(
key: _makeValueKey(controller),
view: view,
databaseController: controller,
shrinkWrap: shrinkWrap,
);
}
@ -59,9 +61,11 @@ class CalendarPageTabBarBuilderImpl implements DatabaseTabBarItemBuilder {
class CalendarPage extends StatefulWidget {
final ViewPB view;
final DatabaseController databaseController;
final bool shrinkWrap;
const CalendarPage({
required this.view,
required this.databaseController,
this.shrinkWrap = false,
super.key,
});
@ -95,12 +99,8 @@ class _CalendarPageState extends State<CalendarPage> {
Widget build(BuildContext context) {
return CalendarControllerProvider(
controller: _eventController,
child: MultiBlocProvider(
providers: [
BlocProvider<CalendarBloc>.value(
value: _calendarBloc,
)
],
child: BlocProvider<CalendarBloc>.value(
value: _calendarBloc,
child: MultiBlocListener(
listeners: [
BlocListener<CalendarBloc, CalendarState>(
@ -159,14 +159,10 @@ class _CalendarPageState extends State<CalendarPage> {
],
child: BlocBuilder<CalendarBloc, CalendarState>(
builder: (context, state) {
return Column(
children: [
_buildCalendar(
_eventController,
state.settings
.foldLeft(0, (previous, a) => a.firstDayOfWeek),
),
],
return _buildCalendar(
context,
_eventController,
state.settings.foldLeft(0, (previous, a) => a.firstDayOfWeek),
);
},
),
@ -175,19 +171,26 @@ class _CalendarPageState extends State<CalendarPage> {
);
}
Widget _buildCalendar(EventController eventController, int firstDayOfWeek) {
return Expanded(
child: Padding(
padding: GridSize.contentInsets,
child: MonthView(
Widget _buildCalendar(
BuildContext context,
EventController eventController,
int firstDayOfWeek,
) {
return Padding(
padding: GridSize.contentInsets,
child: LayoutBuilder(
// must specify MonthView width for useAvailableVerticalSpace to work properly
builder: (context, constraints) => MonthView(
key: _calendarState,
controller: _eventController,
cellAspectRatio: .6,
width: constraints.maxWidth,
cellAspectRatio: 0.6,
startDay: _weekdayFromInt(firstDayOfWeek),
borderColor: Theme.of(context).dividerColor,
headerBuilder: _headerNavigatorBuilder,
weekDayBuilder: _headerWeekDayBuilder,
cellBuilder: _calendarDayBuilder,
useAvailableVerticalSpace: widget.shrinkWrap,
),
),
);

View File

@ -50,6 +50,7 @@ class GridPageTabBarBuilderImpl implements DatabaseTabBarItemBuilder {
BuildContext context,
ViewPB view,
DatabaseController controller,
bool shrinkWrap,
) {
return GridPage(
key: _makeValueKey(controller),

View File

@ -31,6 +31,7 @@ abstract class DatabaseTabBarItemBuilder {
BuildContext context,
ViewPB view,
DatabaseController controller,
bool shrinkWrap,
);
/// Returns the setting bar of the tab bar item. The setting bar is shown on the
@ -48,8 +49,10 @@ abstract class DatabaseTabBarItemBuilder {
class DatabaseTabBarView extends StatefulWidget {
final ViewPB view;
final bool shrinkWrap;
const DatabaseTabBarView({
required this.view,
required this.shrinkWrap,
super.key,
});
@ -146,6 +149,7 @@ class _DatabaseTabBarViewState extends State<DatabaseTabBarView> {
context,
tabBar.view,
controller,
widget.shrinkWrap,
);
}).toList();
}
@ -215,7 +219,7 @@ class DatabasePluginWidgetBuilder extends PluginWidgetBuilder {
Widget tabBarItem(String pluginId) => ViewTabBarItem(view: notifier.view);
@override
Widget buildWidget({PluginContext? context}) {
Widget buildWidget({PluginContext? context, required bool shrinkWrap}) {
notifier.isDeleted.addListener(() {
notifier.isDeleted.value.fold(() => null, (deletedView) {
if (deletedView.hasIndex()) {
@ -226,6 +230,7 @@ class DatabasePluginWidgetBuilder extends PluginWidgetBuilder {
return DatabaseTabBarView(
key: ValueKey(notifier.view.id),
view: notifier.view,
shrinkWrap: shrinkWrap,
);
}

View File

@ -4,13 +4,15 @@ import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
import 'package:flutter/material.dart';
class DatabaseViewWidget extends StatefulWidget {
final ViewPB view;
final bool shrinkWrap;
const DatabaseViewWidget({
super.key,
required this.view,
this.shrinkWrap = true,
});
final ViewPB view;
@override
State<DatabaseViewWidget> createState() => _DatabaseViewWidgetState();
}
@ -46,7 +48,10 @@ class _DatabaseViewWidgetState extends State<DatabaseViewWidget> {
return ValueListenableBuilder<ViewLayoutPB>(
valueListenable: _layoutTypeChangeNotifier,
builder: (_, __, ___) {
return view.plugin().widgetBuilder.buildWidget();
return view
.plugin()
.widgetBuilder
.buildWidget(shrinkWrap: widget.shrinkWrap);
},
);
}

View File

@ -82,7 +82,7 @@ class DocumentPluginWidgetBuilder extends PluginWidgetBuilder
EdgeInsets get contentPadding => EdgeInsets.zero;
@override
Widget buildWidget({PluginContext? context}) {
Widget buildWidget({PluginContext? context, required bool shrinkWrap}) {
notifier.isDeleted.addListener(() {
notifier.isDeleted.value.fold(() => null, (deletedView) {
if (deletedView.hasIndex()) {

View File

@ -1,4 +1,5 @@
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:appflowy/startup/plugin/plugin.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';
import 'package:appflowy/workspace/application/view/view_service.dart';
@ -90,7 +91,7 @@ class _BuiltInPageWidgetState extends State<BuiltInPageWidget> {
onEnter: (_) => widget.editorState.service.scrollService?.disable(),
onExit: (_) => widget.editorState.service.scrollService?.enable(),
child: SizedBox(
height: 400,
height: viewPB.pluginType == PluginType.calendar ? 700 : 400,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,

View File

@ -78,6 +78,7 @@ class _DatabaseBlockComponentWidgetState
return DatabaseViewWidget(
key: ValueKey(viewPB.id),
view: viewPB,
shrinkWrap: true,
);
},
);

View File

@ -58,7 +58,8 @@ class TrashPluginDisplay extends PluginWidgetBuilder {
Widget? get rightBarItem => null;
@override
Widget buildWidget({PluginContext? context}) => const TrashPage(
Widget buildWidget({PluginContext? context, required bool shrinkWrap}) =>
const TrashPage(
key: ValueKey('TrashPage'),
);

View File

@ -66,7 +66,7 @@ abstract class PluginWidgetBuilder with NavigationItem {
EdgeInsets get contentPadding =>
const EdgeInsets.symmetric(horizontal: 40, vertical: 28);
Widget buildWidget({PluginContext? context});
Widget buildWidget({PluginContext? context, required bool shrinkWrap});
}
class PluginContext {

View File

@ -233,6 +233,7 @@ class PageManager {
final builder = notifier.plugin.widgetBuilder;
final pluginWidget = builder.buildWidget(
context: PluginContext(onDeleted: onDeleted),
shrinkWrap: false,
);
return Padding(