moonetix_offerwall 2.0.2
moonetix_offerwall: ^2.0.2 copied to clipboard
Show the Moonetix offerwall in your Flutter app. Your server creates a single-use session token, and the plugin opens the offerwall with it.
Moonetix Offerwall for Flutter #
Show the Moonetix offerwall inside your Flutter app with one call. The plugin uses the native Moonetix Android SDK and Moonetix iOS SDK: the offerwall opens in a locked-down native screen, offer links go to the store or the browser, and a few simple events come back to your Dart code.
| Platform | Status |
|---|---|
| Android 5.0 (API 21) or newer | Supported (Moonetix Android SDK 2.0.1) |
| iOS 13 or newer | Supported (Moonetix iOS SDK 2.0.1, bundled with the plugin) |
| Web, desktop | Not supported. open reports MoonetixErrorCode.unsupported. |
Your API key and link hash salt never ship in the app. The app only receives a single-use session token.
How it works #
- When the user taps your Earn button, your app asks your own server for a session.
- Your server calls
POST https://api.moonetix.com/v1/sessionwith your API key and the user's ID. Moonetix returns a token that works once and for 10 minutes. - Your server passes the token to the app, and the app calls
Moonetix.open(token). - Rewards reach your server through your signed postback, exactly as with the offerwall link.
Install #
flutter pub add moonetix_offerwall
Or add it to your pubspec.yaml and run flutter pub get:
dependencies:
moonetix_offerwall: ^2.0.2
Requirements: Flutter 3.27 or newer (Dart 3.6). Android minSdk 21 or higher. iOS 13 or newer,
built with Xcode 16 or newer.
On iOS there is nothing else to add either: the plugin brings the Moonetix iOS SDK with it, for CocoaPods and for Swift Package Manager. For your App Store privacy details, see App Store privacy details.
On Android there is nothing else to add. The plugin adds the Moonetix Maven repository
(https://moonetix.com/maven, only for the com.moonetix group) and brings the Android SDK, its
INTERNET permission, its screen and its R8 rules with it.
If your android/settings.gradle(.kts) sets repositoriesMode to FAIL_ON_PROJECT_REPOS or
PREFER_SETTINGS, add the repository there yourself:
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven { url = uri("https://moonetix.com/maven") }
}
}
1. Create a session on your server #
POST https://api.moonetix.com/v1/session
- Header
Authorization: Bearer <your API key>(Apps, your app, Integration). - Body (form or JSON):
user_id(required, 1 to 100 characters of letters, numbers and. _ @ : + -, the same ID you receive in postbacks) and optionallysub1tosub5.
Response (HTTP 201):
{"ok": true, "token": "sst_...", "expires_in": 600, "expires_at": "2026-10-17T15:10:00+02:00"}
Errors: 400 invalid_user_id, 401 invalid_api_key, 403 app_not_live or user_blocked
(do not show the offerwall), 405 method_not_allowed, 429 rate_limited (see Retry-After).
Only return a token for the signed-in user of your own app. Never let the client choose the user_id.
PHP #
<?php
// GET /earn/session on YOUR server, for the signed-in user only.
$apiKey = getenv('MOONETIX_API_KEY'); // never in the app
$userId = (string) $currentUser->id; // from your own session, not from the request
$ch = curl_init('https://api.moonetix.com/v1/session');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $apiKey],
CURLOPT_POSTFIELDS => http_build_query(['user_id' => $userId]),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
$data = json_decode((string) $body, true);
header('Content-Type: application/json');
header('Cache-Control: no-store');
if ($status !== 201 || empty($data['token'])) {
http_response_code(502);
echo json_encode(['error' => $data['error'] ?? 'session_failed']);
exit;
}
echo json_encode(['token' => $data['token']]);
Node.js (18+) #
// Express route on YOUR server, behind your own authentication.
app.get('/earn/session', requireLogin, async (req, res) => {
const r = await fetch('https://api.moonetix.com/v1/session', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.MOONETIX_API_KEY}`, // never in the app
'Content-Type': 'application/json',
},
body: JSON.stringify({ user_id: String(req.user.id) }),
});
const data = await r.json().catch(() => ({}));
res.set('Cache-Control', 'no-store');
if (r.status !== 201 || !data.token) {
return res.status(502).json({ error: data.error || 'session_failed' });
}
res.json({ token: data.token });
});
2. Open the offerwall in your app #
Call init once with the App ID from the Integration tab, then fetch a fresh token from your server
every time the user opens the offerwall.
import 'package:moonetix_offerwall/moonetix_offerwall.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
Moonetix.init('YOUR_APP_ID');
runApp(const MyApp());
}
// When the user taps "Earn":
Future<void> openOfferwall() async {
final String token = await myApi.fetchMoonetixToken(); // your own backend call
await Moonetix.open(token);
}
open never throws for offerwall problems (missing init, malformed or expired token, no network,
unsupported platform). They arrive as events, see Events.
Branding #
The top bar matches your offerwall automatically: the Moonetix mark, like on the offerwall, with the title and colors from the Design tab of your app in the Moonetix dashboard. There is nothing to configure in the app. Changes you save in the Design tab reach apps within about 15 minutes.
To override the branding in code, pass MoonetixOptions:
await Moonetix.open(
token,
options: const MoonetixOptions(
title: 'Earn coins',
toolbarColor: Color(0xFF004ABB),
showLogo: false,
),
);
| Option | Default | Description |
|---|---|---|
title |
null |
Text in the top bar. null uses the title from your Design tab, or "Earn rewards". |
toolbarColor |
null |
Color of the top bar. null uses the background color from your Design tab, or a neutral bar that follows light and dark mode. The title and close icon always keep a readable contrast. |
showLogo |
true |
Show the Moonetix mark next to the title. |
Events #
Listen to Moonetix.events (a broadcast stream, so listen before you call open):
final StreamSubscription<MoonetixEvent> sub = Moonetix.events.listen((MoonetixEvent event) {
switch (event) {
case MoonetixOpened():
break;
case MoonetixClosed():
refreshBalanceFromServer();
case MoonetixErrorEvent(:final MoonetixError error):
debugPrint('Moonetix ${error.code.name}: ${error.message}');
}
});
// Cancel it when your screen goes away: sub.cancel();
Or set callbacks, like the Android SDK listener:
Moonetix.setListener(MoonetixListener(
onClosed: refreshBalanceFromServer,
onError: (MoonetixError error) => debugPrint(error.toString()),
));
// Moonetix.setListener(null) removes it.
| Event | When |
|---|---|
MoonetixOpened |
The offerwall finished loading its first page. |
MoonetixClosed |
The offerwall screen closed (close button, back, or the system). Once per open. A good moment to reload the user's balance from your server. |
MoonetixErrorEvent |
See the codes below. |
MoonetixErrorCode |
Meaning |
|---|---|
notInitialized |
open was called before init. |
invalidAppId |
init received something that is not a 24-character lowercase hex App ID. |
invalidToken |
The token is malformed, or the server does not know it (HTTP 404). |
tokenExpiredOrUsed |
The token is older than 10 minutes or was already used (HTTP 410). Create a new session. |
network |
The offerwall could not be reached. The screen shows a Try again button. |
unsupported |
No offerwall on this platform (web and desktop). |
unknown |
Anything else, for example Android System WebView is missing, or open was called while the app was in the background. |
Never credit rewards from these events. Anything that happens on a user's device can be faked. Credit rewards only from the signed server-to-server postback.
What the plugin handles for you (iOS) #
- Only
https://wall.moonetix.compages load inside the offerwall. App Store links open the App Store, other websites open in Safari, and unsafe schemes are blocked. - The close button returns to your app. Swiping from the left edge goes back inside the offerwall.
- The single-use token is loaded at most once and kept in memory only.
- Light and dark mode, larger text sizes and VoiceOver.
What the plugin handles for you (Android) #
- Only
https://wall.moonetix.compages load inside the offerwall. Google Play links open the Play Store app, other websites open in the browser, and unsafe schemes are blocked. - Back goes back inside the offerwall, and closes it on the first page. Android 13+ predictive back is supported.
- The single-use token is loaded at most once. Rotation and dark mode switches do not reload the page.
- Edge-to-edge on Android 15 and 16, with light and dark mode.
- File uploads (task screenshots) use the system file picker.
See the Android SDK docs for the details.
Security #
- Create sessions on your server only. Never put the Moonetix API key or the link hash salt in your app: anyone can read an app's files.
- Only hand out tokens for the signed-in user of your app, and never accept a
user_idfrom the client. - Credit rewards only from the signed postback, never from plugin events.
- The token only passes through memory. The plugin never logs it and there is no JavaScript bridge into your app.
Troubleshooting #
- Could not find com.moonetix:offerwall:2.0.1: your Gradle settings ignore project repositories.
Add the Maven repository to
settings.gradle(.kts)as shown in Install. - Kotlin metadata errors ("compiled with an incompatible version of Kotlin"): the Android SDK is built with Kotlin 2.1. Use Kotlin 2.0 or newer in your Android project (Flutter's current templates do).
unknown: "Moonetix.open() needs a visible screen": callopenwhile your app is in the foreground, for example from a button tap.
Example #
The example folder has a small app: enter your App ID, paste a fresh token, and open the offerwall.
License #
Apache License 2.0. See LICENSE.