Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
chore: show and hide property
appflowyaa9e3d065b74
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.dartindex a0dd50a633..ab618b0fa9 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@@ -1,40 +1,66 @@import 'package:app_flowy/workspace/application/grid/field/field_service.dart';+import 'package:app_flowy/workspace/application/grid/field/grid_listenr.dart';import 'package:flowy_sdk/log.dart';import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart';import 'package:flutter_bloc/flutter_bloc.dart';import 'package:freezed_annotation/freezed_annotation.dart';import 'dart:async';-import 'package:dartz/dartz.dart';part 'property_bloc.freezed.dart';class GridPropertyBloc extends Bloc<GridPropertyEvent, GridPropertyState> {final FieldService _service;+ final GridFieldsListener _fieldListener;+GridPropertyBloc({required String gridId, required List<Field> fields}): _service = FieldService(gridId: gridId),+ _fieldListener = GridFieldsListener(gridId: gridId),super(GridPropertyState.initial(gridId, fields)) {on<GridPropertyEvent>((event, emit) async {- await event.map(setFieldVisibility: (_SetFieldVisibility value) async {- final result = await _service.updateField(fieldId: value.fieldId, visibility: value.visibility);- result.fold(- (l) => null,- (err) => Log.error(err),- );- });+ await event.map(+ initial: (_Initial value) {+ _startListening();+ },+ setFieldVisibility: (_SetFieldVisibility value) async {+ final result = await _service.updateField(fieldId: value.fieldId, visibility: value.visibility);+ result.fold(+ (l) => null,+ (err) => Log.error(err),+ );+ },+ didReceiveFieldUpdate: (_DidReceiveFieldUpdate value) {+ emit(state.copyWith(fields: value.fields));+ },+ );},);}@overrideFuture<void> close() async {+ await _fieldListener.stop();return super.close();}++ void _startListening() {+ _fieldListener.updateFieldsNotifier.addPublishListener((result) {+ result.fold(+ (fields) {+ add(GridPropertyEvent.didReceiveFieldUpdate(fields));+ },+ (err) => Log.error(err),+ );+ });+ _fieldListener.start();+ }}@freezedclass GridPropertyEvent with _$GridPropertyEvent {+ const factory GridPropertyEvent.initial() = _Initial;const factory GridPropertyEvent.setFieldVisibility(String fieldId, bool visibility) = _SetFieldVisibility;+ const factory GridPropertyEvent.didReceiveFieldUpdate(List<Field> fields) = _DidReceiveFieldUpdate;}@freezeddiff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/grid_page.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/grid_page.dartindex c8c5cfd7b2..83bce9c7ef 100755--- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/grid_page.dart+++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/grid_page.dart@@ -148,11 +148,13 @@ class _FlowyGridState extends State<FlowyGrid> {return BlocBuilder<GridBloc, GridState>(buildWhen: (previous, current) => previous.fields.length != current.fields.length,builder: (context, state) {- return SliverPersistentHeader(- delegate: GridHeaderDelegate(gridId: gridId, fields: List.from(state.fields)),- floating: true,- pinned: true,- );+ return GridHeader(gridId: gridId, fields: List.from(state.fields));++ // return SliverPersistentHeader(+ // delegate: GridHeaderDelegate(gridId: gridId, fields: List.from(state.fields)),+ // floating: true,+ // pinned: true,+ // );},);}diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/content/number_cell.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/content/number_cell.dartindex 6983cc1015..bc51829412 100644--- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/content/number_cell.dart+++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/content/number_cell.dart@@ -38,7 +38,7 @@ class _NumberCellState extends State<NumberCell> {@overrideFuture<void> dispose() async {- await _cellBloc.close();+ _cellBloc.close();super.dispose();}}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.dartindex be025501a0..80a7a51d59 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@@ -12,15 +12,41 @@ import 'package:flutter_bloc/flutter_bloc.dart';import 'field_editor.dart';import 'field_cell.dart';-class GridHeaderDelegate extends SliverPersistentHeaderDelegate {+class GridHeader extends StatelessWidget {+ final String gridId;+ final List<Field> fields;+ const GridHeader({Key? key, required this.gridId, required this.fields}) : super(key: key);++ @override+ Widget build(BuildContext context) {+ return BlocProvider(+ create: (context) {+ final bloc = getIt<GridHeaderBloc>(param1: gridId, param2: fields);+ bloc.add(const GridHeaderEvent.initial());+ return bloc;+ },+ child: BlocBuilder<GridHeaderBloc, GridHeaderState>(+ builder: (context, state) {+ return SliverPersistentHeader(+ delegate: _GridHeaderDelegate(gridId: gridId, fields: List.from(state.fields)),+ floating: true,+ pinned: true,+ );+ },+ ),+ );+ }+}++class _GridHeaderDelegate extends SliverPersistentHeaderDelegate {final String gridId;final List<Field> fields;- GridHeaderDelegate({required this.gridId, required this.fields});+ _GridHeaderDelegate({required this.gridId, required this.fields});@overrideWidget build(BuildContext context, double shrinkOffset, bool overlapsContent) {- return GridHeader(gridId: gridId, fields: fields, key: ObjectKey(fields));+ return _GridHeaderWidget(gridId: gridId, fields: fields, key: ObjectKey(fields));}@override@@ -31,47 +57,42 @@ class GridHeaderDelegate extends SliverPersistentHeaderDelegate {@overridebool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) {- if (oldDelegate is GridHeaderDelegate) {+ if (oldDelegate is _GridHeaderDelegate) {return fields != oldDelegate.fields;}- return false;+ return true;}}-class GridHeader extends StatelessWidget {- final List<Field> fields;+class _GridHeaderWidget extends StatelessWidget {final String gridId;- const GridHeader({required this.gridId, required this.fields, Key? key}) : super(key: key);+ final List<Field> fields;++ const _GridHeaderWidget({required this.gridId, required this.fields, Key? key}) : super(key: key);@overrideWidget build(BuildContext context) {final theme = context.watch<AppTheme>();- return BlocProvider(- create: (context) {- final bloc = getIt<GridHeaderBloc>(param1: gridId, param2: fields);- bloc.add(const GridHeaderEvent.initial());- return bloc;+ return BlocBuilder<GridHeaderBloc, GridHeaderState>(+ builder: (context, state) {+ final cells = state.fields.map(+ (field) => GridFieldCell(+ GridFieldCellContext(gridId: gridId, field: field),+ ),+ );++ final row = Row(+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ const _HeaderLeading(),+ ...cells,+ _HeaderTrailing(gridId: gridId),+ ],+ key: UniqueKey(),+ );++ return Container(height: GridSize.headerHeight, color: theme.surface, child: row);},- child: BlocBuilder<GridHeaderBloc, GridHeaderState>(- builder: (context, state) {- final cells = state.fields.map(- (field) => GridFieldCell(- GridFieldCellContext(gridId: gridId, field: field),- ),- );-- final row = Row(- crossAxisAlignment: CrossAxisAlignment.stretch,- children: [- const _HeaderLeading(),- ...cells,- _HeaderTrailing(gridId: gridId),- ],- );-- return Container(color: theme.surface, child: row);- },- ),);}}diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/toolbar/grid_property.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/toolbar/grid_property.dartindex b1c57a1530..9951e6ba65 100644--- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/toolbar/grid_property.dart+++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/toolbar/grid_property.dart@@ -42,7 +42,8 @@ class GridPropertyList extends StatelessWidget with FlowyOverlayDelegate {@overrideWidget build(BuildContext context) {return BlocProvider(- create: (context) => getIt<GridPropertyBloc>(param1: gridId, param2: fields),+ create: (context) =>+ getIt<GridPropertyBloc>(param1: gridId, param2: fields)..add(const GridPropertyEvent.initial()),child: BlocBuilder<GridPropertyBloc, GridPropertyState>(builder: (context, state) {final cells = state.fields.map((field) {