-
Notifications
You must be signed in to change notification settings - Fork 287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] Provide a Dart Idiomatic Async API #890
Comments
I think this is a wide scope issue and may need a lot of codebase refactoring, not sure about the feasibility and amount of effort required for now. So, I'm labeling this with a single label for more information from others. |
This would be a welcome change!!! We already experienced a huge amount of refactoring from the 0. versions of the plugin until today, so anything that is more like what we are used to using everyday, will likely cause a lot less issues. The way to use the plugin is a bit weird and doesn't feel like the rest of my code. |
Any news here? The existing API is really hard to use. |
I'm now adding Banner Ads to my app and am reminded how hilariously hard to use the AdMob APIs are: @override
void initState() {
...
// Why are we creating an instance if we're not going to hold a reference to it??
BannerAd(
adUnitId: AdHelper.bannerAdUnitId,
request: AdRequest(),
size: AdSize.banner,
// Why is a simple callback it's own class??????
listener: BannerAdListener(
onAdLoaded: (ad) {
setState(() {
// WHHHHHYYYYYY do we have to do type casting here?????
_bannerAd = ad as BannerAd;
});
},
onAdFailedToLoad: (ad, err) {
print('Failed to load a banner ad: ${err.message}');
ad.dispose();
},
),
).load();
} This feels like 2010s "Enterprise grade" Java or something. This is really painful. I hope you guys fix it. |
@caseycrogers this is something we are actively looking into but no immediate news to share. However, comments like these show the importance of this feature request. Thanks |
I have done this using simple completers. If someone wants inspiration for using this api. Future<RewardedInterstitialAd> _populateRewardedInterstitialAd({
required String adUnitId,
required VoidCallback onAdDismissedFullScreenContent,
required VoidCallback onAdShowedFullScreenContent,
}) async {
try {
final adCompleter = Completer<Ad?>();
await RewardedInterstitialAd.load(
adUnitId: adUnitId,
request: const AdRequest(),
rewardedInterstitialAdLoadCallback: RewardedInterstitialAdLoadCallback(
onAdLoaded: (ad) {
ad.fullScreenContentCallback = FullScreenContentCallback(
onAdShowedFullScreenContent: (ad) {
onAdShowedFullScreenContent();
},
onAdDismissedFullScreenContent: (ad) {
onAdDismissedFullScreenContent();
},
);
adCompleter.complete(ad);
},
onAdFailedToLoad: adCompleter.completeError,
),
);
final rewardedInterstitial = await adCompleter.future;
if (rewardedInterstitial == null) {
throw const AdsClientException('Rewarded Interstitial Ad was null');
}
return rewardedInterstitial as RewardedInterstitialAd;
} catch (error, stackTrace) {
Error.throwWithStackTrace(AdsClientException(error), stackTrace);
}
} |
[REQUIRED] Step 2: Describe the problem
The entire
google_mobile_ads
API is built with callback APIs. These are bug prone and very non-idiomatic for Flutter. Really non-idiomatic in any language post ~2005. This means each dev more or less needs to write a wrapper around the current API to convert it to Flutter idiomatic futures.Here is an example of what the API would look like using Flutter/Dart idioms:
However even this isn't very Flutter idiomatic. It really isn't even going far enough. The ideal would be a widget using the controller pattern roughly as follows (see
ScrollController
andScrollable
for full Flutter idiomatic examples of the controller pattern):The text was updated successfully, but these errors were encountered: