gameolive 0.0.16 copy "gameolive: ^0.0.16" to clipboard
gameolive: ^0.0.16 copied to clipboard

outdated

A plugin to integrate awesome games and intract with GameOlive platform operrings and features.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:gameolive/GameOliveView.dart';
import 'package:gameolive/GameOliveWindow.dart';
import 'package:gameolive/gameolive.dart';
import 'package:gameolive/models/config.dart';
import 'package:gameolive/models/game.dart';
import 'package:gameolive/models/gamesResponse.dart';
import 'package:gameolive/models/launchConfig.dart';
import 'package:gameolive/models/playerBalance.dart';
import 'package:gameolive/models/transaction.dart';
import 'package:gameolive/shared/playmode.dart';

import 'custom_dialog_box.dart';
import 'game_dialog_box.dart';

const clientId =
    "fb_game_sa-4862d2b3-fb68-4963-b47b-beec6af422a5@05cc351f-dbd0-43af-aaaf-515ffaecdd34.gol";
const clientSecret = "abc1602937927739";
const operatorId = "5f8ae3cbc34272000af1f3bf";
const server = 'https://elantra-api.gameolive.com';
const static = 'https://static.luckybeetlegames.com';
const walletClientId =
    "wallet_manager-6f18a5bb-9b2e-4ed8-b7db-abf6465256f8@4e539d5f-4dd9-4518-8e67-49e401ea0b4b.gol";
