Menu

MREC

💡Tips


The Flutter SDK provides two ways to load MREC ads: Programmatic and Widget.

Programmatic

Create and load an MREC ad via McSdk static methods. Suitable for scenarios that require precise control over the ad lifecycle.

dart Copy
void initializeMRecAd() {
  // Set MREC ad callback listener
  McSdk.setMRecListener(McAdViewAdListener(
    onAdLoadedCallback: (McAd ad) {
      // MREC loaded successfully callback
    },
    onAdLoadFailedCallback: (String adUnitId, McError error) {
      // MREC load failed callback
    },
    onAdClickedCallback: (McAd ad) {
      // MREC clicked callback
    },
    onAdExpandedCallback: (McAd ad) {
      // MREC expanded callback
    },
    onAdCollapsedCallback: (McAd ad) {
      // MREC collapsed callback
    },
    onAdDisplayedCallback: (McAd ad) {
      // MREC displayed successfully callback
    },
    onAdRevenuePaidCallback: (McAd ad) {
      // MREC ad revenue callback
    },
    onAdLoadFinishedCallback: (String adUnitId) {
      // Current load round finished callback
    },
  ));

  loadMRecAd();
}

void loadMRecAd() {
  // Set scenario ID (optional)
  McSdk.setMRecPlacement("your mediation unit id", "test_scenario_id_mrec");

  // Create MREC ad and specify display position
  McSdk.createMRec("your mediation unit id", AdViewPosition.bottomCenter);
}

💡 Tips

  • After calling createMRec, the SDK will automatically start loading the ad.
  • If auto-refresh is enabled, the SDK will automatically load the next round of ads when the refresh interval expires.
  • Only when auto-refresh is paused do you need to manually call McSdk.loadMRec(adUnitId) to reload.

AdViewPosition supports the following position enums:

Enum Value Description
AdViewPosition.topCenter Top center
AdViewPosition.topRight Top right
AdViewPosition.centered Screen center
AdViewPosition.centerLeft Vertically centered left
AdViewPosition.centerRight Vertically centered right
AdViewPosition.bottomLeft Bottom left
AdViewPosition.bottomCenter Bottom center
AdViewPosition.bottomRight Bottom right

Widget

Use the McAdView widget to embed directly into the Flutter Widget tree. Suitable for scenarios that require flexible layout.

dart Copy
final McAdViewController adViewController = McAdViewController();

Widget buildMRecAd() {
  return McAdView(
    adUnitId: "your mediation unit id",
    adFormat: AdFormat.mrec,
    controller: adViewController,
    listener: McAdViewAdListener(
      onAdLoadedCallback: (McAd ad) {
        // MREC loaded successfully callback
      },
      onAdLoadFailedCallback: (String adUnitId, McError error) {
        // MREC load failed callback
      },
      onAdClickedCallback: (McAd ad) {
        // MREC clicked callback
      },
      onAdExpandedCallback: (McAd ad) {
        // MREC expanded callback
      },
      onAdCollapsedCallback: (McAd ad) {
        // MREC collapsed callback
      },
      onAdDisplayedCallback: (McAd ad) {
        // MREC displayed successfully callback
      },
      onAdRevenuePaidCallback: (McAd ad) {
        // MREC ad revenue callback
      },
      onAdLoadFinishedCallback: (String adUnitId) {
        // Current load round finished callback
      },
    ),
    extraParameters: {"key": "value"},
    localExtraParameters: {"key": value}
  );
}

💡 Tips

  • To manually refresh the ad, call the loadAd() method via McAdViewController.
  • MREC and Banner share the McAdView widget; the ad format is distinguished by the adFormat parameter.

Only the Programmatic approach requires manual show/hide control. The Widget approach is automatically managed by the Flutter Widget lifecycle.

dart Copy
// Show MREC ad
McSdk.showMRec("your mediation unit id");

// Hide MREC ad
McSdk.hideMRec("your mediation unit id");

3. Release Resources

When the MREC ad is no longer needed, release resources promptly to avoid memory leaks.

dart Copy
// Release MREC ad resources
McSdk.destroyMRec("your mediation unit id");

💡 Tips

  • After calling destroyMRec, all callbacks for that placement will stop firing.
  • To show the ad again, you need to call createMRec to create a new ad.

4. Set Custom Parameters

Use custom parameters to pass additional configuration to the Ad Network.

dart Copy
// Set Extra Parameter (Max only)
McSdk.setMRecExtraParameter(
  "your mediation unit id",
  "mrec_test_extra_key",
  "mrec_test_extra_value",
);

// Set Local Extra Parameter
McSdk.setMRecLocalExtraParameter(
  "your mediation unit id",
  "mrec_test_local_extra_key",
  value,
);

Previous
Banner
Next
The Callback Info
Last modified: 2026-06-25Powered by