|
| 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