const walletClientSecret = "gol1606078109162";

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _scaffoldKey = GlobalKey<ScaffoldState>();

  String _platformVersion = 'Unknown';
  final _gameolivePlugin = Gameolive();

  List<Game>? _games;
  LaunchConfig? inlineLaunchConfig;
  PlayerBalance? _playerBalance;
  String defaultPlayerId = "DEMO_USER";
  String _playerId = "DEMO_USER";
  String _playerToken = "DEMO_TOKEN";

  TextEditingController? _c;
  TextEditingController? _txtTransactionId;
  TextEditingController? _txtAmount;
  TextEditingController? _txtCurrency;
  TextEditingController? _txtCoins;
  TextEditingController? _txtRefernce;
  TextEditingController? _txtRemarks;

  @override
  void initState() {
    super.initState();
    initPlatformState();
    initGameOlive();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      platformVersion = await _gameolivePlugin.getPlatformVersion() ??
          'Unknown platform version';
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  initGameOlive() async {
    Config config = Config(
        operatorId: operatorId,
        clientId: clientId,
        clientSecret: clientSecret,
        server: server,
        static: static);
    List<Game>? games;
    try {
      await _gameolivePlugin.init(config); // initialize the library

      GamesResponse gamesResponse =
          await _gameolivePlugin.getGames(10, 0); // get first 10 games
      games = gamesResponse.games;
    } on PlatformException {
      // Log exception and report studio@gameolive.com
    }

    setState(() {
      _games = games;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: const Text('Plugin example app'),
          ),
          body: _games == null
              ? const Text('Execution is in progress')
              : _games!.isEmpty
                  ? const Text(
                      'There are no games in the offerings for this platform')
                  : Column(
                      children: [
                        inlineLaunchConfig == null
                            ? const SizedBox()
                            : SizedBox(
                                width: 720,
                                height: 220,
                                child: GameOliveWindow(
                                  instance: _gameolivePlugin,
                                  gameLaunchConfig: inlineLaunchConfig,
                                  onRoundStarted: (started) => {
                                    _scaffoldKey.currentState!.showSnackBar(
                                      SnackBar(
                                          content: Text(" started $started")),
                                    )
                                  },
                                )),
                        const SizedBox(),
                        Flexible(
                            child: ListView.builder(
                                // Let the ListView know how many items it needs to build.
                                itemCount: _games!.length,
                                // Provide a builder function. This is where the magic happens.
                                // Convert each item into a widget based on the type of item it is.
                                itemBuilder: (context, index) {
                                  final item = _games![index];
                                  return Slidable(
                                    actionPane:
                                        const SlidableDrawerActionPane(),
                                    actionExtentRatio: 0.25,
                                    actions: <Widget>[
                                      IconSlideAction(
                                        caption: 'Game Link',
                                        color: Colors.blue,
                                        icon: Icons.archive,
                                        onTap: () async {
                                          LaunchConfig launchConfig =
                                              LaunchConfig();
                                          launchConfig.server = server;
                                          launchConfig.static = static;
                                          launchConfig.operatorId = operatorId;
                                          launchConfig.configId =
                                              item.configuration!.id;
                                          launchConfig.playerId = _playerId;
                                          launchConfig.playerToken =
                                              _playerToken;

                                          String gameLink =
                                              await _gameolivePlugin
                                                  .getGameUrl(launchConfig);
                                          showDialog(
                                              context: context,
                                              builder: (BuildContext context) {
                                                return CustomDialogBox(
                                                  title: "Link to the game",
                                                  descriptions: gameLink,
                                                  text: "Close",
                                                );
                                              });
                                        },
                                      ),
                                      IconSlideAction(
                                        caption:
                                            '${_playerId == defaultPlayerId ? 'Register Player' : _playerId}: ${_playerBalance != null ? '${_playerBalance!.cash}|${_playerBalance!.currency}|${_playerBalance!.coin}' : ''}',
                                        color: Colors.indigo,
                                        icon: Icons.person_add,
                                        onTap: () {
                                          showDialog(
                                              context: context,
                                              builder: (BuildContext context) {
                                                return Dialog(
                                                  shape: RoundedRectangleBorder(
                                                      borderRadius:
                                                          BorderRadius.circular(
                                                              20.0)), //this right here
                                                  child: Container(
                                                    child: Padding(
                                                      padding:
                                                          const EdgeInsets.all(
                                                              12.0),
                                                      child: Column(
                                                        mainAxisAlignment:
                                                            MainAxisAlignment
                                                                .center,
                                                        crossAxisAlignment:
                                                            CrossAxisAlignment
                                                                .start,
                                                        children: [
                                                          TextField(
                                                            decoration:
                                                                const InputDecoration(
                                                                    hintText:
                                                                        'Player UID'),
                                                            controller: _c,
                                                          ),
                                                          SizedBox(
                                                            width: 320.0,
                                                            child: RaisedButton(
                                                              onPressed:
                                                                  () async {
                                                                try {
                                                                  String
                                                                      playerToken =
                                                                      await _gameolivePlugin.getPlayerToken(
                                                                          _c!
                                                                              .text,
                                                                          PlayMode
                                                                              .real);
                                                                  Config walletConfig = Config(
                                                                      operatorId:
                                                                          operatorId,
                                                                      clientId:
                                                                          walletClientId,
                                                                      clientSecret:
                                                                          walletClientSecret,
                                                                      server:
                                                                          server,
                                                                      static:
                                                                          static);
                                                                  PlayerBalance
                                                                      pb =
                                                                      await _gameolivePlugin.getPlayerBalance(
                                                                          _c!
                                                                              .text,
                                                                          PlayMode
                                                                              .real,
                                                                          walletConfig);
                                                                  setState(() {
                                                                    _playerId =
                                                                        _c!.text;
                                                                    _playerToken =
                                                                        playerToken;
                                                                    _playerBalance =
                                                                        pb;
                                                                  });

                                                                  var transactions = await _gameolivePlugin.getPlayerAccountHistory(
                                                                      _playerId,
                                                                      PlayMode
                                                                          .real,
                                                                      0,
                                                                      10,
                                                                      walletConfig);
                                                                  print(transactions
                                                                      .count);
                                                                } catch (ex) {
                                                                  const snackBar =
                                                                      SnackBar(
                                                                    duration: Duration(
                                                                        seconds:
                                                                            10),
                                                                    content: Text(
                                                                        'Exception while getting plater token!'),
                                                                  );
                                                                  _scaffoldKey
                                                                      .currentState!
                                                                      .showSnackBar(
                                                                          snackBar);
                                                                }
                                                              },
                                                              color: const Color(
                                                                  0xFF1BC0C5),
                                                              child: const Text(
                                                                "Register Or Login Player",
                                                                style: TextStyle(
                                                                    color: Colors
                                                                        .white),
                                                              ),
                                                            ),
                                                          ),
                                                          Text(
                                                              'Current Player: $_playerId'),
                                                          TextField(
                                                            decoration:
                                                                const InputDecoration(
                                                                    hintText:
                                                                        'Transaction UID'),
                                                            controller:
                                                                _txtTransactionId,
                                                          ),
                                                          TextField(
                                                            decoration:
                                                                const InputDecoration(
                                                                    hintText:
                                                                        'Amount'),
                                                            controller:
                                                                _txtAmount,
                                                          ),
                                                          TextField(
                                                            decoration:
                                                                const InputDecoration(
                                                                    hintText:
                                                                        'Currency'),
                                                            controller:
                                                                _txtCurrency,
                                                          ),
                                                          TextField(
                                                            decoration:
                                                                const InputDecoration(
                                                                    hintText:
                                                                        'Coins'),
                                                            controller:
                                                                _txtCoins,
                                                          ),
                                                          TextField(
                                                            decoration:
                                                                const InputDecoration(
                                                                    hintText:
                                                                        'Reference'),
                                                            controller:
                                                                _txtRefernce,
                                                          ),
                                                          TextField(
                                                            decoration:
                                                                const InputDecoration(
                                                                    hintText:
                                                                        'Remarks'),
                                                            controller:
                                                                _txtRemarks,
                                                          ),
                                                          SizedBox(
                                                            width: 320.0,
                                                            child: RaisedButton(
                                                              onPressed:
                                                                  () async {
                                                                try {
                                                                  Transaction trx = Transaction(
                                                                      uid: _txtTransactionId!
                                                                          .text,
                                                                      amount: double.parse(
                                                                          _txtAmount!
                                                                              .text),
                                                                      currency:
                                                                          _txtCurrency!
                                                                              .text,
                                                                      coins: int.parse(
                                                                          _txtCoins!
                                                                              .text),
                                                                      reference:
                                                                          _txtRefernce!
                                                                              .text);
                                                                  trx.remarks =
                                                                      _txtRemarks!
                                                                          .text;
                                                                  // Create new configuration with service account with Wallet Manager permissions.
                                                                  // it is recommended to no give wallet manager permissions to Game Admin or other permissions as it might risk the exploitation of wallet
                                                                  // it is highly recommended to use wallet manager service account for server to server request and not to use in client application, but if you wish to use it on client side for simplicity you can do it at your own risk
                                                                  Config walletConfig = Config(
                                                                      operatorId:
                                                                          operatorId,
                                                                      clientId:
                                                                          walletClientId,
                                                                      clientSecret:
                                                                          walletClientSecret,
                                                                      server:
                                                                          server,
                                                                      static:
                                                                          static);
                                                                  var newTransaction =
                                                                      await _gameolivePlugin.depositToPlayerAccount(
                                                                          _playerId,
                                                                          trx,
                                                                          walletConfig);
                                                                  setState(() {
                                                                    _playerBalance =
                                                                        newTransaction;
                                                                  });
                                                                  // print( // todo make new Model for TransactionRef.
                                                                  //     _newTransaction
                                                                  //         .uid);
                                                                } catch (ex) {
                                                                  const snackBar =
                                                                      SnackBar(
                                                                    duration: Duration(
                                                                        seconds:
                                                                            10),
                                                                    content: Text(
                                                                        'Exception while making player transaction!'),
                                                                  );
                                                                  _scaffoldKey
                                                                      .currentState!
                                                                      .showSnackBar(
                                                                          snackBar);
                                                                }
                                                              },
                                                              color: const Color(
                                                                  0xFF1BC0C5),
                                                              child: const Text(
                                                                "Deposit to Player wallet",
                                                                style: TextStyle(
                                                                    color: Colors
                                                                        .white),
                                                              ),
                                                            ),
                                                          ),
                                                        ],
                                                      ),
                                                    ),
                                                  ),
                                                );
                                              });

                                          print('share');
                                        },
                                      ),
                                    ],
                                    secondaryActions: <Widget>[
                                      IconSlideAction(
                                        caption: 'inline',
                                        color: Colors.blue,
                                        icon: Icons.more_horiz,
                                        onTap: () async {
                                          LaunchConfig launchConfig =
                                              LaunchConfig();
                                          launchConfig.server = server;
                                          launchConfig.static = static;
                                          launchConfig.operatorId = operatorId;
                                          launchConfig.configId =
                                              item.configuration!.id;
                                          launchConfig.playerId = _playerId;
                                          launchConfig.playerToken =
                                              _playerToken;
                                          setState(() {
                                            inlineLaunchConfig = launchConfig;
                                          });
                                        },
                                      ),
                                      IconSlideAction(
                                        caption: 'redirect',
                                        color: Colors.black45,
                                        icon: Icons.arrow_forward,
                                        onTap: () {
                                          LaunchConfig launchConfig =
                                              LaunchConfig();
                                          launchConfig.server = server;
                                          launchConfig.static = static;
                                          launchConfig.operatorId = operatorId;
                                          launchConfig.configId =
                                              item.configuration!.id;
                                          launchConfig.orientation =
                                              "landscape";
                                          launchConfig.playerId = _playerId;
                                          launchConfig.playerToken =
                                              _playerToken;
                                          Navigator.push(
                                              context,
                                              MaterialPageRoute(
                                                builder: (context) =>
                                                    GameOliveView(
                                                  instance: _gameolivePlugin,
                                                  launchConfig: launchConfig,
                                                  onGoToHome: (value) {
                                                    Navigator.pop(context);
                                                  },
                                                  onBalanceChange: (balace) {
                                                    debugPrint(
                                                        "balance update");
                                                  },
                                                ),
                                              ));
                                        },
                                      ),
                                      IconSlideAction(
                                        caption: 'Dialog',
                                        color: Colors.indigo,
                                        icon: Icons.add_to_photos,
                                        onTap: () {
                                          LaunchConfig gameLaunchConfig =
                                              LaunchConfig();
                                          gameLaunchConfig.server = server;
                                          gameLaunchConfig.static = static;
                                          gameLaunchConfig.operatorId =
                                              operatorId;
                                          gameLaunchConfig.configId =
                                              item.configuration!.id;
                                          gameLaunchConfig.playerId =
                                              _playerId; // unique if of the player
                                          gameLaunchConfig.playerToken =
                                              _playerToken; // unique if of the player

                                          showDialog(
                                              context: context,
                                              builder: (BuildContext context) {
//                             return GameOliveDialogBox(gameLaunchConfig: gameLaunchConfig);
                                                return GameDialogBox(
                                                    instance: _gameolivePlugin,
                                                    gameLaunchConfig:
                                                        gameLaunchConfig);
                                              });
                                        },
                                      ),
                                    ],
                                    child: Container(
                                      color: Colors.white,
                                      child: ListTile(
                                        leading: const Text(('<')),
                                        title: Text(item.title ?? ""),
                                        trailing: const Text(('Swipe >')),
                                        subtitle: Column(
                                          mainAxisAlignment:
                                              MainAxisAlignment.start,
                                          crossAxisAlignment:
                                              CrossAxisAlignment.start,
                                          children: [
                                            Text(item.configuration!.id ?? ""),
                                            Text('enabled: ${item.enabled}'),
                                            Text('label: ${item.label}'),
                                            Text('Rating: ${item.rating}'),
                                            Text(
                                                'playerCount: ${item.playerCount}'),
                                            Text(
                                                'description: ${item.description}')
                                          ],
                                        ),
                                      ),
                                    ),
                                  );
                                })),
                      ],
                    )),
    );
  }
}
2
likes
0
pub points
0%
popularity

Publisher

verified publishergameolive.com

A plugin to integrate awesome games and intract with GameOlive platform operrings and features.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, flutter_cache_manager, flutter_web_plugins, http, plugin_platform_interface, shared_preferences, webview_flutter

More

Packages that depend on gameolive