hubble_sdk 0.1.0 copy "hubble_sdk: ^0.1.0" to clipboard
hubble_sdk: ^0.1.0 copied to clipboard

unlistedoutdated

Hubble Money - A rewarding platform for your purchases

Hubble's SDK for flutter #

Getting Started #

Please contact us at myhubble.money/support for more information.

Installation #

Add this to your package's pubspec.yaml file:

dependencies:
  hubble_sdk: {current_latest_version}

Usage example #


import 'package:hubble_sdk/hubble_sdk.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class _SampleApp extends StatefulWidget {
  const _SampleApp();

  @override
  State<_SampleApp> createState() => _SampleAppState();
}

class _SampleAppState extends State<_SampleApp> {
  final _hubbleSdkController = HubbleSDKController(
    appPackageName: 'your.app.package.name',
    authToken: 'tokenOfTheUserInYourSystem',
    setCookie: (cookie) async {
      if (kDebugMode) {
        print('setCookie: $cookie');
      }

      // shared preference
      // secure storage
      // anywhere you want to store the cookie
    },
    getCookie: () async {
      return 'cookie';
    },
    appVersion: '1.0.0',
    appBuildNumber: '100',
    // shared by hubble to the integrator
    clientId: 'keyGivenByHubble',
    clientSecret: 'secretGivenByHubble',
    onEvent: (eventName, eventProperties) {
      // send to analytics
      if (kDebugMode) {
        print('onEvent: $eventName, $eventProperties');
      }
    },
    appFlavor: 'debug',
  );

  var _token = 'tokenOfTheUserInYourSystem';
  var _clientId = 'keyGivenByHubble';
  var _clientSecret = 'secretGivenByHubble';

  @override
  void dispose() {
    _hubbleSdkController.close();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      routes: <String, WidgetBuilder>{
        '/': (BuildContext context) {
          return Scaffold(
            backgroundColor: Colors.white,
            appBar: AppBar(
              title: const Text('Hubble SDK Example'),
            ),
            body: Center(
                child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Container(
                  margin: const EdgeInsets.all(8),
                  padding: const EdgeInsets.all(8),
                  decoration: BoxDecoration(
                    border: Border.all(
                      color: Colors.black,
                    ),
                    borderRadius: BorderRadius.circular(4),
                  ),
                  child: TextFormField(
                    initialValue: _token,
                    onChanged: (value) {
                      _token = value;
                    },
                    decoration: const InputDecoration(
                      border: InputBorder.none,
                      hintText: 'Enter token',
                    ),
                  ),
                ),
                Container(
                  margin: const EdgeInsets.all(8),
                  padding: const EdgeInsets.all(8),
                  decoration: BoxDecoration(
                    border: Border.all(
                      color: Colors.black,
                    ),
                    borderRadius: BorderRadius.circular(4),
                  ),
                  child: TextFormField(
                    initialValue: _clientId,
                    onChanged: (value) {
                      _clientId = value;
                    },
                    decoration: const InputDecoration(
                      border: InputBorder.none,
                      hintText: 'Enter client id',
                    ),
                  ),
                ),
                Container(
                  margin: const EdgeInsets.all(8),
                  padding: const EdgeInsets.all(8),
                  decoration: BoxDecoration(
                    border: Border.all(
                      color: Colors.black,
                    ),
                    borderRadius: BorderRadius.circular(4),
                  ),
                  child: TextFormField(
                    initialValue: _clientSecret,
                    onChanged: (value) {
                      _clientSecret = value;
                    },
                    decoration: const InputDecoration(
                      border: InputBorder.none,
                      hintText: 'Enter client secret',
                    ),
                  ),
                ),
                ElevatedButton(
                  onPressed: () {
                    _hubbleSdkController.updateConfig(
                      clientSecret: _clientSecret,
                      clientId: _clientId,
                      authToken: _token,
                    );
                    _hubbleSdkController.reInit();

                    Navigator.of(context).push(MaterialPageRoute(
                      builder: (context) {
                        return HubbleSDK(
                          controller: _hubbleSdkController,
                        );
                      },
                    ));
                  },
                  child: const Text('Launch SDK (material page)'),
                ),
              ],
            )),
          );
        },
      },
    );
  }
}