Skip to content

Flutter SDK

The gamifyhost_games Flutter package renders the GamifyHost game experience inside a WebView, providing a native integration for iOS and Android apps.

Add the package to your pubspec.yaml:

dependencies:
gamifyhost_games: ^1.0.0

Then run:

Terminal window
flutter pub get

The SDK uses webview_flutter under the hood. Ensure your platform is configured:

Android (android/app/build.gradle.kts):

android {
defaultConfig {
minSdk = 21 // WebView requires API 21+
}
}

iOS (ios/Runner/Info.plist):

<key>io.flutter.embedded_views_preview</key>
<true/>
import 'package:flutter/material.dart';
import 'package:gamifyhost_games/gamifyhost_games.dart';
class GameScreen extends StatelessWidget {
const GameScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Games')),
body: const GamifyHostWidget(
config: GamifyHostConfig(
publicKey: 'pk_live_your_public_key',
userId: 'user_12345',
initialBalance: 5000,
),
),
);
}
}

The GamifyHostConfig class accepts the following parameters:

ParameterTypeRequiredDefaultDescription
publicKeyStringYesYour GamifyHost public API key
userIdStringYesThe authenticated user’s ID
apiUrlStringNohttps://api.gamifyhost.comAPI base URL
widgetUrlStringNohttps://cdn.gamifyhost.com/widget.jsWidget script URL
initialBalanceintNo0Balance to show before API responds
const config = GamifyHostConfig(
publicKey: 'pk_live_abc123',
userId: 'user_12345',
apiUrl: 'https://api.gamifyhost.com',
widgetUrl: 'https://cdn.gamifyhost.com/widget.js',
initialBalance: 5000,
);

Use copyWith to create a modified config:

final updatedConfig = config.copyWith(
userId: 'user_67890',
initialBalance: 3000,
);

The GamifyHostWidget accepts these properties:

PropertyTypeDefaultDescription
configGamifyHostConfigRequiredWidget configuration
controllerGamifyHostController?nullOptional controller for programmatic access
onReadyVoidCallback?nullCalled when widget finishes loading
onErrorFunction(String)?nullCalled on WebView loading errors
backgroundColorColorColor(0xFF1F1022)Background while loading
showLoadingIndicatorbooltrueShow spinner while loading
loadingIndicatorColorColor?Theme primarySpinner color

Use GamifyHostController for programmatic control:

class GameScreen extends StatefulWidget {
const GameScreen({super.key});
@override
State<GameScreen> createState() => _GameScreenState();
}
class _GameScreenState extends State<GameScreen> {
final _controller = GamifyHostController();
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Games'),
actions: [
IconButton(
icon: const Icon(Icons.refresh),
onPressed: () => _controller.reload(),
),
],
),
body: GamifyHostWidget(
config: const GamifyHostConfig(
publicKey: 'pk_live_abc123',
userId: 'user_12345',
),
controller: _controller,
onReady: () => debugPrint('Widget loaded'),
onError: (err) => debugPrint('Error: $err'),
),
);
}
}
MethodDescription
reload()Reload the widget with the current config
reloadWithConfig(config)Reload with a new GamifyHostConfig
runJavaScript(js)Execute arbitrary JS inside the WebView
isReadyValueNotifier<bool> indicating load state
dispose()Clean up resources
_controller.isReady.addListener(() {
if (_controller.isReady.value) {
debugPrint('Widget is ready');
}
});

When the authenticated user changes (e.g. after login), reload with a new config:

_controller.reloadWithConfig(
const GamifyHostConfig(
publicKey: 'pk_live_abc123',
userId: 'new_user_id',
initialBalance: 0,
),
);

Or simply update the config prop — the widget auto-detects config changes and reloads:

GamifyHostWidget(
config: GamifyHostConfig(
publicKey: 'pk_live_abc123',
userId: currentUserId, // Changes trigger reload
),
)
import 'package:flutter/material.dart';
import 'package:gamifyhost_games/gamifyhost_games.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'My App',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(
seedColor: const Color(0xFFD125F4),
brightness: Brightness.dark,
),
),
home: const GameScreen(),
);
}
}
class GameScreen extends StatefulWidget {
const GameScreen({super.key});
@override
State<GameScreen> createState() => _GameScreenState();
}
class _GameScreenState extends State<GameScreen> {
final _controller = GamifyHostController();
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('GamifyHost Games'),
actions: [
IconButton(
icon: const Icon(Icons.refresh),
onPressed: () => _controller.reload(),
),
],
),
body: GamifyHostWidget(
config: const GamifyHostConfig(
publicKey: 'pk_live_your_public_key',
userId: 'user_12345',
apiUrl: 'https://api.gamifyhost.com',
initialBalance: 5000,
),
controller: _controller,
backgroundColor: const Color(0xFF1F1022),
showLoadingIndicator: true,
onReady: () => debugPrint('GamifyHost widget loaded'),
onError: (error) => debugPrint('GamifyHost error: $error'),
),
);
}
}