southgames_flutter 0.5.5 copy "southgames_flutter: ^0.5.5" to clipboard
southgames_flutter: ^0.5.5 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';

// If using Firebase Cloud Messaging, import it:
// import 'package:firebase_messaging/firebase_messaging.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  // Initialize the SDK with token management.
  // The tokenProvider and onTokenRefresh ensure the device token
  // is sent on every app start and refreshed automatically.
  SouthGamesSDK.init(
    apiKey: 'sg_live_xxxxxxxxxxxxxxxx',
    orgId: 'your-org-slug',
    // Example with FCM (uncomment if using firebase_messaging):
    // tokenProvider: () => FirebaseMessaging.instance.getToken(),
    // onTokenRefresh: FirebaseMessaging.instance.onTokenRefresh,
  );

  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 = 'Identificando cliente...';

  @override
  void initState() {
    super.initState();
    // Automatically identify and send/refresh token on every app start.
    _identify();
  }

  Future<void> _identify() async {
    try {
      // identify() automatically fetches and sends the device token
      // on every call (i.e., every app start).
      final res = await SouthGamesSDK.identify(
        externalId: 'demo_user_123',
        email: 'demo@example.com',
        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 SouthGamesSDK.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 SouthGamesSDK.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 SouthGamesSDK.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: _identify,
              child: const Text('Identificar 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'),
                    ),
                  );
                },
              ),
            ),
          ],
        ),
      ),
    );
  }
}
0
likes
0
points
124
downloads

Publisher

unverified uploader

Weekly Downloads

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.

Homepage
Repository (GitHub)
View/report issues

Topics

#gamification #loyalty #games #promotions #notifications

License

unknown (license)

Dependencies

flutter, http, webview_flutter

More

Packages that depend on southgames_flutter