mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: close bloc when overlay dismiss
This commit is contained in:
parent
3fdf922f81
commit
2eccd0452b
@ -150,7 +150,7 @@
|
|||||||
"duplicate": "Duplicate",
|
"duplicate": "Duplicate",
|
||||||
"delete": "Delete",
|
"delete": "Delete",
|
||||||
"textFieldName": "Text",
|
"textFieldName": "Text",
|
||||||
"checkboxFieldName": "Number",
|
"checkboxFieldName": "Checkbox",
|
||||||
"dateFieldName": "Date",
|
"dateFieldName": "Date",
|
||||||
"numberFieldName": "Number",
|
"numberFieldName": "Number",
|
||||||
"singleSelectFieldName": "Select",
|
"singleSelectFieldName": "Select",
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import 'package:flowy_sdk/log.dart';
|
||||||
import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart';
|
import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||||
@ -14,8 +15,15 @@ class CreateFieldBloc extends Bloc<CreateFieldEvent, CreateFieldState> {
|
|||||||
on<CreateFieldEvent>(
|
on<CreateFieldEvent>(
|
||||||
(event, emit) async {
|
(event, emit) async {
|
||||||
await event.map(
|
await event.map(
|
||||||
initial: (_InitialField value) {},
|
initial: (_InitialField value) async {
|
||||||
|
final result = await service.getDefaultField();
|
||||||
|
result.fold(
|
||||||
|
(field) => emit(state.copyWith(field: Some(field))),
|
||||||
|
(err) => Log.error(err),
|
||||||
|
);
|
||||||
|
},
|
||||||
updateName: (_UpdateName value) {},
|
updateName: (_UpdateName value) {},
|
||||||
|
done: (_Done value) {},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -31,6 +39,7 @@ class CreateFieldBloc extends Bloc<CreateFieldEvent, CreateFieldState> {
|
|||||||
class CreateFieldEvent with _$CreateFieldEvent {
|
class CreateFieldEvent with _$CreateFieldEvent {
|
||||||
const factory CreateFieldEvent.initial() = _InitialField;
|
const factory CreateFieldEvent.initial() = _InitialField;
|
||||||
const factory CreateFieldEvent.updateName(String newName) = _UpdateName;
|
const factory CreateFieldEvent.updateName(String newName) = _UpdateName;
|
||||||
|
const factory CreateFieldEvent.done() = _Done;
|
||||||
}
|
}
|
||||||
|
|
||||||
@freezed
|
@freezed
|
||||||
|
@ -12,9 +12,7 @@ class FieldService {
|
|||||||
|
|
||||||
FieldService({required this.gridId});
|
FieldService({required this.gridId});
|
||||||
|
|
||||||
Future<Either<Field, FlowyError>> getDefaultField(
|
Future<Either<Field, FlowyError>> getDefaultField() {
|
||||||
String gridId,
|
|
||||||
) {
|
|
||||||
final payload = GridId.create()..value = gridId;
|
final payload = GridId.create()..value = gridId;
|
||||||
return GridEventCreateDefaultField(payload).send();
|
return GridEventCreateDefaultField(payload).send();
|
||||||
}
|
}
|
||||||
@ -26,7 +24,7 @@ class FieldService {
|
|||||||
String? startFieldId,
|
String? startFieldId,
|
||||||
) {
|
) {
|
||||||
final typeOptionData = typeOption.writeToBuffer();
|
final typeOptionData = typeOption.writeToBuffer();
|
||||||
return _createField(gridId, field, typeOptionData, startFieldId);
|
return createField(gridId, field, typeOptionData, startFieldId);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Either<Unit, FlowyError>> createSingleSelectField(
|
Future<Either<Unit, FlowyError>> createSingleSelectField(
|
||||||
@ -36,7 +34,7 @@ class FieldService {
|
|||||||
String? startFieldId,
|
String? startFieldId,
|
||||||
) {
|
) {
|
||||||
final typeOptionData = typeOption.writeToBuffer();
|
final typeOptionData = typeOption.writeToBuffer();
|
||||||
return _createField(gridId, field, typeOptionData, startFieldId);
|
return createField(gridId, field, typeOptionData, startFieldId);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Either<Unit, FlowyError>> createMultiSelectField(
|
Future<Either<Unit, FlowyError>> createMultiSelectField(
|
||||||
@ -46,7 +44,7 @@ class FieldService {
|
|||||||
String? startFieldId,
|
String? startFieldId,
|
||||||
) {
|
) {
|
||||||
final typeOptionData = typeOption.writeToBuffer();
|
final typeOptionData = typeOption.writeToBuffer();
|
||||||
return _createField(gridId, field, typeOptionData, startFieldId);
|
return createField(gridId, field, typeOptionData, startFieldId);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Either<Unit, FlowyError>> createNumberField(
|
Future<Either<Unit, FlowyError>> createNumberField(
|
||||||
@ -56,7 +54,7 @@ class FieldService {
|
|||||||
String? startFieldId,
|
String? startFieldId,
|
||||||
) {
|
) {
|
||||||
final typeOptionData = typeOption.writeToBuffer();
|
final typeOptionData = typeOption.writeToBuffer();
|
||||||
return _createField(gridId, field, typeOptionData, startFieldId);
|
return createField(gridId, field, typeOptionData, startFieldId);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Either<Unit, FlowyError>> createDateField(
|
Future<Either<Unit, FlowyError>> createDateField(
|
||||||
@ -66,19 +64,19 @@ class FieldService {
|
|||||||
String? startFieldId,
|
String? startFieldId,
|
||||||
) {
|
) {
|
||||||
final typeOptionData = typeOption.writeToBuffer();
|
final typeOptionData = typeOption.writeToBuffer();
|
||||||
return _createField(gridId, field, typeOptionData, startFieldId);
|
return createField(gridId, field, typeOptionData, startFieldId);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Either<Unit, FlowyError>> _createField(
|
Future<Either<Unit, FlowyError>> createField(
|
||||||
String gridId,
|
String gridId,
|
||||||
Field field,
|
Field field,
|
||||||
Uint8List typeOptionData,
|
Uint8List? typeOptionData,
|
||||||
String? startFieldId,
|
String? startFieldId,
|
||||||
) {
|
) {
|
||||||
final payload = CreateFieldPayload.create()
|
final payload = CreateFieldPayload.create()
|
||||||
..gridId = gridId
|
..gridId = gridId
|
||||||
..field_2 = field
|
..field_2 = field
|
||||||
..typeOptionData = typeOptionData
|
..typeOptionData = typeOptionData ?? Uint8List.fromList([])
|
||||||
..startFieldId = startFieldId ?? "";
|
..startFieldId = startFieldId ?? "";
|
||||||
|
|
||||||
return GridEventCreateField(payload).send();
|
return GridEventCreateField(payload).send();
|
||||||
|
@ -3,55 +3,73 @@ import 'package:app_flowy/workspace/application/grid/field/create_field_bloc.dar
|
|||||||
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
||||||
import 'package:flowy_infra_ui/style_widget/text.dart';
|
import 'package:flowy_infra_ui/style_widget/text.dart';
|
||||||
import 'package:flowy_infra_ui/widget/spacing.dart';
|
import 'package:flowy_infra_ui/widget/spacing.dart';
|
||||||
import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart';
|
import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart' hide Row;
|
||||||
import 'package:flowy_sdk/protobuf/flowy-grid-data-model/meta.pb.dart';
|
import 'package:flowy_sdk/protobuf/flowy-grid-data-model/meta.pb.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
|
||||||
import 'field_name_input.dart';
|
import 'field_name_input.dart';
|
||||||
import 'field_tyep_switcher.dart';
|
import 'field_tyep_switcher.dart';
|
||||||
|
|
||||||
class CreateFieldPannel extends StatelessWidget {
|
class CreateFieldPannel extends FlowyOverlayDelegate {
|
||||||
const CreateFieldPannel({Key? key}) : super(key: key);
|
final String gridId;
|
||||||
|
final CreateFieldBloc _createFieldBloc;
|
||||||
|
CreateFieldPannel({required this.gridId, Key? key}) : _createFieldBloc = getIt<CreateFieldBloc>(param1: gridId) {
|
||||||
|
_createFieldBloc.add(const CreateFieldEvent.initial());
|
||||||
|
}
|
||||||
|
|
||||||
static void show(BuildContext context) {
|
void show(BuildContext context, String gridId) {
|
||||||
const pannel = CreateFieldPannel();
|
|
||||||
FlowyOverlay.of(context).insertWithAnchor(
|
FlowyOverlay.of(context).insertWithAnchor(
|
||||||
widget: OverlayContainer(
|
widget: OverlayContainer(
|
||||||
child: pannel,
|
child: _CreateFieldPannelWidget(_createFieldBloc),
|
||||||
constraints: BoxConstraints.loose(const Size(300, 200)),
|
constraints: BoxConstraints.loose(const Size(220, 200)),
|
||||||
),
|
),
|
||||||
identifier: pannel.identifier(),
|
identifier: identifier(),
|
||||||
anchorContext: context,
|
anchorContext: context,
|
||||||
anchorDirection: AnchorDirection.bottomWithLeftAligned,
|
anchorDirection: AnchorDirection.bottomWithLeftAligned,
|
||||||
style: FlowyOverlayStyle(blur: false),
|
style: FlowyOverlayStyle(blur: false),
|
||||||
);
|
delegate: this,
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return BlocProvider(
|
|
||||||
create: (context) => getIt<CreateFieldBloc>()..add(const CreateFieldEvent.initial()),
|
|
||||||
child: BlocBuilder<CreateFieldBloc, CreateFieldState>(
|
|
||||||
builder: (context, state) {
|
|
||||||
return state.field.fold(
|
|
||||||
() => const SizedBox(),
|
|
||||||
(field) => Column(children: [
|
|
||||||
const FlowyText.medium("Edit property"),
|
|
||||||
const VSpace(10),
|
|
||||||
_FieldNameTextField(field),
|
|
||||||
const VSpace(10),
|
|
||||||
_FieldTypeSwitcher(field),
|
|
||||||
]),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
String identifier() {
|
String identifier() {
|
||||||
return toString();
|
return toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didRemove() async {
|
||||||
|
await _createFieldBloc.close();
|
||||||
|
// TODO: implement didRemove
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _CreateFieldPannelWidget extends StatelessWidget {
|
||||||
|
final CreateFieldBloc createFieldBloc;
|
||||||
|
const _CreateFieldPannelWidget(this.createFieldBloc, {Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return BlocProvider.value(
|
||||||
|
value: createFieldBloc,
|
||||||
|
child: BlocBuilder<CreateFieldBloc, CreateFieldState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
return state.field.fold(
|
||||||
|
() => const SizedBox(),
|
||||||
|
(field) => ListView(
|
||||||
|
shrinkWrap: true,
|
||||||
|
children: [
|
||||||
|
const FlowyText.medium("Edit property", fontSize: 12),
|
||||||
|
const VSpace(10),
|
||||||
|
_FieldNameTextField(field),
|
||||||
|
const VSpace(10),
|
||||||
|
_FieldTypeSwitcher(field),
|
||||||
|
const VSpace(10),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _FieldTypeSwitcher extends StatelessWidget {
|
class _FieldTypeSwitcher extends StatelessWidget {
|
||||||
|
@ -55,9 +55,7 @@ class FieldActionItem extends StatelessWidget {
|
|||||||
|
|
||||||
enum FieldAction {
|
enum FieldAction {
|
||||||
hide,
|
hide,
|
||||||
// insertLeft,
|
|
||||||
duplicate,
|
duplicate,
|
||||||
// insertRight,
|
|
||||||
delete,
|
delete,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,8 @@ class FieldTypeSwitcher extends StatelessWidget {
|
|||||||
return SizedBox(
|
return SizedBox(
|
||||||
height: 36,
|
height: 36,
|
||||||
child: FlowyButton(
|
child: FlowyButton(
|
||||||
text: FlowyText.medium(field.name, fontSize: 12),
|
text: FlowyText.medium(field.fieldType.title(), fontSize: 12),
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||||
hoverColor: theme.hover,
|
hoverColor: theme.hover,
|
||||||
onTap: () => FieldTypeList.show(context, onSelectField),
|
onTap: () => FieldTypeList.show(context, onSelectField),
|
||||||
leftIcon: svg(field.fieldType.iconName(), color: theme.iconColor),
|
leftIcon: svg(field.fieldType.iconName(), color: theme.iconColor),
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import 'package:app_flowy/workspace/presentation/plugins/grid/src/layout/sizes.dart';
|
|
||||||
import 'package:flowy_infra/image.dart';
|
import 'package:flowy_infra/image.dart';
|
||||||
import 'package:flowy_infra/theme.dart';
|
import 'package:flowy_infra/theme.dart';
|
||||||
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
||||||
|
@ -65,7 +65,7 @@ class GridHeader extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
const _HeaderLeading(),
|
const _HeaderLeading(),
|
||||||
...cells,
|
...cells,
|
||||||
const _HeaderTrailing(),
|
_HeaderTrailing(gridId: gridId),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -88,7 +88,8 @@ class _HeaderLeading extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _HeaderTrailing extends StatelessWidget {
|
class _HeaderTrailing extends StatelessWidget {
|
||||||
const _HeaderTrailing({Key? key}) : super(key: key);
|
final String gridId;
|
||||||
|
const _HeaderTrailing({required this.gridId, Key? key}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -100,13 +101,14 @@ class _HeaderTrailing extends StatelessWidget {
|
|||||||
border: Border(top: borderSide, bottom: borderSide),
|
border: Border(top: borderSide, bottom: borderSide),
|
||||||
),
|
),
|
||||||
padding: GridSize.headerContentInsets,
|
padding: GridSize.headerContentInsets,
|
||||||
child: const CreateFieldButton(),
|
child: CreateFieldButton(gridId: gridId),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CreateFieldButton extends StatelessWidget {
|
class CreateFieldButton extends StatelessWidget {
|
||||||
const CreateFieldButton({Key? key}) : super(key: key);
|
final String gridId;
|
||||||
|
const CreateFieldButton({required this.gridId, Key? key}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -114,7 +116,7 @@ class CreateFieldButton extends StatelessWidget {
|
|||||||
return FlowyButton(
|
return FlowyButton(
|
||||||
text: const FlowyText.medium('New column', fontSize: 12),
|
text: const FlowyText.medium('New column', fontSize: 12),
|
||||||
hoverColor: theme.hover,
|
hoverColor: theme.hover,
|
||||||
onTap: () => CreateFieldPannel.show(context),
|
onTap: () => CreateFieldPannel(gridId: gridId).show(context, gridId),
|
||||||
leftIcon: svg("home/add"),
|
leftIcon: svg("home/add"),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ class FlowyButton extends StatelessWidget {
|
|||||||
children.add(const HSpace(6));
|
children.add(const HSpace(6));
|
||||||
}
|
}
|
||||||
|
|
||||||
children.add(Align(child: text));
|
children.add(text);
|
||||||
|
|
||||||
if (rightIcon != null) {
|
if (rightIcon != null) {
|
||||||
children.add(const Spacer());
|
children.add(const Spacer());
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import 'package:flowy_infra/theme.dart';
|
import 'package:flowy_infra/theme.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
class FlowyText extends StatelessWidget {
|
class FlowyText extends StatelessWidget {
|
||||||
@ -42,6 +42,7 @@ class FlowyText extends StatelessWidget {
|
|||||||
return Text(title,
|
return Text(title,
|
||||||
overflow: overflow,
|
overflow: overflow,
|
||||||
softWrap: false,
|
softWrap: false,
|
||||||
|
textAlign: textAlign,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: theme.textColor,
|
color: theme.textColor,
|
||||||
fontWeight: fontWeight,
|
fontWeight: fontWeight,
|
||||||
|
@ -81,6 +81,7 @@ class _RoundedInputFieldState extends State<RoundedInputField> {
|
|||||||
},
|
},
|
||||||
cursorColor: widget.cursorColor,
|
cursorColor: widget.cursorColor,
|
||||||
obscureText: obscuteText,
|
obscureText: obscuteText,
|
||||||
|
style: widget.style,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
contentPadding: widget.contentPadding,
|
contentPadding: widget.contentPadding,
|
||||||
hintText: widget.hintText,
|
hintText: widget.hintText,
|
||||||
|
@ -64,7 +64,8 @@ impl ClientGridEditor {
|
|||||||
|
|
||||||
pub async fn make_default_field(&self) -> FlowyResult<Field> {
|
pub async fn make_default_field(&self) -> FlowyResult<Field> {
|
||||||
let field_type = FieldType::default();
|
let field_type = FieldType::default();
|
||||||
let field_meta = FieldBuilder::from_field_type(&field_type).build();
|
let name = format!("Property {}", self.pad.read().await.fields().len());
|
||||||
|
let field_meta = FieldBuilder::from_field_type(&field_type).name(&name).build();
|
||||||
Ok(field_meta.into())
|
Ok(field_meta.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user