Skip to content

Commit 1467b26

Browse files
committed
feat(ads): add local interstitial ad dialog widget
- Create a new dialog widget for displaying local interstitial ads - Implement full-screen dialog with ad image and navigation functionality - Add close button for dismissing the dialog - Include error handling for image loading
1 parent 60f513a commit 1467b26

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import 'package:core/core.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:go_router/go_router.dart';
4+
import 'package:ui_kit/ui_kit.dart';
5+
6+
/// {@template local_interstitial_ad_dialog}
7+
/// A dialog widget that displays a [LocalInterstitialAd].
8+
///
9+
/// This dialog is designed to be shown as a full-screen overlay,
10+
/// presenting the ad's image and providing a way to dismiss it or
11+
/// navigate to the ad's target URL.
12+
/// {@endtemplate}
13+
class LocalInterstitialAdDialog extends StatelessWidget {
14+
/// {@macro local_interstitial_ad_dialog}
15+
const LocalInterstitialAdDialog({
16+
required this.localInterstitialAd,
17+
super.key,
18+
});
19+
20+
/// The [LocalInterstitialAd] to display.
21+
final LocalInterstitialAd localInterstitialAd;
22+
23+
@override
24+
Widget build(BuildContext context) {
25+
final theme = Theme.of(context);
26+
return Dialog.fullscreen(
27+
backgroundColor: theme.colorScheme.surface,
28+
child: Stack(
29+
children: [
30+
Center(
31+
child: SingleChildScrollView(
32+
child: Column(
33+
mainAxisAlignment: MainAxisAlignment.center,
34+
children: [
35+
if (localInterstitialAd.imageUrl.isNotEmpty)
36+
Padding(
37+
padding: const EdgeInsets.all(AppSpacing.lg),
38+
child: InkWell(
39+
onTap: () {
40+
// Navigate to the target URL when the ad image is tapped.
41+
// Using context.go to open external URL.
42+
context.go(localInterstitialAd.targetUrl);
43+
},
44+
child: Image.network(
45+
localInterstitialAd.imageUrl,
46+
fit: BoxFit.contain,
47+
errorBuilder: (context, error, stackTrace) =>
48+
const SizedBox.shrink(),
49+
),
50+
),
51+
),
52+
const SizedBox(height: AppSpacing.lg),
53+
Text(
54+
'Local Interstitial Ad',
55+
style: theme.textTheme.titleLarge?.copyWith(
56+
color: theme.colorScheme.onSurface,
57+
),
58+
textAlign: TextAlign.center,
59+
),
60+
const SizedBox(height: AppSpacing.md),
61+
Text(
62+
'This is a full-screen advertisement.',
63+
style: theme.textTheme.bodyMedium?.copyWith(
64+
color: theme.colorScheme.onSurfaceVariant,
65+
),
66+
textAlign: TextAlign.center,
67+
),
68+
],
69+
),
70+
),
71+
),
72+
Positioned(
73+
top: AppSpacing.lg,
74+
right: AppSpacing.lg,
75+
child: IconButton(
76+
icon: Icon(
77+
Icons.close,
78+
color: theme.colorScheme.onSurface,
79+
),
80+
onPressed: () {
81+
// Dismiss the dialog.
82+
Navigator.of(context).pop();
83+
},
84+
),
85+
),
86+
],
87+
),
88+
);
89+
}
90+
}

0 commit comments

Comments
 (0)