knt_base_monetized 3.0.1 copy "knt_base_monetized: ^3.0.1" to clipboard
knt_base_monetized: ^3.0.1 copied to clipboard

Helper blocs for handling common in-app-purchase flow

knt_base_monetized #

Helper blocs for handling common in-app-purchase & admob flow.

Getting Started #

  1. Config your admob ID

  2. 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).
  3. BLoC pattern knowledge, refer library fluter_bloc.

  4. Use fluter_bloc library:

    • Create BlocProvider at application level for this package's blocs.
    • Use BlocBuilder & BlocListener for handling state from these blocs.

Common flow #

  1. For Admob:

    • Step 1: Create instances of AdmobConfig & AdmobService & FrequentlyAdsBloc and/or StaticAdsBloc.

    • Step 2: At main() top-level function, initialize MobileAd 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 inside initState():

          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 with BlocListener.)

  2. For in-app-purchase

    • Step 1: Create instances of a SubscriptionBloc that extends BaseSubscriptionBloc.
    • Step 2: Overrides all needed methods with the correspond functions from your in app purchase library.
    • Step 3: Create PremiumPage which shows UI for premium-feature, contains SKU list / restore purchase option / term & privacy.
    • Step 4:
      • For showing SKU list: Using SubscriptionBloc#FetchListSkuEvent.
      • For request subscription on SKU item: Using SubscriptionBloc#RequestSubscriptionEvent.
      • For request restore purchase: Using SubscriptionBloc#RestoreSubscriptionEvent.
    • Step 4 (Optional): Create instances of FreeUsageCounterBloc to handle user's free usage flow.

Note #

0
likes
130
pub points
3%
popularity

Publisher

verified publisherappixi.net

Helper blocs for handling common in-app-purchase flow

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, knt_bloc, meta

More

Packages that depend on knt_base_monetized