prodege_play 1.0.0 copy "prodege_play: ^1.0.0" to clipboard
prodege_play: ^1.0.0 copied to clipboard

PlatformAndroid

ProdegePlay SDK Flutter wrapper

example/lib/main.dart

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:prodege_play/prodege_play.dart';
import 'package:prodege_play_example/screens/home_screen.dart';
import 'package:prodege_play_example/utils/snackbar.dart';

import 'app_screen.dart';
import 'screens/offerwall_screen.dart';

enum AppBarAction {
  hide,
  isInitialized,
  isVisible,
  requestUsageAccess,
  checkUsagePermission,
}

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  AppScreen _currentScreen = AppScreen.home;
  bool _isInitialized = false;

  @override
  void initState() {
    super.initState();
    _initializeProdegePlaySdk();
  }

  void _initializeProdegePlaySdk() async {
    final options = ProdegePlayOptions()..userId = "USER_ID";

    try {
      await ProdegePlay.init(
        apiKey: "API_KEY",
        secretKey: "SECRET_KEY",
        options: options,
      );
      _onSuccessfulSdkInitialization();
    } on PlatformException catch (error) {
      _showMessage("SDK initialization error ${error.message}");
    } on UnimplementedError {
      _showUnimplementedMessage();
    }
  }

  void _onSuccessfulSdkInitialization() {
    _showMessage("SDK initialized successfully");

    if (!mounted) return;

    setState(() {
      _isInitialized = true;
    });
  }

  void _onTabTapped(int index) {
    setState(() {
      _currentScreen = AppScreen.values[index];
    });
  }

  void _showMessage(String message) {
    SnackbarGlobal.show(message);
  }

  void _showUnimplementedMessage() {
    _showMessage("ProdegePlay is not supported in $defaultTargetPlatform");
  }

  void _onActionSelected(AppBarAction action) {
    switch (action) {
      case AppBarAction.hide:
        ProdegePlay.hideOfferwall().onError<UnimplementedError>(
          (_, _) => _showUnimplementedMessage(),
        );
      case AppBarAction.isInitialized:
        _checkInitialization();
      case AppBarAction.isVisible:
        _checkVisibility();
      case AppBarAction.requestUsageAccess:
        ProdegePlay.requestUsagePermission().onError<UnimplementedError>(
          (_, _) => _showUnimplementedMessage(),
        );
      case AppBarAction.checkUsagePermission:
        _checkUsagePermission();
    }
  }

  Future _checkInitialization() async {
    try {
      final result = await ProdegePlay.isInitialized();
      _showMessage("SDK is${result ? "" : " not"} initialized");
    } on UnimplementedError {
      _showUnimplementedMessage();
    }
  }

  Future _checkVisibility() async {
    try {
      final result = await ProdegePlay.isOfferwallVisible();
      _showMessage("Offerwall is${result ? "" : " not"} visible");
    } on UnimplementedError {
      _showUnimplementedMessage();
    }
  }

  Future _checkUsagePermission() async {
    try {
      final result = await ProdegePlay.hasAcceptedUsagePermission();
      _showMessage("Usage access is ${result ? "permitted" : "prohibited"}");
    } on UnimplementedError {
      _showUnimplementedMessage();
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      scaffoldMessengerKey: SnackbarGlobal.key,
      home: Scaffold(
        appBar: AppBar(
          title: const Text('ProdegePlay Sample'),
          actions: [
            PopupMenuButton(
              onSelected: _onActionSelected,
              itemBuilder: (BuildContext context) {
                return [
                  PopupMenuItem(
                    value: AppBarAction.hide,
                    child: Text("Hide offerwall"),
                  ),
                  PopupMenuItem(
                    value: AppBarAction.isInitialized,
                    child: Text("Check initialization"),
                  ),
                  PopupMenuItem(
                    value: AppBarAction.isVisible,
                    child: Text("Check visibility"),
                  ),
                  PopupMenuItem(
                    value: AppBarAction.checkUsagePermission,
                    child: Text("Check usage permission"),
                  ),
                  PopupMenuItem(
                    value: AppBarAction.requestUsageAccess,
                    child: Text("Request usage permission"),
                  ),
                ];
              },
            ),
          ],
        ),
        body: switch (_currentScreen) {
          AppScreen.home => HomeScreen(_isInitialized),
          AppScreen.offerwall => OfferwallScreen(),
        },
        bottomNavigationBar: BottomNavigationBar(
          onTap: _onTabTapped,
          currentIndex:
              AppScreen.values
                  .firstWhere(
                    (e) => e == _currentScreen,
                    orElse: () => AppScreen.home,
                  )
                  .index,
          items: [
            BottomNavigationBarItem(
              icon: Icon(Icons.home_outlined),
              label: "Home",
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.local_offer_outlined),
              label: "Offerwall",
            ),
          ],
        ),
      ),
    );
  }
}
0
likes
135
points
1
downloads

Publisher

unverified uploader

Weekly Downloads

ProdegePlay SDK Flutter wrapper

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on prodege_play

Packages that implement prodege_play