💡Tips
- Recommended to use the standardized callback handling flow
- Auto-refresh feature — see HyperBid Tools Console - App Management - Mediation Unit - Advanced Settings
- MREC (Medium Rectangle) has a standard size of 300×250, suitable for in-feed and in-content placements
The Flutter SDK provides two ways to load MREC ads: Programmatic and Widget.
Create and load an MREC ad via McSdk static methods. Suitable for scenarios that require precise control over the ad lifecycle.
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 |
Use the McAdView widget to embed directly into the Flutter Widget tree. Suitable for scenarios that require flexible layout.
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 viaMcAdViewController.- MREC and Banner share the
McAdViewwidget; the ad format is distinguished by theadFormatparameter.
Only the Programmatic approach requires manual show/hide control. The Widget approach is automatically managed by the Flutter Widget lifecycle.
// Show MREC ad
McSdk.showMRec("your mediation unit id");
// Hide MREC ad
McSdk.hideMRec("your mediation unit id");
When the MREC ad is no longer needed, release resources promptly to avoid memory leaks.
// 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
createMRecto create a new ad.
Use custom parameters to pass additional configuration to the Ad Network.
// 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,
);