diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/cell_listener.dart b/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/cell_listener.dart index d1fb0acc0c..314345017e 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/cell_listener.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/cell_listener.dart @@ -12,7 +12,7 @@ typedef UpdateFieldNotifiedValue = Either; class CellListener { final String rowId; final String fieldId; - PublishNotifier updateCellNotifier = PublishNotifier(); + PublishNotifier? updateCellNotifier = PublishNotifier(); GridNotificationListener? _listener; CellListener({required this.rowId, required this.fieldId}); @@ -24,8 +24,8 @@ class CellListener { switch (ty) { case GridNotification.DidUpdateCell: result.fold( - (payload) => updateCellNotifier.value = left(CellNotificationData.fromBuffer(payload)), - (error) => updateCellNotifier.value = right(error), + (payload) => updateCellNotifier?.value = left(CellNotificationData.fromBuffer(payload)), + (error) => updateCellNotifier?.value = right(error), ); break; default: @@ -35,6 +35,7 @@ class CellListener { Future stop() async { await _listener?.stop(); - updateCellNotifier.dispose(); + updateCellNotifier?.dispose(); + updateCellNotifier = null; } } diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/checkbox_cell_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/checkbox_cell_bloc.dart index 0f56b9c53c..2d937b8cd2 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/checkbox_cell_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/checkbox_cell_bloc.dart @@ -43,7 +43,7 @@ class CheckboxCellBloc extends Bloc { } void _startListening() { - _listener.updateCellNotifier.addPublishListener((result) { + _listener.updateCellNotifier?.addPublishListener((result) { result.fold( (notificationData) async => await _loadCellData(), (err) => Log.error(err), diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/date_cell_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/date_cell_bloc.dart index 7dd58bf5ac..b4b6d7e152 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/date_cell_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/date_cell_bloc.dart @@ -52,7 +52,7 @@ class DateCellBloc extends Bloc { } void _startListening() { - _cellListener.updateCellNotifier.addPublishListener((result) { + _cellListener.updateCellNotifier?.addPublishListener((result) { result.fold( (notificationData) => _loadCellData(), (err) => Log.error(err), @@ -60,7 +60,7 @@ class DateCellBloc extends Bloc { }); _cellListener.start(); - _fieldListener.updateFieldNotifier.addPublishListener((result) { + _fieldListener.updateFieldNotifier?.addPublishListener((result) { result.fold( (field) { if (!isClosed) { diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/number_cell_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/number_cell_bloc.dart index a145305bbe..287d70b701 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/number_cell_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/number_cell_bloc.dart @@ -59,7 +59,7 @@ class NumberCellBloc extends Bloc { } void _startListening() { - _cellListener.updateCellNotifier.addPublishListener((result) { + _cellListener.updateCellNotifier?.addPublishListener((result) { result.fold( (notificationData) async { await _getCellData(); @@ -69,7 +69,7 @@ class NumberCellBloc extends Bloc { }); _cellListener.start(); - _fieldListener.updateFieldNotifier.addPublishListener((result) { + _fieldListener.updateFieldNotifier?.addPublishListener((result) { result.fold( (field) => _getCellData(), (err) => Log.error(err), diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/selection_cell_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/selection_cell_bloc.dart index b7e472e181..dbca1b5ae3 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/selection_cell_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/selection_cell_bloc.dart @@ -64,7 +64,7 @@ class SelectionCellBloc extends Bloc { } void _startListening() { - _cellListener.updateCellNotifier.addPublishListener((result) { + _cellListener.updateCellNotifier?.addPublishListener((result) { result.fold( (notificationData) => _loadOptions(), (err) => Log.error(err), @@ -72,7 +72,7 @@ class SelectionCellBloc extends Bloc { }); _cellListener.start(); - _fieldListener.updateFieldNotifier.addPublishListener((result) { + _fieldListener.updateFieldNotifier?.addPublishListener((result) { result.fold( (field) => _loadOptions(), (err) => Log.error(err), diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/selection_editor_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/selection_editor_bloc.dart index 5d2c52dc0e..813b779646 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/selection_editor_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell_bloc/selection_editor_bloc.dart @@ -134,7 +134,7 @@ class SelectOptionEditorBloc extends Bloc _loadOptions(), (err) => Log.error(err), @@ -142,7 +142,7 @@ class SelectOptionEditorBloc extends Bloc { } void _startListening() { - _fieldListener.updateFieldNotifier.addPublishListener((result) { + _fieldListener.updateFieldNotifier?.addPublishListener((result) { result.fold( (field) { if (!isClosed) { diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/field_listener.dart b/frontend/app_flowy/lib/workspace/application/grid/field/field_listener.dart index 450d88fe18..b31a9c3ff5 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/field/field_listener.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/field/field_listener.dart @@ -11,7 +11,7 @@ typedef UpdateFieldNotifiedValue = Either; class SingleFieldListener { final String fieldId; - PublishNotifier updateFieldNotifier = PublishNotifier(); + PublishNotifier? updateFieldNotifier = PublishNotifier(); GridNotificationListener? _listener; SingleFieldListener({required this.fieldId}); @@ -30,8 +30,8 @@ class SingleFieldListener { switch (ty) { case GridNotification.DidUpdateField: result.fold( - (payload) => updateFieldNotifier.value = left(Field.fromBuffer(payload)), - (error) => updateFieldNotifier.value = right(error), + (payload) => updateFieldNotifier?.value = left(Field.fromBuffer(payload)), + (error) => updateFieldNotifier?.value = right(error), ); break; default: @@ -41,6 +41,7 @@ class SingleFieldListener { Future stop() async { await _listener?.stop(); - updateFieldNotifier.dispose(); + updateFieldNotifier?.dispose(); + updateFieldNotifier = null; } } diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/grid_listenr.dart b/frontend/app_flowy/lib/workspace/application/grid/field/grid_listenr.dart index c257fe3c0d..6774205a5e 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/field/grid_listenr.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/field/grid_listenr.dart @@ -11,7 +11,7 @@ typedef UpdateFieldNotifiedValue = Either; class GridFieldsListener { final String gridId; - PublishNotifier updateFieldsNotifier = PublishNotifier(); + PublishNotifier? updateFieldsNotifier = PublishNotifier(); GridNotificationListener? _listener; GridFieldsListener({required this.gridId}); @@ -26,8 +26,8 @@ class GridFieldsListener { switch (ty) { case GridNotification.DidUpdateGridField: result.fold( - (payload) => updateFieldsNotifier.value = left(GridFieldChangeset.fromBuffer(payload)), - (error) => updateFieldsNotifier.value = right(error), + (payload) => updateFieldsNotifier?.value = left(GridFieldChangeset.fromBuffer(payload)), + (error) => updateFieldsNotifier?.value = right(error), ); break; default: @@ -37,6 +37,7 @@ class GridFieldsListener { Future stop() async { await _listener?.stop(); - updateFieldsNotifier.dispose(); + updateFieldsNotifier?.dispose(); + updateFieldsNotifier = null; } } diff --git a/frontend/app_flowy/lib/workspace/application/grid/grid_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/grid_bloc.dart index 882b3eb5b4..c37c31ec46 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/grid_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/grid_bloc.dart @@ -58,7 +58,7 @@ class GridBloc extends Bloc { } void _startListening() { - _fieldListener.updateFieldsNotifier.addPublishListener((result) { + _fieldListener.updateFieldsNotifier?.addPublishListener((result) { result.fold( (changeset) { fieldCache.applyChangeset(changeset); diff --git a/frontend/app_flowy/lib/workspace/application/grid/row/row_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/row/row_bloc.dart index dbbe9b054d..b16d75dc92 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/row/row_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/row/row_bloc.dart @@ -73,7 +73,7 @@ class RowBloc extends Bloc { } Future _startListening() async { - _rowlistener.updateRowNotifier.addPublishListener((result) { + _rowlistener.updateRowNotifier?.addPublishListener((result) { result.fold( (row) => add(RowEvent.didUpdateRow(row)), (err) => Log.error(err), diff --git a/frontend/app_flowy/lib/workspace/application/grid/row/row_listener.dart b/frontend/app_flowy/lib/workspace/application/grid/row/row_listener.dart index 716d252802..7d947b8482 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/row/row_listener.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/row/row_listener.dart @@ -12,7 +12,7 @@ typedef UpdateFieldNotifiedValue = Either, FlowyError>; class RowListener { final String rowId; - PublishNotifier updateRowNotifier = PublishNotifier(); + PublishNotifier? updateRowNotifier = PublishNotifier(); GridNotificationListener? _listener; RowListener({required this.rowId}); @@ -25,8 +25,8 @@ class RowListener { switch (ty) { case GridNotification.DidUpdateRow: result.fold( - (payload) => updateRowNotifier.value = left(Row.fromBuffer(payload)), - (error) => updateRowNotifier.value = right(error), + (payload) => updateRowNotifier?.value = left(Row.fromBuffer(payload)), + (error) => updateRowNotifier?.value = right(error), ); break; default: @@ -36,6 +36,7 @@ class RowListener { Future stop() async { await _listener?.stop(); - updateRowNotifier.dispose(); + updateRowNotifier?.dispose(); + updateRowNotifier = null; } } diff --git a/frontend/app_flowy/lib/workspace/application/grid/setting/property_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/setting/property_bloc.dart index 0ec31d08b6..634bb1e56d 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/setting/property_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/setting/property_bloc.dart @@ -51,7 +51,7 @@ class GridPropertyBloc extends Bloc { } void _startListening() { - _fieldListener.updateFieldsNotifier.addPublishListener((result) { + _fieldListener.updateFieldsNotifier?.addPublishListener((result) { result.fold( (changeset) { _fieldCache.applyChangeset(changeset); diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/grid_header.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/grid_header.dart index dcf5702f40..a00b9e6295 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/grid_header.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/header/grid_header.dart @@ -25,6 +25,7 @@ class GridHeaderSliverAdaptor extends StatelessWidget { create: (context) => getIt(param1: gridId, param2: fieldCache)..add(const GridHeaderEvent.initial()), child: BlocBuilder( + buildWhen: (previous, current) => previous.fields.length != current.fields.length, builder: (context, state) { return SliverPersistentHeader( delegate: SliverHeaderDelegateImplementation(gridId: gridId, fields: state.fields), @@ -45,7 +46,7 @@ class SliverHeaderDelegateImplementation extends SliverPersistentHeaderDelegate @override Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) { - return _GridHeader(gridId: gridId, fields: fields, key: ObjectKey(fields)); + return _GridHeader(gridId: gridId, fields: fields); } @override