Skip to content

Commit 2590bc0

Browse files
committed
Refactor colors + fix some unit tests
1 parent efe7817 commit 2590bc0

16 files changed

+129
-68
lines changed

lib/features/roadster/roadster_screen.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ class _RoadsterDetailScreenState extends State<RoadsterDetailScreen>
136136
}
137137

138138
void _scrollToTop() {
139+
if (!mounted || !_scrollController.hasClients) return;
139140
_scrollController.animateTo(
140141
0,
141142
duration: const Duration(milliseconds: 800),

lib/features/roadster/widget/animated_counter_widget.dart

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,27 @@ class _AnimatedCounterWidgetState extends State<AnimatedCounterWidget>
3838
_controller.forward();
3939
}
4040

41+
@override
42+
void didUpdateWidget(covariant AnimatedCounterWidget oldWidget) {
43+
super.didUpdateWidget(oldWidget);
44+
if (oldWidget.value != widget.value ||
45+
oldWidget.duration != widget.duration) {
46+
_controller.duration = widget.duration;
47+
_animation = Tween<double>(
48+
begin: _animation.value,
49+
end: widget.value,
50+
).animate(
51+
CurvedAnimation(
52+
parent: _controller,
53+
curve: Curves.easeOutCubic,
54+
),
55+
);
56+
_controller
57+
..reset()
58+
..forward();
59+
}
60+
}
61+
4162
@override
4263
void dispose() {
4364
_controller.dispose();
@@ -49,18 +70,19 @@ class _AnimatedCounterWidgetState extends State<AnimatedCounterWidget>
4970
return AnimatedBuilder(
5071
animation: _animation,
5172
builder: (context, child) {
73+
final text = widget.decimals > 0
74+
? _animation.value.toStringAsFixed(widget.decimals)
75+
: _animation.value.toInt().toString().replaceAllMapped(
76+
RegExp(r'(\d{1,3})(?=(\d{3})+(?!\d))'),
77+
(Match m) => '${m[1]},',
78+
);
79+
5280
return Text(
53-
widget.decimals > 0
54-
? _animation.value.toStringAsFixed(widget.decimals)
55-
: _animation.value.toInt().toString().replaceAllMapped(
56-
RegExp(r'(\d{1,3})(?=(\d{3})+(?!\d))'),
57-
(Match m) => '${m[1]},',
58-
),
59-
style: const TextStyle(
60-
color: Colors.white,
61-
fontSize: 20,
62-
fontWeight: FontWeight.bold,
63-
),
81+
text,
82+
style: Theme.of(context).textTheme.titleLarge?.copyWith(
83+
color: Theme.of(context).colorScheme.onSurface,
84+
fontWeight: FontWeight.bold,
85+
),
6486
);
6587
},
6688
);

lib/features/roadster/widget/animated_stat_card_widget.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ class AnimatedStatCardWidget extends StatelessWidget {
5353
const SizedBox(height: 8),
5454
Text(
5555
title,
56-
style: const TextStyle(
57-
color: Colors.white60,
56+
style: Theme.of(context).textTheme.bodySmall?.copyWith(
57+
color: Theme.of(context).colorScheme.onSurfaceVariant,
5858
fontSize: 12,
5959
),
6060
),

lib/features/roadster/widget/app_bar/image_carousel.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,11 @@ class ImageCarousel extends StatelessWidget {
7070
animation: pageController,
7171
builder: (context, child) {
7272
var value = 1.0;
73-
if (pageController.position.haveDimensions) {
74-
value = pageController.page! - index;
75-
value = (1 - (value.abs() * 0.3)).clamp(0.0, 1.0);
73+
if (pageController.hasClients) {
74+
final currentPage = pageController.page ??
75+
pageController.initialPage.toDouble();
76+
value =
77+
(1 - ((currentPage - index).abs() * 0.3)).clamp(0.0, 1.0);
7678
}
7779
return Center(
7880
child: _buildAnimatedImageCard(value, images[index]),
@@ -84,4 +86,4 @@ class ImageCarousel extends StatelessWidget {
8486
),
8587
);
8688
}
87-
}
89+
}

lib/features/roadster/widget/app_bar/roadster_app_bar.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ class _RoadsterAppBarState extends State<RoadsterAppBar> {
6868
expandedHeight: 380,
6969
floating: false,
7070
pinned: true,
71-
backgroundColor: Colors.transparent,
7271
flexibleSpace: FlexibleSpaceBar(
7372
title: AnimatedOpacity(
7473
opacity: widget.scrollOffset > 200 ? 1.0 : 0.0,

lib/features/roadster/widget/background/animated_gradient_background.dart

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@ class AnimatedGradientBackground extends StatelessWidget {
1010

1111
@override
1212
Widget build(BuildContext context) {
13+
final isDark = Theme.of(context).brightness == Brightness.dark;
14+
15+
// Define gradients for light and dark themes
16+
final darkColors = [
17+
const Color(0xFF0D0E1C),
18+
const Color(0xFF1A1B3A),
19+
const Color(0xFF2D1B3D),
20+
];
21+
22+
final lightColors = [
23+
const Color(0xFFF0F4FF),
24+
const Color(0xFFE8ECFF),
25+
const Color(0xFFDDE3FF),
26+
];
27+
28+
final colors = isDark ? darkColors : lightColors;
29+
1330
return AnimatedBuilder(
1431
animation: pulseController,
1532
builder: (context, child) {
@@ -19,16 +36,8 @@ class AnimatedGradientBackground extends StatelessWidget {
1936
begin: Alignment.topLeft,
2037
end: Alignment.bottomRight,
2138
colors: [
22-
Color.lerp(
23-
const Color(0xFF0D0E1C),
24-
const Color(0xFF1A1B3A),
25-
pulseController.value,
26-
)!,
27-
Color.lerp(
28-
const Color(0xFF1A1B3A),
29-
const Color(0xFF2D1B3D),
30-
pulseController.value,
31-
)!,
39+
Color.lerp(colors[0], colors[1], pulseController.value)!,
40+
Color.lerp(colors[1], colors[2], pulseController.value)!,
3241
],
3342
),
3443
),

lib/features/roadster/widget/buttons/track_live_button.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class TrackLiveButton extends StatelessWidget {
2626
icon: const Icon(Icons.rocket_launch),
2727
label: Text(S.of(context).trackLive),
2828
backgroundColor: Theme.of(context).colorScheme.primary,
29+
foregroundColor: Theme.of(context).colorScheme.onPrimary,
2930
),
3031
),
3132
);

lib/features/roadster/widget/details_card_widget.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@ class _DetailsCardWidgetState extends State<DetailsCardWidget>
9191
Text(
9292
widget.description1,
9393
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
94-
color: Colors.white70,
94+
color: Theme.of(context).colorScheme.onSurface,
9595
height: 1.5,
9696
),
9797
),
9898
const SizedBox(height: 12),
9999
Text(
100100
widget.description2,
101101
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
102-
color: Colors.white60,
102+
color: Theme.of(context).colorScheme.onSurfaceVariant,
103103
height: 1.4,
104104
),
105105
),

lib/features/roadster/widget/distance_card_widget.dart

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,14 @@ class DistanceCardWidget extends StatelessWidget {
6969
children: [
7070
Text(
7171
title,
72-
style: TextStyle(
73-
color: Theme.of(context)
74-
.colorScheme
75-
.onSurface
76-
.withValues(alpha: 0.7),
77-
fontSize: 14,
78-
),
72+
style:
73+
Theme.of(context).textTheme.bodySmall?.copyWith(
74+
color: Theme.of(context)
75+
.colorScheme
76+
.onSurface
77+
.withValues(alpha: 0.7),
78+
fontSize: 14,
79+
),
7980
),
8081
const SizedBox(height: 4),
8182
Row(
@@ -88,11 +89,14 @@ class DistanceCardWidget extends StatelessWidget {
8889
const SizedBox(width: 4),
8990
Text(
9091
S.of(context).millionKm,
91-
style: TextStyle(
92-
color: color,
93-
fontSize: 16,
94-
fontWeight: FontWeight.bold,
95-
),
92+
style: Theme.of(context)
93+
.textTheme
94+
.bodyMedium
95+
?.copyWith(
96+
color: color,
97+
fontSize: 16,
98+
fontWeight: FontWeight.bold,
99+
),
96100
),
97101
],
98102
),

lib/features/roadster/widget/launch_section_widget.dart

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class LaunchSectionWidget extends StatelessWidget {
1515
Widget build(BuildContext context) {
1616
final l10n = S.of(context);
1717

18+
final scheme = Theme.of(context).colorScheme;
19+
1820
return Card(
1921
elevation: 6,
2022
shape: RoundedRectangleBorder(
@@ -26,8 +28,8 @@ class LaunchSectionWidget extends StatelessWidget {
2628
borderRadius: BorderRadius.circular(16),
2729
gradient: LinearGradient(
2830
colors: [
29-
Colors.orange.withValues(alpha: 0.2),
30-
Colors.red.withValues(alpha: 0.1),
31+
scheme.primary.withValues(alpha: 0.2),
32+
scheme.secondary.withValues(alpha: 0.1),
3133
],
3234
),
3335
),
@@ -38,7 +40,7 @@ class LaunchSectionWidget extends StatelessWidget {
3840
children: [
3941
Icon(
4042
Icons.rocket,
41-
color: Colors.orange[400],
43+
color: scheme.primary,
4244
),
4345
const SizedBox(width: 8),
4446
Text(
@@ -58,17 +60,17 @@ class LaunchSectionWidget extends StatelessWidget {
5860
children: [
5961
Text(
6062
l10n.launchMass,
61-
style:
62-
const TextStyle(color: Colors.white60, fontSize: 12),
63+
style: Theme.of(context).textTheme.bodySmall?.copyWith(
64+
color: scheme.onSurfaceVariant,
65+
),
6366
),
6467
const SizedBox(height: 4),
6568
Text(
6669
massKg,
67-
style: TextStyle(
68-
color: Colors.orange[400],
69-
fontSize: 18,
70-
fontWeight: FontWeight.bold,
71-
),
70+
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
71+
color: scheme.primary,
72+
fontWeight: FontWeight.bold,
73+
),
7274
),
7375
],
7476
),
@@ -77,17 +79,17 @@ class LaunchSectionWidget extends StatelessWidget {
7779
children: [
7880
Text(
7981
l10n.launchVehicle,
80-
style:
81-
const TextStyle(color: Colors.white60, fontSize: 12),
82+
style: Theme.of(context).textTheme.bodySmall?.copyWith(
83+
color: scheme.onSurfaceVariant,
84+
),
8285
),
8386
const SizedBox(height: 4),
8487
Text(
8588
vehicle,
86-
style: TextStyle(
87-
color: Colors.orange[400],
88-
fontSize: 18,
89-
fontWeight: FontWeight.bold,
90-
),
89+
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
90+
color: scheme.primary,
91+
fontWeight: FontWeight.bold,
92+
),
9193
),
9294
],
9395
),

0 commit comments

Comments
 (0)