From 2da8c0b52e5aa2c7a2aaf0427db4bcc03c3c7a52 Mon Sep 17 00:00:00 2001 From: NonymousMorlock Date: Mon, 25 Dec 2023 13:35:25 +0000 Subject: [PATCH] Bug Fix: add didUpdateWidgets to trigger rebuild and updates --- analysis_options.yaml | 4 ++++ lib/widgets/clay_animated_container.dart | 17 +++++++++++++++++ lib/widgets/clay_container.dart | 16 ++++++++++++++++ lib/widgets/clay_text.dart | 14 ++++++++++++++ pubspec.lock | 16 ++++++++++++++++ pubspec.yaml | 2 ++ test/clay_containers_test.dart | 14 ++++++++++++++ 7 files changed, 83 insertions(+) create mode 100644 analysis_options.yaml create mode 100644 test/clay_containers_test.dart diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..a5744c1 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,4 @@ +include: package:flutter_lints/flutter.yaml + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/lib/widgets/clay_animated_container.dart b/lib/widgets/clay_animated_container.dart index f3085ab..0fbb3ea 100644 --- a/lib/widgets/clay_animated_container.dart +++ b/lib/widgets/clay_animated_container.dart @@ -72,6 +72,23 @@ class _ClayAnimatedContainerState extends State { emboss = widget.emboss ?? clayTheme?.emboss ?? false; } + @override + void didUpdateWidget(covariant ClayAnimatedContainer oldWidget) { + super.didUpdateWidget(oldWidget); + final clayTheme = context.clayTheme; + height = widget.height ?? clayTheme?.height; + width = widget.width ?? clayTheme?.width; + color = widget.color ?? clayTheme?.color ?? const Color(0xFFf0f0f0); + parentColor = widget.parentColor ?? clayTheme?.parentColor; + surfaceColor = widget.surfaceColor ?? clayTheme?.surfaceColor; + borderRadius = widget.borderRadius ?? clayTheme?.borderRadius; + customBorderRadius = + widget.customBorderRadius ?? clayTheme?.customBorderRadius; + depth = widget.depth ?? clayTheme?.depth ?? 20; + spread = widget.spread ?? clayTheme?.spread ?? 6; + emboss = widget.emboss ?? clayTheme?.emboss ?? false; + } + @override Widget build(BuildContext context) { var colorValue = color; diff --git a/lib/widgets/clay_container.dart b/lib/widgets/clay_container.dart index c442f1f..c161cd1 100644 --- a/lib/widgets/clay_container.dart +++ b/lib/widgets/clay_container.dart @@ -64,6 +64,22 @@ class _ClayContainerState extends State { spread = widget.spread ?? clayTheme?.spread ?? 6; } + @override + void didUpdateWidget(covariant ClayContainer oldWidget) { + super.didUpdateWidget(oldWidget); + final clayTheme = context.clayTheme; + height = widget.height ?? clayTheme?.height; + width = widget.width ?? clayTheme?.width; + color = widget.color ?? clayTheme?.color ?? const Color(0xFFf0f0f0); + parentColor = widget.parentColor ?? clayTheme?.parentColor; + surfaceColor = widget.surfaceColor ?? clayTheme?.surfaceColor; + borderRadius = widget.borderRadius ?? clayTheme?.borderRadius; + customBorderRadius = + widget.customBorderRadius ?? clayTheme?.customBorderRadius; + depth = widget.depth ?? clayTheme?.depth ?? 20; + spread = widget.spread ?? clayTheme?.spread ?? 6; + } + @override Widget build(BuildContext context) { var colorValue = color; diff --git a/lib/widgets/clay_text.dart b/lib/widgets/clay_text.dart index b6ebca7..46f0bdb 100644 --- a/lib/widgets/clay_text.dart +++ b/lib/widgets/clay_text.dart @@ -54,6 +54,20 @@ class _ClayTextState extends State { emboss = widget.emboss ?? textTheme?.emboss ?? false; } + @override + void didUpdateWidget(covariant ClayText oldWidget) { + super.didUpdateWidget(oldWidget); + final textTheme = context.clayTheme?.textTheme; + color = widget.color ?? textTheme?.color ?? const Color(0xFFf0f0f0); + parentColor = widget.parentColor ?? textTheme?.parentColor; + textColor = widget.textColor ?? textTheme?.textColor; + style = widget.style ?? textTheme?.style ?? const TextStyle(); + spread = widget.spread ?? textTheme?.spread; + depth = widget.depth ?? textTheme?.depth ?? 40; + size = widget.size ?? textTheme?.size ?? 14; + emboss = widget.emboss ?? textTheme?.emboss ?? false; + } + double? _getSpread(double base) { final calculated = (base / 10).floor().toDouble(); return calculated == 0 ? 1 : calculated; diff --git a/pubspec.lock b/pubspec.lock index 7e0fe89..84b8305 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -54,11 +54,27 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_lints: + dependency: "direct dev" + description: + name: flutter_lints + sha256: e2a421b7e59244faef694ba7b30562e489c2b489866e505074eb005cd7060db7 + url: "https://pub.dev" + source: hosted + version: "3.0.1" flutter_test: dependency: "direct dev" description: flutter source: sdk version: "0.0.0" + lints: + dependency: transitive + description: + name: lints + sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290 + url: "https://pub.dev" + source: hosted + version: "3.0.0" matcher: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index a1fc22e..e701d0c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,6 +11,8 @@ dependencies: sdk: flutter dev_dependencies: + flutter_lints: ^3.0.1 flutter_test: sdk: flutter + flutter: \ No newline at end of file diff --git a/test/clay_containers_test.dart b/test/clay_containers_test.dart new file mode 100644 index 0000000..c20efe5 --- /dev/null +++ b/test/clay_containers_test.dart @@ -0,0 +1,14 @@ +import 'package:clay_containers/clay_containers.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('ClayContainer can have a child.', (WidgetTester tester) async { + await tester.pumpWidget( + ClayContainer( + color: Colors.grey, + child: Container(), + ), + ); + }); +}