chore: set notifier to null after dispose

This commit is contained in:
appflowy 2022-04-15 14:21:32 +08:00
parent 676dffbf21
commit d71e0de8c3
14 changed files with 35 additions and 30 deletions

View File

@ -12,7 +12,7 @@ typedef UpdateFieldNotifiedValue = Either<CellNotificationData, FlowyError>;
class CellListener {
final String rowId;
final String fieldId;
PublishNotifier<UpdateFieldNotifiedValue> updateCellNotifier = PublishNotifier();
PublishNotifier<UpdateFieldNotifiedValue>? 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<void> stop() async {
await _listener?.stop();
updateCellNotifier.dispose();
updateCellNotifier?.dispose();
updateCellNotifier = null;
}
}

View File

@ -43,7 +43,7 @@ class CheckboxCellBloc extends Bloc<CheckboxCellEvent, CheckboxCellState> {
}
void _startListening() {
_listener.updateCellNotifier.addPublishListener((result) {
_listener.updateCellNotifier?.addPublishListener((result) {
result.fold(
(notificationData) async => await _loadCellData(),
(err) => Log.error(err),

View File

@ -52,7 +52,7 @@ class DateCellBloc extends Bloc<DateCellEvent, DateCellState> {
}
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<DateCellEvent, DateCellState> {
});
_cellListener.start();
_fieldListener.updateFieldNotifier.addPublishListener((result) {
_fieldListener.updateFieldNotifier?.addPublishListener((result) {
result.fold(
(field) {
if (!isClosed) {

View File

@ -59,7 +59,7 @@ class NumberCellBloc extends Bloc<NumberCellEvent, NumberCellState> {
}
void _startListening() {
_cellListener.updateCellNotifier.addPublishListener((result) {
_cellListener.updateCellNotifier?.addPublishListener((result) {
result.fold(
(notificationData) async {
await _getCellData();
@ -69,7 +69,7 @@ class NumberCellBloc extends Bloc<NumberCellEvent, NumberCellState> {
});
_cellListener.start();
_fieldListener.updateFieldNotifier.addPublishListener((result) {
_fieldListener.updateFieldNotifier?.addPublishListener((result) {
result.fold(
(field) => _getCellData(),
(err) => Log.error(err),

View File

@ -64,7 +64,7 @@ class SelectionCellBloc extends Bloc<SelectionCellEvent, SelectionCellState> {
}
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<SelectionCellEvent, SelectionCellState> {
});
_cellListener.start();
_fieldListener.updateFieldNotifier.addPublishListener((result) {
_fieldListener.updateFieldNotifier?.addPublishListener((result) {
result.fold(
(field) => _loadOptions(),
(err) => Log.error(err),

View File

@ -134,7 +134,7 @@ class SelectOptionEditorBloc extends Bloc<SelectOptionEditorEvent, SelectOptionE
}
void _startListening() {
_cellListener.updateCellNotifier.addPublishListener((result) {
_cellListener.updateCellNotifier?.addPublishListener((result) {
result.fold(
(notificationData) => _loadOptions(),
(err) => Log.error(err),
@ -142,7 +142,7 @@ class SelectOptionEditorBloc extends Bloc<SelectOptionEditorEvent, SelectOptionE
});
_cellListener.start();
_fieldListener.updateFieldNotifier.addPublishListener((result) {
_fieldListener.updateFieldNotifier?.addPublishListener((result) {
result.fold(
(field) {
if (!isClosed) {

View File

@ -45,7 +45,7 @@ class FieldCellBloc extends Bloc<FieldCellEvent, FieldCellState> {
}
void _startListening() {
_fieldListener.updateFieldNotifier.addPublishListener((result) {
_fieldListener.updateFieldNotifier?.addPublishListener((result) {
result.fold(
(field) {
if (!isClosed) {

View File

@ -11,7 +11,7 @@ typedef UpdateFieldNotifiedValue = Either<Field, FlowyError>;
class SingleFieldListener {
final String fieldId;
PublishNotifier<UpdateFieldNotifiedValue> updateFieldNotifier = PublishNotifier();
PublishNotifier<UpdateFieldNotifiedValue>? 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<void> stop() async {
await _listener?.stop();
updateFieldNotifier.dispose();
updateFieldNotifier?.dispose();
updateFieldNotifier = null;
}
}

View File

@ -11,7 +11,7 @@ typedef UpdateFieldNotifiedValue = Either<GridFieldChangeset, FlowyError>;
class GridFieldsListener {
final String gridId;
PublishNotifier<UpdateFieldNotifiedValue> updateFieldsNotifier = PublishNotifier();
PublishNotifier<UpdateFieldNotifiedValue>? 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<void> stop() async {
await _listener?.stop();
updateFieldsNotifier.dispose();
updateFieldsNotifier?.dispose();
updateFieldsNotifier = null;
}
}

View File

@ -58,7 +58,7 @@ class GridBloc extends Bloc<GridEvent, GridState> {
}
void _startListening() {
_fieldListener.updateFieldsNotifier.addPublishListener((result) {
_fieldListener.updateFieldsNotifier?.addPublishListener((result) {
result.fold(
(changeset) {
fieldCache.applyChangeset(changeset);

View File

@ -73,7 +73,7 @@ class RowBloc extends Bloc<RowEvent, RowState> {
}
Future<void> _startListening() async {
_rowlistener.updateRowNotifier.addPublishListener((result) {
_rowlistener.updateRowNotifier?.addPublishListener((result) {
result.fold(
(row) => add(RowEvent.didUpdateRow(row)),
(err) => Log.error(err),

View File

@ -12,7 +12,7 @@ typedef UpdateFieldNotifiedValue = Either<List<Field>, FlowyError>;
class RowListener {
final String rowId;
PublishNotifier<UpdateRowNotifiedValue> updateRowNotifier = PublishNotifier();
PublishNotifier<UpdateRowNotifiedValue>? 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<void> stop() async {
await _listener?.stop();
updateRowNotifier.dispose();
updateRowNotifier?.dispose();
updateRowNotifier = null;
}
}

View File

@ -51,7 +51,7 @@ class GridPropertyBloc extends Bloc<GridPropertyEvent, GridPropertyState> {
}
void _startListening() {
_fieldListener.updateFieldsNotifier.addPublishListener((result) {
_fieldListener.updateFieldsNotifier?.addPublishListener((result) {
result.fold(
(changeset) {
_fieldCache.applyChangeset(changeset);

View File

@ -25,6 +25,7 @@ class GridHeaderSliverAdaptor extends StatelessWidget {
create: (context) =>
getIt<GridHeaderBloc>(param1: gridId, param2: fieldCache)..add(const GridHeaderEvent.initial()),
child: BlocBuilder<GridHeaderBloc, GridHeaderState>(
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