Skip to content

Commit 893b6e0

Browse files
committed
fix: show multi-line in row detail page
1 parent 1f2b30a commit 893b6e0

File tree

5 files changed

+88
-76
lines changed

5 files changed

+88
-76
lines changed

frontend/app_flowy/lib/plugins/grid/application/field/field_editor_bloc.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ class FieldEditorBloc extends Bloc<FieldEditorEvent, FieldEditorState> {
3333
await dataController.loadTypeOptionData();
3434
},
3535
updateName: (name) {
36-
dataController.fieldName = name;
37-
emit(state.copyWith(name: name));
36+
if (state.name != name) {
37+
dataController.fieldName = name;
38+
emit(state.copyWith(name: name));
39+
}
3840
},
3941
didReceiveFieldChanged: (FieldPB field) {
4042
emit(state.copyWith(

frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/field_cell.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,11 @@ class _DragToExpandLine extends StatelessWidget {
137137
class FieldCellButton extends StatelessWidget {
138138
final VoidCallback onTap;
139139
final FieldPB field;
140+
final int? maxLines;
140141
const FieldCellButton({
141142
required this.field,
142143
required this.onTap,
144+
this.maxLines = 1,
143145
Key? key,
144146
}) : super(key: key);
145147

@@ -150,7 +152,11 @@ class FieldCellButton extends StatelessWidget {
150152
hoverColor: theme.shader6,
151153
onTap: onTap,
152154
leftIcon: svgWidget(field.fieldType.iconName(), color: theme.iconColor),
153-
text: FlowyText.medium(field.name, fontSize: 12),
155+
text: FlowyText.medium(
156+
field.name,
157+
fontSize: 12,
158+
maxLines: maxLines,
159+
),
154160
margin: GridSize.cellContentInsets,
155161
);
156162
}

frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/field_editor.dart

Lines changed: 46 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import 'package:app_flowy/plugins/grid/application/field/field_editor_bloc.dart';
22
import 'package:app_flowy/plugins/grid/application/field/type_option/type_option_context.dart';
33
import 'package:appflowy_popover/appflowy_popover.dart';
4+
import 'package:dartz/dartz.dart' show none;
45
import 'package:easy_localization/easy_localization.dart';
5-
import 'package:app_flowy/workspace/presentation/widgets/dialogs.dart';
66
import 'package:flowy_infra/theme.dart';
7-
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
87
import 'package:flowy_infra_ui/style_widget/button.dart';
98
import 'package:flowy_infra_ui/style_widget/text.dart';
109
import 'package:flowy_infra_ui/widget/rounded_input_field.dart';
@@ -59,38 +58,38 @@ class _FieldEditorState extends State<FieldEditor> {
5958
isGroupField: widget.isGroupField,
6059
loader: widget.typeOptionLoader,
6160
)..add(const FieldEditorEvent.initial()),
62-
child: BlocBuilder<FieldEditorBloc, FieldEditorState>(
63-
builder: (context, state) {
64-
return ListView(
65-
shrinkWrap: true,
66-
children: [
67-
FlowyText.medium(
68-
LocaleKeys.grid_field_editProperty.tr(),
69-
fontSize: 12,
70-
),
71-
const VSpace(10),
72-
_FieldNameTextField(popoverMutex: popoverMutex),
73-
const VSpace(10),
74-
..._addDeleteFieldButton(state),
75-
_FieldTypeOptionCell(popoverMutex: popoverMutex),
76-
],
77-
);
78-
},
61+
child: ListView(
62+
shrinkWrap: true,
63+
children: [
64+
FlowyText.medium(
65+
LocaleKeys.grid_field_editProperty.tr(),
66+
fontSize: 12,
67+
),
68+
const VSpace(10),
69+
_FieldNameTextField(popoverMutex: popoverMutex),
70+
const VSpace(10),
71+
..._addDeleteFieldButton(),
72+
_FieldTypeOptionCell(popoverMutex: popoverMutex),
73+
],
7974
),
8075
);
8176
}
8277

83-
List<Widget> _addDeleteFieldButton(FieldEditorState state) {
78+
List<Widget> _addDeleteFieldButton() {
8479
if (widget.onDeleted == null) {
8580
return [];
8681
}
8782
return [
88-
_DeleteFieldButton(
89-
popoverMutex: popoverMutex,
90-
onDeleted: () {
91-
state.field.fold(
92-
() => Log.error('Can not delete the field'),
93-
(field) => widget.onDeleted?.call(field.id),
83+
BlocBuilder<FieldEditorBloc, FieldEditorState>(
84+
builder: (context, state) {
85+
return _DeleteFieldButton(
86+
popoverMutex: popoverMutex,
87+
onDeleted: () {
88+
state.field.fold(
89+
() => Log.error('Can not delete the field'),
90+
(field) => widget.onDeleted?.call(field.id),
91+
);
92+
},
9493
);
9594
},
9695
),
@@ -139,13 +138,13 @@ class _FieldNameTextField extends StatefulWidget {
139138
}
140139

141140
class _FieldNameTextFieldState extends State<_FieldNameTextField> {
142-
late String name;
143141
FocusNode focusNode = FocusNode();
144142
VoidCallback? _popoverCallback;
145-
TextEditingController controller = TextEditingController();
143+
late TextEditingController controller;
146144

147145
@override
148146
void initState() {
147+
controller = TextEditingController();
149148
focusNode.addListener(() {
150149
if (focusNode.hasFocus) {
151150
widget.popoverMutex.close();
@@ -158,20 +157,29 @@ class _FieldNameTextFieldState extends State<_FieldNameTextField> {
158157
@override
159158
Widget build(BuildContext context) {
160159
final theme = context.watch<AppTheme>();
161-
162-
controller.text = context.read<FieldEditorBloc>().state.name;
163-
return BlocListener<FieldEditorBloc, FieldEditorState>(
164-
listenWhen: (previous, current) => previous.name != current.name,
165-
listener: (context, state) {
166-
controller.text = state.name;
167-
},
160+
return MultiBlocListener(
161+
listeners: [
162+
BlocListener<FieldEditorBloc, FieldEditorState>(
163+
listenWhen: (p, c) => p.field == none(),
164+
listener: (context, state) {
165+
focusNode.requestFocus();
166+
},
167+
),
168+
BlocListener<FieldEditorBloc, FieldEditorState>(
169+
listenWhen: (p, c) => controller.text != c.name,
170+
listener: (context, state) {
171+
controller.text = state.name;
172+
},
173+
),
174+
],
168175
child: BlocBuilder<FieldEditorBloc, FieldEditorState>(
176+
buildWhen: (previous, current) =>
177+
previous.errorText != current.errorText,
169178
builder: (context, state) {
170179
listenOnPopoverChanged(context);
171180

172181
return RoundedInputField(
173182
height: 36,
174-
autoFocus: true,
175183
focusNode: focusNode,
176184
style: const TextStyle(fontSize: 13, fontWeight: FontWeight.w500),
177185
controller: controller,
@@ -202,14 +210,6 @@ class _FieldNameTextFieldState extends State<_FieldNameTextField> {
202210
}
203211
});
204212
}
205-
206-
@override
207-
void didUpdateWidget(covariant _FieldNameTextField oldWidget) {
208-
controller.selection = TextSelection.fromPosition(
209-
TextPosition(offset: controller.text.length));
210-
211-
super.didUpdateWidget(oldWidget);
212-
}
213213
}
214214

215215
class _DeleteFieldButton extends StatelessWidget {
@@ -235,29 +235,11 @@ class _DeleteFieldButton extends StatelessWidget {
235235
fontSize: 12,
236236
color: enable ? null : theme.shader4,
237237
),
238+
onTap: () => onDeleted?.call(),
238239
);
239-
if (enable) button = _wrapPopover(button);
240+
// if (enable) button = button;
240241
return button;
241242
},
242243
);
243244
}
244-
245-
Widget _wrapPopover(Widget widget) {
246-
return AppFlowyPopover(
247-
triggerActions: PopoverTriggerFlags.click,
248-
constraints: BoxConstraints.loose(const Size(400, 240)),
249-
mutex: popoverMutex,
250-
direction: PopoverDirection.center,
251-
popupBuilder: (popupContext) {
252-
return PopoverAlertView(
253-
title: LocaleKeys.grid_field_deleteFieldPromptMessage.tr(),
254-
cancel: () {},
255-
confirm: () {
256-
onDeleted?.call();
257-
},
258-
);
259-
},
260-
child: widget,
261-
);
262-
}
263245
}

frontend/app_flowy/lib/plugins/grid/presentation/widgets/row/row_detail.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ class _RowDetailCellState extends State<_RowDetailCell> {
285285
child: SizedBox(
286286
width: 150,
287287
child: FieldCellButton(
288+
maxLines: null,
288289
field: widget.cellId.fieldContext.field,
289290
onTap: () {
290291
popover.show();

frontend/app_flowy/packages/flowy_infra_ui/lib/style_widget/text.dart

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class FlowyText extends StatelessWidget {
88
final double fontSize;
99
final FontWeight fontWeight;
1010
final TextAlign? textAlign;
11+
final int? maxLines;
1112
final Color? color;
1213

1314
const FlowyText(
@@ -18,28 +19,48 @@ class FlowyText extends StatelessWidget {
1819
this.fontWeight = FontWeight.w400,
1920
this.textAlign,
2021
this.color,
22+
this.maxLines = 1,
2123
}) : super(key: key);
2224

23-
const FlowyText.semibold(this.title,
24-
{Key? key, this.fontSize = 16, this.overflow, this.color, this.textAlign})
25-
: fontWeight = FontWeight.w600,
25+
const FlowyText.semibold(
26+
this.title, {
27+
Key? key,
28+
this.fontSize = 16,
29+
this.overflow,
30+
this.color,
31+
this.textAlign,
32+
this.maxLines = 1,
33+
}) : fontWeight = FontWeight.w600,
2634
super(key: key);
2735

28-
const FlowyText.medium(this.title,
29-
{Key? key, this.fontSize = 16, this.overflow, this.color, this.textAlign})
30-
: fontWeight = FontWeight.w500,
36+
const FlowyText.medium(
37+
this.title, {
38+
Key? key,
39+
this.fontSize = 16,
40+
this.overflow,
41+
this.color,
42+
this.textAlign,
43+
this.maxLines = 1,
44+
}) : fontWeight = FontWeight.w500,
3145
super(key: key);
3246

33-
const FlowyText.regular(this.title,
34-
{Key? key, this.fontSize = 16, this.overflow, this.color, this.textAlign})
35-
: fontWeight = FontWeight.w400,
47+
const FlowyText.regular(
48+
this.title, {
49+
Key? key,
50+
this.fontSize = 16,
51+
this.overflow,
52+
this.color,
53+
this.textAlign,
54+
this.maxLines = 1,
55+
}) : fontWeight = FontWeight.w400,
3656
super(key: key);
3757

3858
@override
3959
Widget build(BuildContext context) {
4060
final theme = context.watch<AppTheme>();
4161
return Text(
4262
title,
63+
maxLines: maxLines,
4364
textAlign: textAlign,
4465
overflow: overflow ?? TextOverflow.clip,
4566
style: TextStyle(

0 commit comments

Comments
 (0)