blux_flutter 0.0.8 copy "blux_flutter: ^0.0.8" to clipboard
blux_flutter: ^0.0.8 copied to clipboard

BluxClient Flutter SDK

example/lib/main.dart

import 'dart:async';

import 'package:blux_flutter/blux_flutter_events/blux_flutter_events.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:blux_flutter/blux_flutter_api_stage.dart';
import 'package:blux_flutter/blux_flutter.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({super.key});

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

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  final _plugin = BluxFlutter();

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> _initPlatformState() async {
    String version;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      version =
          await _plugin.getPlatformVersion() ?? 'Unknown platform version';
    } on PlatformException {
      version = '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 = version;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Blux SDK for Flutter'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text('Running on: $_platformVersion\n'),
              Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        ElevatedButton(
                          onPressed: () {
                            _plugin.setAPIStage(APIStage.prod);
                          },
                          child: const Text('Production'),
                        ),
                        ElevatedButton(
                          onPressed: () {
                            _plugin.setAPIStage(APIStage.stg);
                          },
                          child: const Text('Staging'),
                        ),
                      ],
                    ),
                    ElevatedButton(
                      onPressed: () {
                        _plugin.initialize(
                            "66a38b6a233aab065644296f",
                            "0QwVM7OdHcP1JlUm34acWQLTXnLLpInEncy3PT2QvtE",
                            true);
                      },
                      child: const Text('Initialize'),
                    ),
                    ElevatedButton(
                      onPressed: () {
                        _plugin.signIn("luna");
                      },
                      child: const Text('Sign In'),
                    ),
                    ElevatedButton(
                      onPressed: () {
                        _plugin.signOut();
                      },
                      child: const Text('Sign Out'),
                    ),
                    Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        ElevatedButton(
                          onPressed: () {
                            _plugin.sendEvent(AddProductDetailViewEvent(
                                itemId: "1234",
                                customEventProperties: {
                                  "custom_event_properties":
                                      "custom_event_properties"
                                }));
                          },
                          child: const Text('Send AddProductDetailView Event'),
                        ),
                        ElevatedButton(
                          onPressed: () {
                            _plugin.sendEvent(AddCartaddEvent(
                                itemId: "1234",
                                customEventProperties: {
                                  "custom_event_properties":
                                      "custom_event_properties"
                                }));
                          },
                          child: const Text('Send Cartadd Event'),
                        ),
                        ElevatedButton(
                          onPressed: () {
                            _plugin.sendEvent(AddCustomEvent(
                                eventType: "custom_conversion_event",
                                eventProperties: {
                                  "order_id": "ORDER_ID_123",
                                  "order_amount": 100,
                                  "paid_amount": 1500,
                                  "items": [
                                    {"id": "1234", "price": 200, "quantity": 6},
                                    {"id": "5678", "price": 300, "quantity": 1},
                                  ],
                                },
                                customEventProperties: {
                                  "custom_event_properties":
                                      "custom_event_properties"
                                }));
                          },
                          child: const Text('Send AddCustom Event'),
                        ),
                        ElevatedButton(
                          onPressed: () {
                            _plugin.sendEvent(
                              AddOrderEvent(
                                  orderAmount: 200,
                                  paidAmount: 100,
                                  items: [
                                    {"id": "1234", "price": 200, "quantity": 6}
                                  ],
                                  orderId: "wowowo",
                                  customEventProperties: {
                                    "custom_event_properties":
                                        "custom_event_properties"
                                  }),
                            );
                          },
                          child: const Text('Send AddPurchase Event'),
                        ),
                        ElevatedButton(
                          onPressed: () {
                            _plugin.sendEvent(
                              AddOrderEvent(
                                  orderAmount: 200,
                                  paidAmount: 100,
                                  items: [
                                    {"id": "1234", "price": 200, "quantity": 6},
                                    {"id": "5678", "price": 300, "quantity": 1},
                                  ],
                                  orderId: "num1"),
                            );
                          },
                          child: const Text('Send AddPurchase Event Multiple'),
                        ),
                      ],
                    ),
                  ]),
            ],
          ),
        ),
      ),
    );
  }
}