mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: selection text field
This commit is contained in:
parent
1abf0b565f
commit
271a8485b6
@ -1,5 +1,6 @@
|
|||||||
import 'package:app_flowy/workspace/application/grid/row/row_service.dart';
|
import 'package:app_flowy/workspace/application/grid/row/row_service.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:flowy_sdk/protobuf/flowy-grid/selection_type_option.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';
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
@ -36,9 +37,10 @@ class SelectionCellEvent with _$SelectionCellEvent {
|
|||||||
|
|
||||||
@freezed
|
@freezed
|
||||||
class SelectionCellState with _$SelectionCellState {
|
class SelectionCellState with _$SelectionCellState {
|
||||||
const factory SelectionCellState({
|
const factory SelectionCellState() = _SelectionCellState;
|
||||||
Cell? cell,
|
// required String girdId,
|
||||||
}) = _SelectionCellState;
|
// required Field field,
|
||||||
|
// required List<SelectOption> options,
|
||||||
|
|
||||||
factory SelectionCellState.initial() => const SelectionCellState();
|
factory SelectionCellState.initial() => const SelectionCellState();
|
||||||
}
|
}
|
||||||
|
@ -33,17 +33,15 @@ class TextCellBloc extends Bloc<TextCellEvent, TextCellState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void updateCellContent(String content) {
|
void updateCellContent(String content) {
|
||||||
if (state.cellData != null) {
|
final fieldId = state.cellData.field.id;
|
||||||
final fieldId = state.cellData!.field.id;
|
final gridId = state.cellData.gridId;
|
||||||
final gridId = state.cellData!.gridId;
|
final rowId = state.cellData.rowId;
|
||||||
final rowId = state.cellData!.rowId;
|
service.updateCell(
|
||||||
service.updateCell(
|
data: content,
|
||||||
data: content,
|
fieldId: fieldId,
|
||||||
fieldId: fieldId,
|
gridId: gridId,
|
||||||
gridId: gridId,
|
rowId: rowId,
|
||||||
rowId: rowId,
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -67,7 +65,7 @@ class TextCellState with _$TextCellState {
|
|||||||
}) = _TextCellState;
|
}) = _TextCellState;
|
||||||
|
|
||||||
factory TextCellState.initial(FutureCellData cellData) => TextCellState(
|
factory TextCellState.initial(FutureCellData cellData) => TextCellState(
|
||||||
content: cellData?.cell?.content ?? "",
|
content: cellData.cell?.content ?? "",
|
||||||
cellData: cellData,
|
cellData: cellData,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import 'package:dartz/dartz.dart';
|
|||||||
|
|
||||||
part 'row_bloc.freezed.dart';
|
part 'row_bloc.freezed.dart';
|
||||||
|
|
||||||
typedef CellDataMap = HashMap<String, GridCellData>;
|
typedef CellDataMap = LinkedHashMap<String, GridCellData>;
|
||||||
|
|
||||||
class RowBloc extends Bloc<RowEvent, RowState> {
|
class RowBloc extends Bloc<RowEvent, RowState> {
|
||||||
final RowService rowService;
|
final RowService rowService;
|
||||||
@ -48,10 +48,10 @@ class RowBloc extends Bloc<RowEvent, RowState> {
|
|||||||
didUpdateCell: (_DidUpdateCell value) async {
|
didUpdateCell: (_DidUpdateCell value) async {
|
||||||
final optionRow = await state.row;
|
final optionRow = await state.row;
|
||||||
final CellDataMap cellDataMap = optionRow.fold(
|
final CellDataMap cellDataMap = optionRow.fold(
|
||||||
() => HashMap.identity(),
|
() => CellDataMap.identity(),
|
||||||
(row) => _makeCellDatas(row),
|
(row) => _makeCellDatas(row),
|
||||||
);
|
);
|
||||||
emit(state.copyWith(cellDataMap: cellDataMap));
|
emit(state.copyWith(cellDataMap: Some(cellDataMap)));
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -111,13 +111,15 @@ class RowBloc extends Bloc<RowEvent, RowState> {
|
|||||||
CellDataMap _makeCellDatas(Row row) {
|
CellDataMap _makeCellDatas(Row row) {
|
||||||
var map = CellDataMap.new();
|
var map = CellDataMap.new();
|
||||||
for (final field in state.fields) {
|
for (final field in state.fields) {
|
||||||
map[field.id] = GridCellData(
|
if (field.visibility) {
|
||||||
rowId: row.id,
|
map[field.id] = GridCellData(
|
||||||
gridId: rowService.gridId,
|
rowId: row.id,
|
||||||
blockId: rowService.blockId,
|
gridId: rowService.gridId,
|
||||||
cell: row.cellByFieldId[field.id],
|
blockId: rowService.blockId,
|
||||||
field: field,
|
cell: row.cellByFieldId[field.id],
|
||||||
);
|
field: field,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
@ -138,7 +140,7 @@ class RowState with _$RowState {
|
|||||||
required double rowHeight,
|
required double rowHeight,
|
||||||
required List<Field> fields,
|
required List<Field> fields,
|
||||||
required Future<Option<Row>> row,
|
required Future<Option<Row>> row,
|
||||||
required CellDataMap? cellDataMap,
|
required Option<CellDataMap> cellDataMap,
|
||||||
}) = _RowState;
|
}) = _RowState;
|
||||||
|
|
||||||
factory RowState.initial(GridRowData data) => RowState(
|
factory RowState.initial(GridRowData data) => RowState(
|
||||||
@ -146,6 +148,6 @@ class RowState with _$RowState {
|
|||||||
rowHeight: data.height,
|
rowHeight: data.height,
|
||||||
fields: data.fields,
|
fields: data.fields,
|
||||||
row: Future(() => none()),
|
row: Future(() => none()),
|
||||||
cellDataMap: null,
|
cellDataMap: none(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ class RowService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef FutureCellData = GridCellData?;
|
typedef FutureCellData = GridCellData;
|
||||||
|
|
||||||
class GridCellData extends Equatable {
|
class GridCellData extends Equatable {
|
||||||
final String gridId;
|
final String gridId;
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import 'package:app_flowy/workspace/application/grid/row/row_service.dart';
|
import 'package:app_flowy/workspace/application/grid/row/row_service.dart';
|
||||||
import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart';
|
|
||||||
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/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'checkbox_cell.dart';
|
import 'checkbox_cell.dart';
|
||||||
@ -8,12 +7,9 @@ import 'number_cell.dart';
|
|||||||
import 'selection_cell/selection_cell.dart';
|
import 'selection_cell/selection_cell.dart';
|
||||||
import 'text_cell.dart';
|
import 'text_cell.dart';
|
||||||
|
|
||||||
Widget buildGridCell(String rowId, Field field, FutureCellData cellData) {
|
Widget buildGridCell(FutureCellData cellData) {
|
||||||
if (cellData == null) {
|
final key = ValueKey(cellData.field.id + cellData.rowId);
|
||||||
return const SizedBox();
|
switch (cellData.field.fieldType) {
|
||||||
}
|
|
||||||
final key = ValueKey(field.id + rowId);
|
|
||||||
switch (field.fieldType) {
|
|
||||||
case FieldType.Checkbox:
|
case FieldType.Checkbox:
|
||||||
return CheckboxCell(cellData: cellData, key: key);
|
return CheckboxCell(cellData: cellData, key: key);
|
||||||
case FieldType.DateTime:
|
case FieldType.DateTime:
|
||||||
|
@ -79,19 +79,13 @@ class SelectOptionTextField extends StatelessWidget {
|
|||||||
initialTags: ["abc", "bdf"],
|
initialTags: ["abc", "bdf"],
|
||||||
focusNode: _focusNode,
|
focusNode: _focusNode,
|
||||||
textSeparators: const [' ', ','],
|
textSeparators: const [' ', ','],
|
||||||
inputfieldBuilder: (
|
inputfieldBuilder: (BuildContext context, editController, focusNode, error, onChanged, onSubmitted) {
|
||||||
BuildContext context,
|
|
||||||
TextEditingController editController,
|
|
||||||
FocusNode focusNode,
|
|
||||||
String? error,
|
|
||||||
void Function(String)? onChanged,
|
|
||||||
void Function(String)? onSubmitted,
|
|
||||||
) {
|
|
||||||
return ((context, sc, tags, onTagDelegate) {
|
return ((context, sc, tags, onTagDelegate) {
|
||||||
return TextField(
|
return TextField(
|
||||||
controller: editController,
|
controller: editController,
|
||||||
focusNode: focusNode,
|
focusNode: focusNode,
|
||||||
onChanged: (value) {},
|
onChanged: onChanged,
|
||||||
|
onSubmitted: onSubmitted,
|
||||||
onEditingComplete: () => focusNode.unfocus(),
|
onEditingComplete: () => focusNode.unfocus(),
|
||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
|
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
|
||||||
@ -131,6 +125,8 @@ class SelectOptionTextField extends StatelessWidget {
|
|||||||
borderRadius: BorderRadius.circular(6.0),
|
borderRadius: BorderRadius.circular(6.0),
|
||||||
),
|
),
|
||||||
child: FlowyText.medium("abc", fontSize: 12),
|
child: FlowyText.medium("abc", fontSize: 12),
|
||||||
|
margin: const EdgeInsets.symmetric(horizontal: 5.0),
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 5.0),
|
||||||
)
|
)
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
import 'package:app_flowy/startup/startup.dart';
|
import 'package:app_flowy/startup/startup.dart';
|
||||||
import 'package:app_flowy/workspace/application/grid/prelude.dart';
|
import 'package:app_flowy/workspace/application/grid/prelude.dart';
|
||||||
import 'package:app_flowy/workspace/presentation/plugins/grid/src/widgets/cell/cell_container.dart';
|
import 'package:app_flowy/workspace/presentation/plugins/grid/src/widgets/cell/cell_container.dart';
|
||||||
|
import 'package:flowy_sdk/log.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
|
||||||
import 'extension.dart';
|
import 'extension.dart';
|
||||||
|
|
||||||
@ -32,10 +34,19 @@ class _SingleSelectCellState extends State<SingleSelectCell> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
_focusNode.addCallback(context, () {});
|
_focusNode.addCallback(context, () {
|
||||||
return SelectOptionTextField(
|
Log.info(_focusNode.hasFocus);
|
||||||
focusNode: _focusNode,
|
});
|
||||||
controller: _controller,
|
return BlocProvider.value(
|
||||||
|
value: _cellBloc,
|
||||||
|
child: BlocBuilder<SelectionCellBloc, SelectionCellState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
return SelectOptionTextField(
|
||||||
|
focusNode: _focusNode,
|
||||||
|
controller: _controller,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,20 +114,3 @@ class _SelectionCell extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SelectionBadge extends StatelessWidget {
|
|
||||||
final SelectOption option;
|
|
||||||
const SelectionBadge({required this.option, Key? key}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: option.color.make(context),
|
|
||||||
shape: BoxShape.rectangle,
|
|
||||||
borderRadius: BorderRadius.circular(6.0),
|
|
||||||
),
|
|
||||||
child: FlowyText.medium(option.name, fontSize: 12),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -122,17 +122,19 @@ class _RowCells extends StatelessWidget {
|
|||||||
return BlocBuilder<RowBloc, RowState>(
|
return BlocBuilder<RowBloc, RowState>(
|
||||||
buildWhen: (previous, current) => previous.cellDataMap != current.cellDataMap,
|
buildWhen: (previous, current) => previous.cellDataMap != current.cellDataMap,
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
final children = state.fields
|
final List<Widget> children = state.cellDataMap.fold(
|
||||||
.where((field) => field.visibility)
|
() => [],
|
||||||
.map((field) => CellContainer(
|
(dataMap) {
|
||||||
width: field.width.toDouble(),
|
return dataMap.values.map(
|
||||||
child: buildGridCell(
|
(value) {
|
||||||
state.rowId,
|
return CellContainer(
|
||||||
field,
|
width: value.field.width.toDouble(),
|
||||||
state.cellDataMap?[field.id],
|
child: buildGridCell(value),
|
||||||
),
|
);
|
||||||
))
|
},
|
||||||
.toList();
|
).toList();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
return Row(children: children);
|
return Row(children: children);
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user