Skip to content

Commit 72b6f4f

Browse files
committed
refactor(ads): transform NativeAdCardImageStart into a provider-agnostic widget
- Remove generic ad model dependency - Accept NativeAdView as a parameter for ad rendering - Simplify widget structure and increase reusability - Update documentation to reflect new functionality
1 parent 66f5968 commit 72b6f4f

File tree

1 file changed

+9
-62
lines changed

1 file changed

+9
-62
lines changed
Lines changed: 9 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,29 @@
11
import 'package:flutter/material.dart';
2-
import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/native_ad.dart'
3-
as app_native_ad;
2+
import 'package:flutter_news_app_mobile_client_full_source_code/ads/widgets/native_ad_view.dart';
43
import 'package:ui_kit/ui_kit.dart';
54

65
/// {@template native_ad_card_image_start}
7-
/// A generic widget to display a native ad with a small image at the start.
6+
/// A widget to display a native ad with a small image at the start,
7+
/// visually mimicking [HeadlineTileImageStart].
88
///
9-
/// This widget is designed to visually match [HeadlineTileImageStart]
10-
/// and uses a generic [app_native_ad.NativeAd] model.
9+
/// This widget accepts a [NativeAdView] to render the actual ad content,
10+
/// ensuring it remains provider-agnostic.
1111
/// {@endtemplate}
1212
class NativeAdCardImageStart extends StatelessWidget {
1313
/// {@macro native_ad_card_image_start}
14-
const NativeAdCardImageStart({required this.nativeAd, super.key});
14+
const NativeAdCardImageStart({required this.adView, super.key});
1515

16-
/// The generic native ad data to display.
17-
final app_native_ad.NativeAd nativeAd;
16+
/// The widget responsible for rendering the native ad content.
17+
final NativeAdView adView;
1818

1919
@override
2020
Widget build(BuildContext context) {
21-
final theme = Theme.of(context);
22-
final textTheme = theme.textTheme;
23-
final colorScheme = theme.colorScheme;
24-
25-
// Placeholder content for the generic ad.
26-
// The actual rendering of the SDK-specific ad will happen in a child widget.
2721
return Card(
2822
margin: const EdgeInsets.symmetric(
2923
horizontal: AppSpacing.paddingMedium,
3024
vertical: AppSpacing.xs,
3125
),
32-
child: Padding(
33-
padding: const EdgeInsets.all(AppSpacing.md),
34-
child: Row(
35-
crossAxisAlignment: CrossAxisAlignment.start,
36-
children: [
37-
SizedBox(
38-
width: 72, // Standard small image size
39-
height: 72,
40-
child: ClipRRect(
41-
borderRadius: BorderRadius.circular(AppSpacing.xs),
42-
child: ColoredBox(
43-
color: colorScheme.surfaceContainerHighest,
44-
child: Icon(
45-
Icons.campaign_outlined,
46-
color: colorScheme.onSurfaceVariant,
47-
size: AppSpacing.xl,
48-
),
49-
),
50-
),
51-
),
52-
const SizedBox(width: AppSpacing.md), // Always add spacing
53-
Expanded(
54-
child: Column(
55-
crossAxisAlignment: CrossAxisAlignment.start,
56-
children: [
57-
Text(
58-
'Ad: ${nativeAd.id}', // Displaying ID for now
59-
style: textTheme.titleMedium?.copyWith(
60-
fontWeight: FontWeight.w500,
61-
),
62-
maxLines: 2,
63-
overflow: TextOverflow.ellipsis,
64-
),
65-
const SizedBox(height: AppSpacing.sm),
66-
Text(
67-
'This is a generic ad placeholder.',
68-
style: textTheme.bodySmall?.copyWith(
69-
color: colorScheme.primary.withOpacity(0.7),
70-
),
71-
maxLines: 2,
72-
overflow: TextOverflow.ellipsis,
73-
),
74-
],
75-
),
76-
),
77-
],
78-
),
79-
),
26+
child: adView, // Directly render the provided NativeAdView
8027
);
8128
}
8229
}

0 commit comments

Comments
 (0)