geo_sdk_flutter_plugin 0.0.2+17 copy "geo_sdk_flutter_plugin: ^0.0.2+17" to clipboard
geo_sdk_flutter_plugin: ^0.0.2+17 copied to clipboard

outdated

A plugin to wrap the GeoSDK

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:geo_sdk_flutter_plugin/geo_sdk_plugin.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  GeoSdkFlutterPlugin _geoSdkFlutterPlugin;

  List<LDEvent> _ldEventLogList = List();

  String _sdkVersion = '';
  LDEvent _lastEvent;
  int _payloadSentCount = 0;

  @override
  void initState() {
    super.initState();

    SchedulerBinding.instance.addPostFrameCallback((_) {
      startEvents();
    });
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> startEvents() async {

    try {
      _initGeoSdkPlugin();
    } on PlatformException {
      print('Failed to launch the SDK.');
    }

  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            backgroundColor: Color(0xff103a72),
            title: const Text('GeoSDK Flutter Plugin Example'),
            centerTitle: true,
          ),
          body: Column(
            children: <Widget>[

              Align(
                alignment: Alignment.topCenter,
                child: Padding(
                  padding: EdgeInsets.symmetric(vertical: 10, horizontal: 20),
                  child: Card(
                    child: Padding(
                      padding: EdgeInsets.symmetric(vertical: 20, horizontal: 10),
                      child: Column(
                        children: <Widget>[
                          Text(
                              'INFO',
                            style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
                          ),
                          Divider(),
                          Text(
                            'GeoSDK is on version: $_sdkVersion',
                            style: TextStyle(fontSize: 17),
                          ),
                          Text(
                            'Total payload sent count: $_payloadSentCount',
                            style: TextStyle(fontSize: 17),
                          ),
                          Text(
                            'The last event caught by the SDK was: ${_lastEvent?.type}',
                            style: TextStyle(fontSize: 17),
                          ),
                        ],

                      ),
                    )
                  )
                )
              ),
              Padding(
                padding: EdgeInsets.symmetric(horizontal: 20),
                child: Divider(thickness: 1,),
              ),
              Text(
                'Event log:',
                style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
              ),
              Expanded(
                child:
                ListView.builder(
                  shrinkWrap: true,
                  itemCount: _ldEventLogList.length,
                  itemBuilder: (context, index) {
                    return Center(
                      child: Padding(
                        padding: EdgeInsets.symmetric(vertical: 10),
                        child: Text(_ldEventLogList[index].type.toString(), style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15),),
                      ),
                    );
                  },
                ) ,
              ),

              Align(
                alignment: Alignment.bottomCenter,
                child: Container(
                  padding: EdgeInsets.symmetric(vertical: 20),
                  child: Text('This plugin is powered by LOTaDATA Inc', style: TextStyle(fontSize: 14),),
                ),
              ),

            ],
          )
      ),
    );
  }


  Future<void> _initGeoSdkPlugin() async {
    _geoSdkFlutterPlugin = new GeoSdkFlutterPlugin();
    _geoSdkFlutterPlugin.setOnEventHandler(onEventHandler);
    _geoSdkFlutterPlugin.setOnPayloadSentHandler(onPayloadSent);

    bool launchResult = await _geoSdkFlutterPlugin.checkPermissionsAndLaunch();
    print('MAIN: launchResult is $launchResult');

    LDEvent lastLDEvent = await _geoSdkFlutterPlugin.getLastEvent;
    String sdkVersion = await _geoSdkFlutterPlugin.getSDKVersion;

    setState(() {
      this._sdkVersion = sdkVersion;
      this._lastEvent = lastLDEvent;
    });
  }


  void onPayloadSent(int count) {
    setState(() {
      this._payloadSentCount = count;
    });
  }

  void onEventHandler(LDEvent ldEvent) {
    print('MAIN: onEventHandler triggered Type: ${ldEvent.type}');

    setState(() {
      _ldEventLogList.add(ldEvent);
    });
  }

  @override
  void dispose() {
    _geoSdkFlutterPlugin.dispose();
    super.dispose();
  }

}
0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

A plugin to wrap the GeoSDK

Homepage

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on geo_sdk_flutter_plugin