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

BlucClient 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")
                                  .setPage("page")
                            ]);
                          },
                          child: const Text('Send AddProductDetailView Event'),
                        ),
                        ElevatedButton(
                          onPressed: () {
                            _plugin
                                .sendEvent([AddCartaddEvent(itemId: "1234")]);
                          },
                          child: const Text('Send Cartadd Event'),
                        ),
                        ElevatedButton(
                          onPressed: () {
                            _plugin.sendEvent([AddLikeEvent(itemId: "1234")]);
                          },
                          child: const Text('Send AddLike Event'),
                        ),
                        ElevatedButton(
                          onPressed: () {
                            _plugin.sendEvent([
                              AddPurchaseEvent(
                                  itemId: "1234",
                                  price: 200,
                                  quantity: 6,
                                  orderId: "wowowo")
                            ]);
                          },
                          child: const Text('Send AddPurchase Event'),
                        ),
                        ElevatedButton(
                          onPressed: () {
                            _plugin.sendEvent([
                              AddPurchaseEvent(
                                  itemId: "1234",
                                  price: 200,
                                  quantity: 6,
                                  orderId: "num1"),
                              AddPurchaseEvent(
                                  itemId: "1234",
                                  price: 200,
                                  quantity: 6,
                                  orderId: "num2"),
                              AddPurchaseEvent(
                                  itemId: "1234",
                                  price: 200,
                                  quantity: 6,
                                  orderId: "num3")
                            ]);
                          },
                          child: const Text('Send AddPurchase Event Multiple'),
                        ),
                      ],
                    ),
                  ]
              ),
            ],
          ),
        ),
      ),
    );
  }
}