Skip to content

Commit

Permalink
Fix checkboxes for boolean not updating
Browse files Browse the repository at this point in the history
  • Loading branch information
gabber235 committed Nov 24, 2024
1 parent 456ebb6 commit 252ae0b
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 65 deletions.
117 changes: 74 additions & 43 deletions app/lib/widgets/inspector/header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import "package:typewriter/widgets/inspector/section_title.dart";

part "header.g.dart";

class FieldHeader extends HookConsumerWidget {
class FieldHeader extends StatefulHookConsumerWidget {
const FieldHeader({
required this.child,
required this.dataBlueprint,
Expand All @@ -44,55 +44,80 @@ class FieldHeader extends HookConsumerWidget {
final bool defaultExpanded;

@override
Widget build(BuildContext context, WidgetRef ref) {
ConsumerState<FieldHeader> createState() => _FieldHeaderState();
}

class _FieldHeaderState extends ConsumerState<FieldHeader> {
late HeaderActions combinedActions;

@override
void initState() {
combinedActions = HeaderActions(
leading: widget.leading,
trailing: widget.trailing,
actions: widget.actions,
);
super.initState();
}

@override
void didUpdateWidget(covariant FieldHeader oldWidget) {
super.didUpdateWidget(oldWidget);

if (widget.leading != oldWidget.leading ||
widget.trailing != oldWidget.trailing ||
widget.actions != oldWidget.actions) {
combinedActions = HeaderActions(
leading: widget.leading,
trailing: widget.trailing,
actions: widget.actions,
);
}
}

@override
Widget build(BuildContext context) {
final parent = Header.maybeOf(context);

final headerActionFilters = ref.watch(headerActionFiltersProvider);
final availableActions = headerActionFilters
.where((filter) => filter.shouldShow(path, dataBlueprint))
.where((filter) => filter.shouldShow(widget.path, widget.dataBlueprint))
.toList();

// If there already is a header for this path, we don't need to create a new
if (parent?.path == path) {
if (parent?.path == widget.path) {
useDelayedExecution(() {
parent?.combineActions(
HeaderActions(
leading: leading +
leading: widget.leading +
filterActions(availableActions, HeaderActionLocation.leading),
trailing: trailing +
trailing: widget.trailing +
filterActions(availableActions, HeaderActionLocation.trailing),
actions: actions +
actions: widget.actions +
filterActions(availableActions, HeaderActionLocation.actions),
),
);
});
return child;
return widget.child;
}

final name =
ref.watch(pathDisplayNameProvider(path)).nullIfEmpty ?? "Fields";
ref.watch(pathDisplayNameProvider(widget.path)).nullIfEmpty ?? "Fields";

final expanded = useState(defaultExpanded);
final expanded = useState(widget.defaultExpanded);
final depth = (parent?.depth ?? -1) + 1;

final combinedActions = useState(
HeaderActions(
leading: leading,
trailing: trailing,
actions: actions,
),
);

return Header(
key: ValueKey(path),
path: path,
key: ValueKey(widget.path),
path: widget.path,
expanded: expanded,
canExpand: canExpand,
canExpand: widget.canExpand,
depth: depth,
combineActions: (actions) =>
combinedActions.value = combinedActions.value.merge(actions),
combineActions: (actions) => setState(() {
combinedActions = combinedActions.merge(actions);
}),
child: Material(
color: canExpand
color: widget.canExpand
? depth.isEven
? Theme.of(context).colorScheme.surface
: Theme.of(context).colorScheme.surfaceContainer
Expand All @@ -110,16 +135,18 @@ class FieldHeader extends HookConsumerWidget {
color: Colors.transparent,
child: InkWell(
borderRadius: BorderRadius.circular(4),
onTap:
canExpand ? () => expanded.value = !expanded.value : null,
onTap: widget.canExpand
? () => expanded.value = !expanded.value
: null,
child: WritersIndicator(
enabled: canExpand && !expanded.value,
provider: fieldWritersProvider(path),
offset:
canExpand ? const Offset(50, 25) : const Offset(15, 15),
enabled: widget.canExpand && !expanded.value,
provider: fieldWritersProvider(widget.path),
offset: widget.canExpand
? const Offset(50, 25)
: const Offset(15, 15),
child: Row(
children: [
if (canExpand)
if (widget.canExpand)
Icon(
expanded.value
? Icons.expand_less
Expand All @@ -128,43 +155,44 @@ class FieldHeader extends HookConsumerWidget {
...createActions(
availableActions,
HeaderActionLocation.leading,
combinedActions.value.leading,
combinedActions.leading,
),
Padding(
padding:
EdgeInsets.symmetric(vertical: canExpand ? 10 : 0),
padding: EdgeInsets.symmetric(
vertical: widget.canExpand ? 10 : 0,
),
child: SectionTitle(
title: name,
),
),
...createActions(
availableActions,
HeaderActionLocation.trailing,
combinedActions.value.trailing,
combinedActions.trailing,
),
const Spacer(),
...createActions(
availableActions,
HeaderActionLocation.actions,
combinedActions.value.actions,
combinedActions.actions,
),
],
),
),
),
),
if (canExpand)
if (widget.canExpand)
Collapsible(
collapsed: !expanded.value,
axis: CollapsibleAxis.vertical,
child: Padding(
padding:
const EdgeInsets.symmetric(horizontal: 6, vertical: 3),
child: child,
child: widget.child,
),
)
else
child,
widget.child,
],
),
),
Expand All @@ -176,8 +204,11 @@ class FieldHeader extends HookConsumerWidget {
HeaderActionLocation location,
) {
return filters
.where((filter) => filter.location(path, dataBlueprint) == location)
.map((filter) => filter.build(path, dataBlueprint))
.where(
(filter) =>
filter.location(widget.path, widget.dataBlueprint) == location,
)
.map((filter) => filter.build(widget.path, widget.dataBlueprint))
.toList();
}

Expand All @@ -190,8 +221,8 @@ class FieldHeader extends HookConsumerWidget {
if (location == HeaderActionLocation.leading) ...actions,
if (location == HeaderActionLocation.trailing) ...actions,
for (final filter in filters)
if (filter.location(path, dataBlueprint) == location)
filter.build(path, dataBlueprint),
if (filter.location(widget.path, widget.dataBlueprint) == location)
filter.build(widget.path, widget.dataBlueprint),
if (location == HeaderActionLocation.actions) ...actions,
].joinWith(() => const SizedBox(width: 8));

Expand Down
52 changes: 30 additions & 22 deletions app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,10 @@ packages:
dependency: "direct main"
description:
name: flutter_animate
sha256: "7c8a6594a9252dad30cc2ef16e33270b6248c4dedc3b3d06c86c4f3f4dc05ae5"
sha256: "5fc5bb5486624a9ed2d3d9a04a9f7a6a92511f36a030531e092ce819ab3091af"
url: "https://pub.dev"
source: hosted
version: "4.5.0"
version: "4.5.1"
flutter_colorpicker:
dependency: "direct main"
description:
Expand Down Expand Up @@ -469,10 +469,10 @@ packages:
dependency: "direct main"
description:
name: flutter_svg
sha256: "578bd8c508144fdaffd4f77b8ef2d8c523602275cd697cc3db284dbd762ef4ce"
sha256: "936d9c1c010d3e234d1672574636f3352b4941ca3decaddd3cafaeb9ad49c471"
url: "https://pub.dev"
source: hosted
version: "2.0.14"
version: "2.0.15"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down Expand Up @@ -641,10 +641,10 @@ packages:
dependency: "direct dev"
description:
name: json_serializable
sha256: ea1432d167339ea9b5bb153f0571d0039607a873d6e04e0117af043f14a1fd4b
sha256: c2fcb3920cf2b6ae6845954186420fca40bc0a8abcc84903b7801f17d7050d7c
url: "https://pub.dev"
source: hosted
version: "6.8.0"
version: "6.9.0"
ktx:
dependency: "direct main"
description:
Expand Down Expand Up @@ -881,10 +881,10 @@ packages:
dependency: "direct main"
description:
name: rive
sha256: "468f0880d49c513e09fdfba26e4abd9d50433c2cf398210b62948d8de3837dd5"
sha256: b44b62feb908610ca6c85e05f4573a66118a23867425926cf06152d171236141
url: "https://pub.dev"
source: hosted
version: "0.13.15"
version: "0.13.17"
rive_common:
dependency: transitive
description:
Expand All @@ -905,10 +905,10 @@ packages:
dependency: transitive
description:
name: riverpod_analyzer_utils
sha256: dc53a659cb543b203cdc35cd4e942ed08ea893eb6ef12029301323bdf18c5d95
sha256: c6b8222b2b483cb87ae77ad147d6408f400c64f060df7a225b127f4afef4f8c8
url: "https://pub.dev"
source: hosted
version: "0.5.7"
version: "0.5.8"
riverpod_annotation:
dependency: "direct main"
description:
Expand All @@ -921,18 +921,18 @@ packages:
dependency: "direct dev"
description:
name: riverpod_generator
sha256: "54458dac2fea976990dc9ed379060db6ae5c8790143f1963fedd0fb99980a326"
sha256: "63546d70952015f0981361636bf8f356d9cfd9d7f6f0815e3c07789a41233188"
url: "https://pub.dev"
source: hosted
version: "2.6.2"
version: "2.6.3"
riverpod_lint:
dependency: "direct dev"
description:
name: riverpod_lint
sha256: "326efc199b87f21053b9a2afbf2aea26c41b3bf6f8ba346ce69126ee17d16ebd"
sha256: "83e4caa337a9840469b7b9bd8c2351ce85abad80f570d84146911b32086fbd99"
url: "https://pub.dev"
source: hosted
version: "2.6.2"
version: "2.6.3"
rxdart:
dependency: transitive
description:
Expand All @@ -953,10 +953,10 @@ packages:
dependency: transitive
description:
name: shelf_web_socket
sha256: "073c147238594ecd0d193f3456a5fe91c4b0abbcc68bf5cd95b36c4e194ac611"
sha256: cc36c297b52866d203dbf9332263c94becc2fe0ceaa9681d07b6ef9807023b67
url: "https://pub.dev"
source: hosted
version: "2.0.0"
version: "2.0.1"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -1166,10 +1166,10 @@ packages:
dependency: transitive
description:
name: url_launcher_linux
sha256: e2b9622b4007f97f504cd64c0128309dfb978ae66adbe944125ed9e1750f06af
sha256: "4e9ba368772369e3e08f231d2301b4ef72b9ff87c31192ef471b380ef29a4935"
url: "https://pub.dev"
source: hosted
version: "3.2.0"
version: "3.2.1"
url_launcher_macos:
dependency: transitive
description:
Expand Down Expand Up @@ -1214,10 +1214,10 @@ packages:
dependency: transitive
description:
name: vector_graphics
sha256: "773c9522d66d523e1c7b25dfb95cc91c26a1e17b107039cfe147285e92de7878"
sha256: "27d5fefe86fb9aace4a9f8375b56b3c292b64d8c04510df230f849850d912cb7"
url: "https://pub.dev"
source: hosted
version: "1.1.14"
version: "1.1.15"
vector_graphics_codec:
dependency: transitive
description:
Expand All @@ -1230,10 +1230,10 @@ packages:
dependency: transitive
description:
name: vector_graphics_compiler
sha256: "26d520739b7c6b5d2a2b3274427874a8390831fd4cd5bb8cfbd7d913477d3a2e"
sha256: ab9ff38fc771e9ee1139320adbe3d18a60327370c218c60752068ebee4b49ab1
url: "https://pub.dev"
source: hosted
version: "1.1.14"
version: "1.1.15"
vector_math:
dependency: transitive
description:
Expand All @@ -1242,6 +1242,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
visibility_detector:
dependency: transitive
description:
name: visibility_detector
sha256: dd5cc11e13494f432d15939c3aa8ae76844c42b723398643ce9addb88a5ed420
url: "https://pub.dev"
source: hosted
version: "0.4.0+2"
vm_service:
dependency: transitive
description:
Expand Down

0 comments on commit 252ae0b

Please sign in to comment.