Skip to content

Commit

Permalink
Bug Fix: add didUpdateWidgets to trigger rebuild and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
NonymousMorlock committed Dec 25, 2023
1 parent 599c93c commit 2da8c0b
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 0 deletions.
4 changes: 4 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions lib/widgets/clay_animated_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ class _ClayAnimatedContainerState extends State<ClayAnimatedContainer> {
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;
Expand Down
16 changes: 16 additions & 0 deletions lib/widgets/clay_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ class _ClayContainerState extends State<ClayContainer> {
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;
Expand Down
14 changes: 14 additions & 0 deletions lib/widgets/clay_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ class _ClayTextState extends State<ClayText> {
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;
Expand Down
16 changes: 16 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ dependencies:
sdk: flutter

dev_dependencies:
flutter_lints: ^3.0.1
flutter_test:
sdk: flutter

flutter:
14 changes: 14 additions & 0 deletions test/clay_containers_test.dart
Original file line number Diff line number Diff line change
@@ -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(),
),
);
});
}

0 comments on commit 2da8c0b

Please sign in to comment.