qgami_sdk
Flutter SDK for integrating QGami game flows.
This package provides:
QGamistatic API for SDK lifecycle (initialize,identify, token refresh, game URL retrieval)QgamiButtonwidget that preloads a game URL and opens an in-app full-screen WebViewQgamiWebViewEventmodel for receiving game/webview events
Installation
Add the dependency:
dependencies:
qgami_sdk: ^0.0.2
Then run:
flutter pub get
Quick Start
- Initialize the SDK.
- Identify the user.
- Render
QgamiButtonwith agameSlug.
import 'package:flutter/material.dart';
import 'package:qgami_sdk/qgami.dart';
import 'package:qgami_sdk/qgami_core.dart';
import 'package:qgami_sdk/qgami_web_view_event.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(home: HomePage());
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
bool identified = false;
@override
void initState() {
super.initState();
_setup();
}
Future<void> _setup() async {
await QGami.initialize(
apiKey: 'YOUR_API_KEY',
environment: QGamiEnvironment.development,
locale: 'en-US',
);
final ok = await QGami.identify(
email: 'user@example.com',
username: 'User 1',
userId: 'user_1',
);
if (!mounted) return;
setState(() => identified = ok);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Qgami Demo')),
body: Center(
child: QgamiButton(
gameSlug: 'slot-machine-qgami',
disabled: !identified,
customBuilder: (context) => Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.circular(8),
),
child: const Text(
'Open Game',
style: TextStyle(color: Colors.white),
),
),
onWebViewEvent: (QgamiWebViewEvent event) {
debugPrint('Qgami event: ${event.type}, data: ${event.data}');
},
),
),
);
}
}
QgamiButton Behavior
QgamiButtonwaits for SDK readiness (initialize+identify) before fetching the game URL.- If tapped before URL readiness, it shows a snackbar:
Game URL is not ready. Please wait for identify. - On success, it opens
QgamiWebViewPagewith a full-screen slide-up transition. - The page now closes only on
GAME_CLOSEevents.
WebView Events
QgamiWebViewEvent.type can include:
GAME_READYACCESS_TOKEN_EXPIREDGAME_LOADINGGAME_LOADEDGAME_PLAY_STARTGAME_PLAY_RESULTGAME_PLAY_ERRORGAME_CLOSE
SDK internals:
- On
GAME_READY, SDK sendsINIT_GAMEto web content. - On
ACCESS_TOKEN_EXPIRED, SDK refreshes token and sendsUPDATE_ACCESS_TOKEN.
Public API Summary
QGami.initialize({apiKey, environment, locale})QGami.identify({email, username, userId})QGami.waitUntilReady({timeout})QGami.getGameUrl({gameSlug})QGami.refreshAccessToken()QGami.getInitGameMessage(...)QGami.getUpdateAccessTokenMessage(...)
State helpers:
QGami.isInitializedQGami.isIdentifiedQGami.isReady
Environment constants:
QGamiEnvironment.developmentQGamiEnvironment.stagingQGamiEnvironment.sandboxQGamiEnvironment.production
Note: QGami.openGame(), QGami.showFloatingGameWidget(), and QGami.openHub() are currently placeholders.
Platform Notes
- Requires
webview_flutterplatform support. - Android app must allow internet access:
<uses-permission android:name="android.permission.INTERNET" />