southgames_flutter 0.4.3
southgames_flutter: ^0.4.3 copied to clipboard
Flutter SDK for SouthGames — integrate gamification and loyalty features (spin wheel, scratch cards, trivia, slot machine, promo codes, in-app notifications) into your Flutter app with a single package.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:southgames_flutter/southgames_flutter.dart';
void main() {
SouthGames.init(
apiKey: 'sg_live_xxxxxxxxxxxxxxxx',
orgId: 'your-org-slug',
);
runApp(const MyApp());
}
/// Example app demonstrating the SouthGames Flutter SDK.
class MyApp extends StatelessWidget {
/// Creates the example app.
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'SouthGames Demo',
home: const HomeScreen(),
);
}
}
/// Home screen with gamification features.
class HomeScreen extends StatefulWidget {
/// Creates the home screen.
const HomeScreen({super.key});
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
String? _clientId;
List<Campaign> _campaigns = [];
String _status = 'Listo para iniciar';
Future<void> _register() async {
try {
final res = await SouthGames.registerClient(
email: 'demo@example.com',
os: 'android',
customParams: {'plan': 'free'},
);
setState(() {
_clientId = res.clientId;
_status = res.created
? 'Cliente registrado: ${res.clientId}'
: 'Cliente actualizado: ${res.clientId}';
});
} on SouthGamesException catch (e) {
setState(() => _status = 'Error: ${e.message}');
}
}
Future<void> _loadCampaigns() async {
try {
final campaigns = await SouthGames.getCampaigns();
setState(() {
_campaigns = campaigns;
_status = '${campaigns.length} campana(s) encontrada(s)';
});
} on SouthGamesException catch (e) {
setState(() => _status = 'Error: ${e.message}');
}
}
Future<void> _play(Campaign campaign) async {
try {
final result = await SouthGames.play(
campaignId: campaign.id,
externalUserId: _clientId ?? 'demo_user',
);
setState(() {
if (result.won) {
_status = 'Ganaste! Codigo: ${result.prizeCode ?? "sin codigo"}';
} else {
_status = 'No ganaste. Resultado: ${result.result}';
}
});
} on SouthGamesException catch (e) {
setState(() => _status = 'Error: ${e.message}');
}
}
Future<void> _loadNotifications() async {
if (_clientId == null) {
setState(() => _status = 'Registra un cliente primero');
return;
}
try {
final notifications = await SouthGames.getInAppNotifications(
clientId: _clientId!,
);
setState(() {
_status = '${notifications.length} notificacion(es)';
});
} on SouthGamesException catch (e) {
setState(() => _status = 'Error: ${e.message}');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('SouthGames Demo')),
body: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(_status, style: Theme.of(context).textTheme.bodyLarge),
const SizedBox(height: 16),
ElevatedButton(
onPressed: _register,
child: const Text('Registrar cliente'),
),
const SizedBox(height: 8),
ElevatedButton(
onPressed: _loadCampaigns,
child: const Text('Cargar campanas'),
),
const SizedBox(height: 8),
ElevatedButton(
onPressed: _loadNotifications,
child: const Text('Ver notificaciones'),
),
const SizedBox(height: 16),
Expanded(
child: ListView.builder(
itemCount: _campaigns.length,
itemBuilder: (context, index) {
final c = _campaigns[index];
return ListTile(
title: Text(c.name),
subtitle: Text(c.gameType ?? 'traditional'),
trailing: ElevatedButton(
onPressed: () => _play(c),
child: const Text('Jugar'),
),
);
},
),
),
],
),
),
);
}
}