myChips SDK
  • Introduction
  • Getting Started
    • Create a Publisher Account
    • Create your App/Site
    • Create an AdUnit
    • Test in Sanbox mode
  • Reward Handling
    • Webhook S2S Postback
    • Validating the Webhook S2S
    • Rejected S2S Webhook Postback
  • Billing
  • Unity
    • Install SDK
    • Reward User
    • FAQ
  • Android
    • Install SDK
    • Reward User
  • React Native
    • Install SDK
    • Reward User
  • RN Expo
    • Install SDK
    • Reward User
  • iOS
    • Install SDK
    • Reward User
  • Flutter
    • Install SDK
    • Reward User
  • iFrame
  • WebView & Direct Link
  • Revenue API
Powered by GitBook
On this page
  1. Flutter

Reward User

1. Fully Managed by MyChips

Use this method only if you have selected Self-Managed Currency. If you already support S2S postback please skip this snippet.

To check for a reward use the checkReward function. It requires your adUnitId, a reward callback (which will be called if the checks shows that there is a reward), and an on error callback.

MCOfferwallSdk.instance.checkReward(
    adUnitId: "YOUR_AD_UNIT_ID",
    onReward: (reward) {
        //do something with the reward, here we just print it out
        //Be cautious: reward.virtualCurrencyReward returns a Double value.
        print("Reward: ${reward.virtualCurrencyReward}");
    },
    onError: (e, st) {
        //do something on error, here we just print it out
        print("Error: $e");
        print("Stacktrace: $st");
    });

If there is no reward and no error, nothing will happen

You should check for the reward whenever the app is started or resumed. Example integration:

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

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

  @override
  State<MainApp> createState() => _MainAppState();
}

class _MainAppState extends State<MainApp> {
  late final AppLifecycleListener _appLifecycleListener;

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

  @override
  void dispose() {
    _appLifecycleListener.dispose();
    super.dispose();
  }

  Future<void> checkReward() async {
    MCOfferwallSdk.instance.checkReward(
      adUnitId: "YOUR_AD_UNIT_ID",
      onReward: (reward) {
        log("Reward: ${reward.virtualCurrencyReward}");
      },
      onError: (e, st) {
        log("Error: $e StackTrace: $st");
      },
    );
  }

  Future<void> initialize() async {
    //initialize the sdk and set the user id
    await MCOfferwallSdk.instance.init("YOUR_API_KEY");
    await MCOfferwallSdk.instance.setUserId("YOUR_USER_ID");

    //check for reward when the app is initialized
    checkReward();

    //check for reward when the app is resumed
    _appLifecycleListener = AppLifecycleListener(
      onResume: () {
        checkReward();
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return ...//your app body
  }
}

2. Server-to-Server (S2S) Postbacks

If you prefer server-to-server communication, MyChips can send a postback to your server with bonus information. The configuration for postbacks is available in your publisher dashboard. This method is useful for validating and securely rewarding users without client-side manipulation.

If you are testing in Sandbox mode, the value of the macro {user_payout} will be 0.

PreviousInstall SDKNextiFrame

Last updated 7 days ago