Skip to content

Commit

Permalink
explicit widget
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Malandruccolo committed May 6, 2024
1 parent 4a5d9d6 commit 6d4f16b
Showing 1 changed file with 40 additions and 33 deletions.
73 changes: 40 additions & 33 deletions samples/admob/native_platform_example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,43 +58,17 @@ class NativeExampleState extends State<NativeExample> {
title: 'Native Example',
home: Scaffold(
appBar: AppBar(
title: const Text('Native Example'),
actions: <Widget>[
// Regenerate the options menu to include a privacy setting.
FutureBuilder(
future: _consentManager.isPrivacyOptionsRequired(),
builder: (context, snapshot) {
final bool visibility = snapshot.data ?? false;
return Visibility(
visible: visibility,
child: PopupMenuButton<String>(
onSelected: (String result) {
if (result == privacySettingsText) {
_consentManager
.showPrivacyOptionsForm((formError) {
if (formError != null) {
debugPrint(
"${formError.errorCode}: ${formError.message}");
}
});
}
},
itemBuilder: (BuildContext context) =>
<PopupMenuEntry<String>>[
const PopupMenuItem<String>(
value: privacySettingsText,
child: Text(privacySettingsText))
],
));
})
],
),
title: const Text('Native Example'),
actions: _isMobileAdsInitializeCalled
? _privacySettingsAppBarAction()
: null),
body: Center(
child: Column(
children: [
Stack(children: [
SizedBox(
height: _nativeAdHeight, width: MediaQuery.of(context).size.width),
height: _nativeAdHeight,
width: MediaQuery.of(context).size.width),
if (_nativeAdIsLoaded && _nativeAd != null)
SizedBox(
height: _nativeAdHeight,
Expand All @@ -114,6 +88,37 @@ class NativeExampleState extends State<NativeExample> {
)));
}

List<Widget> _privacySettingsAppBarAction() {
return <Widget>[
// Regenerate the options menu to include a privacy setting.
FutureBuilder(
future: _consentManager.isPrivacyOptionsRequired(),
builder: (context, snapshot) {
final bool visibility = snapshot.data ?? false;
return Visibility(
visible: visibility,
child: PopupMenuButton<String>(
onSelected: (String result) {
if (result == privacySettingsText) {
_consentManager.showPrivacyOptionsForm((formError) {
if (formError != null) {
debugPrint(
"${formError.errorCode}: ${formError.message}");
}
});
}
},
itemBuilder: (BuildContext context) =>
<PopupMenuEntry<String>>[
const PopupMenuItem<String>(
value: privacySettingsText,
child: Text(privacySettingsText))
],
));
})
];
}

/// Loads a native ad.
void _loadAd() async {
// Only load an ad if the Mobile Ads SDK has gathered consent aligned with
Expand Down Expand Up @@ -163,7 +168,9 @@ class NativeExampleState extends State<NativeExample> {

var canRequestAds = await _consentManager.canRequestAds();
if (canRequestAds) {
_isMobileAdsInitializeCalled = true;
setState(() {
_isMobileAdsInitializeCalled = true;
});

// Initialize the Mobile Ads SDK.
MobileAds.instance.initialize();
Expand Down

0 comments on commit 6d4f16b

Please sign in to comment.