knt_monetize_bloc 2.3.1 knt_monetize_bloc: ^2.3.1 copied to clipboard
Helper blocs for handling in-app-purchase & admob flow
knt_monetize_bloc #
Helper blocs for handling in-app-purchase & admob flow.
Getting Started #
-
Config your admob ID
- Make sure you had completed platform setup followed this reference Platform Admob Setup.
-
Config your in-app-purchase
- Flow this reference flutter_inapp_purchase.
-
Recommends using get_it & injectable for dependencies injection.
- Refer section Registering third party types for create instances of BLoC & service classes in this package.
- These Bloc & service need to be singleton (refer @singleton annotation with
injectable
).
-
BLoC pattern knowledge, refer library fluter_bloc.
-
Use
fluter_bloc
library:- Create
BlocProvider
at application level for this package's blocs. - Use
BlocBuilder
&BlocListener
for handling state from these blocs.
- Create
-
If your Android application enable Proguard rule, add these:
#In app Purchase -keep class com.amazon.** {*;} -keep class com.dooboolab.** { *; } -keep class com.android.vending.billing.** -dontwarn com.amazon.** -keepattributes *Annotation*
Common flow #
-
For Admob:
-
Step 1: Create instances of
AdmobConfig
&AdmobService
&FrequentlyAdsBloc
and/orStaticAdsBloc
. -
Step 2: At
main()
top-level function, initializeMobileAd
by inserting this code:Future<void> main() async { WidgetsFlutterBinding.ensureInitialized(); await getIt<AdmobService>().init(); runApp(App()); }
-
Step 3: Assume that
SplashPage
is your app's first page, then insert these code insideinitState()
:Future.delayed(Duration.zero, () { context.read<FrequentlyAdsBloc>().add(PrepareFrequentlyAdEvent()); }
-
Step 4: Whenever you need to show
InterstitialAd
, just call:context.read<FrequentlyAdsBloc>().add(ShowFrequentlyAdEvent(_adTag));
(I recommend create a unique
_adTag
to identify which screen had requested ad unit. This is helpful when handle state withBlocListener
.)
-
-
For in-app-purchase
- Step 1: Create instances of
IapConfig
&IapService
&SubscriptionBloc
. - Step 2: Create
PremiumPage
which shows UI for premium-feature, contains SKU list / restore purchase option / term & privacy. - Step 3:
- For showing SKU list: Using
SubscriptionBloc#FetchListSkuEvent
. - For request subscription on SKU item: Using
SubscriptionBloc#RequestSubscriptionEvent
. - For request restore purchase: Using
SubscriptionBloc#RestoreSubscriptionEvent
.
- For showing SKU list: Using
- Step 4 (Optional): Create instances of
FreeUsageCounterBloc
to handle user's free usage flow.
- Step 1: Create instances of
Note #
- This package included app_tracking_transparency for handling privacy iOS about admob.
This project is a starting point for a Dart package, a library module containing code that can be shared easily across multiple Flutter or Dart projects.
For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.