mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: reload number cell
This commit is contained in:
parent
cefd64034d
commit
8683c2f343
@ -5,14 +5,14 @@ abstract class IGridCellDataConfig {
|
||||
bool get reloadOnFieldChanged;
|
||||
}
|
||||
|
||||
abstract class ICellDataParser<T> {
|
||||
abstract class IGridCellDataParser<T> {
|
||||
T? parserData(List<int> data);
|
||||
}
|
||||
|
||||
class GridCellDataLoader<T> {
|
||||
final CellService service = CellService();
|
||||
final GridCellIdentifier cellId;
|
||||
final ICellDataParser<T> parser;
|
||||
final IGridCellDataParser<T> parser;
|
||||
final bool reloadOnFieldChanged;
|
||||
|
||||
GridCellDataLoader({
|
||||
@ -40,7 +40,7 @@ class GridCellDataLoader<T> {
|
||||
}
|
||||
}
|
||||
|
||||
class StringCellDataParser implements ICellDataParser<String> {
|
||||
class StringCellDataParser implements IGridCellDataParser<String> {
|
||||
@override
|
||||
String? parserData(List<int> data) {
|
||||
final s = utf8.decode(data);
|
||||
@ -48,7 +48,7 @@ class StringCellDataParser implements ICellDataParser<String> {
|
||||
}
|
||||
}
|
||||
|
||||
class DateCellDataParser implements ICellDataParser<DateCellDataPB> {
|
||||
class DateCellDataParser implements IGridCellDataParser<DateCellDataPB> {
|
||||
@override
|
||||
DateCellDataPB? parserData(List<int> data) {
|
||||
if (data.isEmpty) {
|
||||
@ -58,7 +58,7 @@ class DateCellDataParser implements ICellDataParser<DateCellDataPB> {
|
||||
}
|
||||
}
|
||||
|
||||
class SelectOptionCellDataParser implements ICellDataParser<SelectOptionCellDataPB> {
|
||||
class SelectOptionCellDataParser implements IGridCellDataParser<SelectOptionCellDataPB> {
|
||||
@override
|
||||
SelectOptionCellDataPB? parserData(List<int> data) {
|
||||
if (data.isEmpty) {
|
||||
@ -68,7 +68,7 @@ class SelectOptionCellDataParser implements ICellDataParser<SelectOptionCellData
|
||||
}
|
||||
}
|
||||
|
||||
class URLCellDataParser implements ICellDataParser<URLCellDataPB> {
|
||||
class URLCellDataParser implements IGridCellDataParser<URLCellDataPB> {
|
||||
@override
|
||||
URLCellDataPB? parserData(List<int> data) {
|
||||
if (data.isEmpty) {
|
||||
|
@ -52,6 +52,7 @@ class GridCellControllerBuilder {
|
||||
final cellDataLoader = GridCellDataLoader(
|
||||
cellId: _cellId,
|
||||
parser: StringCellDataParser(),
|
||||
reloadOnFieldChanged: true,
|
||||
);
|
||||
return GridCellController(
|
||||
cellId: _cellId,
|
||||
@ -170,16 +171,13 @@ class IGridCellController<T, D> extends Equatable {
|
||||
}
|
||||
isListening = true;
|
||||
|
||||
/// The cell data will be changed by two reasons:
|
||||
/// 1. User edit the cell
|
||||
/// 2. User edit the field
|
||||
/// For example: The number cell reload the cell data that carries the format
|
||||
/// user input: 12
|
||||
/// cell display: $12
|
||||
_cellDataNotifier = ValueNotifier(_cellsCache.get(_cacheKey));
|
||||
_cellListener = CellListener(rowId: cellId.rowId, fieldId: cellId.field.id);
|
||||
|
||||
/// 1.Listen on user edit event and load the new cell data if needed.
|
||||
/// For example:
|
||||
/// user input: 12
|
||||
/// cell display: $12
|
||||
_cellListener.start(onCellChanged: (result) {
|
||||
result.fold(
|
||||
(_) => _loadData(),
|
||||
@ -193,6 +191,9 @@ class IGridCellController<T, D> extends Equatable {
|
||||
onCellFieldChanged();
|
||||
}
|
||||
|
||||
/// reloadOnFieldChanged should be true if you need to load the data when the corresponding field is changed
|
||||
/// For example:
|
||||
/// ¥12 -> $12
|
||||
if (_cellDataLoader.reloadOnFieldChanged) {
|
||||
_loadData();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user