mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: fix warnings
This commit is contained in:
parent
8b4c46f75b
commit
d390ef9a3a
@ -17,6 +17,7 @@ part 'cell_service.freezed.dart';
|
|||||||
typedef GridDefaultCellContext = GridCellContext<Cell>;
|
typedef GridDefaultCellContext = GridCellContext<Cell>;
|
||||||
typedef GridSelectOptionCellContext = GridCellContext<SelectOptionContext>;
|
typedef GridSelectOptionCellContext = GridCellContext<SelectOptionContext>;
|
||||||
|
|
||||||
|
// ignore: must_be_immutable
|
||||||
class GridCellContext<T> extends Equatable {
|
class GridCellContext<T> extends Equatable {
|
||||||
final GridCell gridCell;
|
final GridCell gridCell;
|
||||||
final GridCellCache cellCache;
|
final GridCellCache cellCache;
|
||||||
@ -76,7 +77,6 @@ class GridCellContext<T> extends Equatable {
|
|||||||
|
|
||||||
if (cellDataLoader.reloadOnFieldChanged) {
|
if (cellDataLoader.reloadOnFieldChanged) {
|
||||||
_onFieldChangedFn = () {
|
_onFieldChangedFn = () {
|
||||||
Log.info("reloadCellData ");
|
|
||||||
_loadData();
|
_loadData();
|
||||||
};
|
};
|
||||||
cellCache.addListener(cacheKey, _onFieldChangedFn!);
|
cellCache.addListener(cacheKey, _onFieldChangedFn!);
|
||||||
@ -200,6 +200,7 @@ class GridCellCacheKey {
|
|||||||
|
|
||||||
abstract class GridCellFieldDelegate {
|
abstract class GridCellFieldDelegate {
|
||||||
void onFieldChanged(void Function(String) callback);
|
void onFieldChanged(void Function(String) callback);
|
||||||
|
void dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
class GridCellCache {
|
class GridCellCache {
|
||||||
@ -279,6 +280,10 @@ class GridCellCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> dispose() async {
|
||||||
|
fieldDelegate.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CellService {
|
class CellService {
|
||||||
|
@ -55,8 +55,9 @@ class GridBloc extends Bloc<GridEvent, GridState> {
|
|||||||
@override
|
@override
|
||||||
Future<void> close() async {
|
Future<void> close() async {
|
||||||
await _gridService.closeGrid();
|
await _gridService.closeGrid();
|
||||||
await fieldCache.dispose();
|
await cellCache.dispose();
|
||||||
await rowCache.dispose();
|
await rowCache.dispose();
|
||||||
|
await fieldCache.dispose();
|
||||||
return super.close();
|
return super.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,10 +54,14 @@ class FieldsNotifier extends ChangeNotifier {
|
|||||||
List<Field> get fields => _fields;
|
List<Field> get fields => _fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef ChangesetListener = void Function(GridFieldChangeset);
|
||||||
|
|
||||||
class GridFieldCache {
|
class GridFieldCache {
|
||||||
final String gridId;
|
final String gridId;
|
||||||
late final GridFieldsListener _fieldListener;
|
late final GridFieldsListener _fieldListener;
|
||||||
final FieldsNotifier _fieldNotifier = FieldsNotifier();
|
final FieldsNotifier _fieldNotifier = FieldsNotifier();
|
||||||
|
final List<ChangesetListener> _changesetListener = [];
|
||||||
|
|
||||||
GridFieldCache({required this.gridId}) {
|
GridFieldCache({required this.gridId}) {
|
||||||
_fieldListener = GridFieldsListener(gridId: gridId);
|
_fieldListener = GridFieldsListener(gridId: gridId);
|
||||||
_fieldListener.start(onFieldsChanged: (result) {
|
_fieldListener.start(onFieldsChanged: (result) {
|
||||||
@ -66,6 +70,9 @@ class GridFieldCache {
|
|||||||
_deleteFields(changeset.deletedFields);
|
_deleteFields(changeset.deletedFields);
|
||||||
_insertFields(changeset.insertedFields);
|
_insertFields(changeset.insertedFields);
|
||||||
_updateFields(changeset.updatedFields);
|
_updateFields(changeset.updatedFields);
|
||||||
|
for (final listener in _changesetListener) {
|
||||||
|
listener(changeset);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
(err) => Log.error(err),
|
(err) => Log.error(err),
|
||||||
);
|
);
|
||||||
@ -77,8 +84,6 @@ class GridFieldCache {
|
|||||||
_fieldNotifier.dispose();
|
_fieldNotifier.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void applyChangeset(GridFieldChangeset changeset) {}
|
|
||||||
|
|
||||||
UnmodifiableListView<Field> get unmodifiableFields => UnmodifiableListView(_fieldNotifier.fields);
|
UnmodifiableListView<Field> get unmodifiableFields => UnmodifiableListView(_fieldNotifier.fields);
|
||||||
|
|
||||||
List<Field> get clonedFields => [..._fieldNotifier.fields];
|
List<Field> get clonedFields => [..._fieldNotifier.fields];
|
||||||
@ -111,6 +116,17 @@ class GridFieldCache {
|
|||||||
_fieldNotifier.removeListener(f);
|
_fieldNotifier.removeListener(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addChangesetListener(ChangesetListener listener) {
|
||||||
|
_changesetListener.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
void removeChangesetListener(ChangesetListener listener) {
|
||||||
|
final index = _changesetListener.indexWhere((element) => element == listener);
|
||||||
|
if (index != -1) {
|
||||||
|
_changesetListener.removeAt(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _deleteFields(List<FieldOrder> deletedFields) {
|
void _deleteFields(List<FieldOrder> deletedFields) {
|
||||||
if (deletedFields.isEmpty) {
|
if (deletedFields.isEmpty) {
|
||||||
return;
|
return;
|
||||||
@ -172,14 +188,26 @@ class GridRowCacheDelegateImpl extends GridRowFieldDelegate {
|
|||||||
|
|
||||||
class GridCellCacheDelegateImpl extends GridCellFieldDelegate {
|
class GridCellCacheDelegateImpl extends GridCellFieldDelegate {
|
||||||
final GridFieldCache _cache;
|
final GridFieldCache _cache;
|
||||||
|
ChangesetListener? _changesetFn;
|
||||||
GridCellCacheDelegateImpl(GridFieldCache cache) : _cache = cache;
|
GridCellCacheDelegateImpl(GridFieldCache cache) : _cache = cache;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onFieldChanged(void Function(String) callback) {
|
void onFieldChanged(void Function(String) callback) {
|
||||||
_cache.addListener(onChanged: (fields) {
|
changesetFn(GridFieldChangeset changeset) {
|
||||||
for (final field in fields) {
|
for (final updatedField in changeset.updatedFields) {
|
||||||
callback(field.id);
|
callback(updatedField.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_cache.addChangesetListener(changesetFn);
|
||||||
|
_changesetFn = changesetFn;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
if (_changesetFn != null) {
|
||||||
|
_cache.removeChangesetListener(_changesetFn!);
|
||||||
|
_changesetFn = null;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ import 'package:app_flowy/workspace/application/grid/prelude.dart';
|
|||||||
import 'package:app_flowy/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart';
|
import 'package:app_flowy/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart';
|
||||||
import 'package:flowy_infra/theme.dart';
|
import 'package:flowy_infra/theme.dart';
|
||||||
import 'package:flowy_infra_ui/style_widget/text.dart';
|
import 'package:flowy_infra_ui/style_widget/text.dart';
|
||||||
|
// ignore: unused_import
|
||||||
import 'package:flowy_sdk/log.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 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
@ -43,7 +44,7 @@ class _SingleSelectCellState extends State<SingleSelectCell> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
Log.info("init widget $hashCode");
|
// Log.trace("init widget $hashCode");
|
||||||
_cellBloc = getIt<SelectionCellBloc>(param1: widget.cellContext)..add(const SelectionCellEvent.initial());
|
_cellBloc = getIt<SelectionCellBloc>(param1: widget.cellContext)..add(const SelectionCellEvent.initial());
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
@ -51,7 +52,7 @@ class _SingleSelectCellState extends State<SingleSelectCell> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = context.watch<AppTheme>();
|
final theme = context.watch<AppTheme>();
|
||||||
Log.info("build widget $hashCode");
|
// Log.trace("build widget $hashCode");
|
||||||
return BlocProvider.value(
|
return BlocProvider.value(
|
||||||
value: _cellBloc,
|
value: _cellBloc,
|
||||||
child: BlocBuilder<SelectionCellBloc, SelectionCellState>(
|
child: BlocBuilder<SelectionCellBloc, SelectionCellState>(
|
||||||
@ -83,18 +84,14 @@ class _SingleSelectCellState extends State<SingleSelectCell> {
|
|||||||
@override
|
@override
|
||||||
void didUpdateWidget(covariant SingleSelectCell oldWidget) {
|
void didUpdateWidget(covariant SingleSelectCell oldWidget) {
|
||||||
if (oldWidget.cellContext != widget.cellContext) {
|
if (oldWidget.cellContext != widget.cellContext) {
|
||||||
// setState(() {
|
// Log.trace("did update widget $hashCode");
|
||||||
|
|
||||||
// });
|
|
||||||
// _cellBloc = getIt<SelectionCellBloc>(param1: widget.cellContext)..add(const SelectionCellEvent.initial());
|
|
||||||
Log.info("did update widget $hashCode");
|
|
||||||
}
|
}
|
||||||
super.didUpdateWidget(oldWidget);
|
super.didUpdateWidget(oldWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> dispose() async {
|
Future<void> dispose() async {
|
||||||
Log.info("dispose widget $hashCode");
|
// Log.trace("dispose widget $hashCode");
|
||||||
_cellBloc.close();
|
_cellBloc.close();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ class Log {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void trace(dynamic msg) {
|
static void trace(dynamic msg) {
|
||||||
Log.shared._logger.d(msg);
|
Log.shared._logger.v(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void error(dynamic msg) {
|
static void error(dynamic msg) {
|
||||||
|
@ -3,17 +3,15 @@ use crate::manager::GridUser;
|
|||||||
use crate::services::block_meta_editor::ClientGridBlockMetaEditor;
|
use crate::services::block_meta_editor::ClientGridBlockMetaEditor;
|
||||||
use crate::services::persistence::block_index::BlockIndexPersistence;
|
use crate::services::persistence::block_index::BlockIndexPersistence;
|
||||||
use crate::services::row::{group_row_orders, GridBlockSnapshot};
|
use crate::services::row::{group_row_orders, GridBlockSnapshot};
|
||||||
use std::borrow::Cow;
|
|
||||||
|
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use flowy_error::{FlowyError, FlowyResult};
|
use flowy_error::FlowyResult;
|
||||||
use flowy_grid_data_model::entities::{
|
use flowy_grid_data_model::entities::{
|
||||||
Cell, CellChangeset, CellMeta, GridBlockMeta, GridBlockMetaChangeset, GridRowsChangeset, IndexRowOrder, Row,
|
CellChangeset, CellMeta, GridBlockMeta, GridBlockMetaChangeset, GridRowsChangeset, IndexRowOrder, Row, RowMeta,
|
||||||
RowMeta, RowMetaChangeset, RowOrder, UpdatedRowOrder,
|
RowMetaChangeset, RowOrder, UpdatedRowOrder,
|
||||||
};
|
};
|
||||||
use flowy_revision::disk::SQLiteGridBlockMetaRevisionPersistence;
|
use flowy_revision::disk::SQLiteGridBlockMetaRevisionPersistence;
|
||||||
use flowy_revision::{RevisionManager, RevisionPersistence};
|
use flowy_revision::{RevisionManager, RevisionPersistence};
|
||||||
use lib_infra::future::FutureResult;
|
use std::borrow::Cow;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
@ -430,11 +430,6 @@ impl ClientGridEditor {
|
|||||||
self.grid_pad.read().await.delta_bytes()
|
self.grid_pad.read().await.delta_bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn row_builder(&self, row_meta: Arc<RowMeta>) -> FlowyResult<Option<Row>> {
|
|
||||||
let field_metas = self.get_field_metas::<FieldOrder>(None).await?;
|
|
||||||
Ok(make_rows_from_row_metas(&field_metas, &[row_meta]).pop())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn modify<F>(&self, f: F) -> FlowyResult<()>
|
async fn modify<F>(&self, f: F) -> FlowyResult<()>
|
||||||
where
|
where
|
||||||
F: for<'a> FnOnce(&'a mut GridMetaPad) -> FlowyResult<Option<GridChangeset>>,
|
F: for<'a> FnOnce(&'a mut GridMetaPad) -> FlowyResult<Option<GridChangeset>>,
|
||||||
|
@ -48,7 +48,7 @@ pub(crate) fn make_row_orders_from_row_metas(row_metas: &[Arc<RowMeta>]) -> Vec<
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn make_row_from_row_meta(fields: &[FieldMeta], row_meta: Arc<RowMeta>) -> Option<Row> {
|
pub(crate) fn make_row_from_row_meta(fields: &[FieldMeta], row_meta: Arc<RowMeta>) -> Option<Row> {
|
||||||
make_rows_from_row_metas(fields, &vec![row_meta]).pop()
|
make_rows_from_row_metas(fields, &[row_meta]).pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn make_rows_from_row_metas(fields: &[FieldMeta], row_metas: &[Arc<RowMeta>]) -> Vec<Row> {
|
pub(crate) fn make_rows_from_row_metas(fields: &[FieldMeta], row_metas: &[Arc<RowMeta>]) -> Vec<Row> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user