blux_flutter 0.1.1
blux_flutter: ^0.1.1 copied to clipboard
BluxClient Flutter SDK
example/lib/main.dart
import 'dart:async';
import 'package:blux_flutter/blux_flutter.dart';
import 'package:blux_flutter/blux_flutter_api_stage.dart';
import 'package:blux_flutter/blux_flutter_events/blux_flutter_events.dart';
import 'package:blux_flutter_example/webview/blux_inapp_webview.dart';
import 'package:blux_flutter_example/webview/blux_webview.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.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: SingleChildScrollView(
padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 12),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Running on $_platformVersion\n'),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: () {
_plugin.setAPIStage(APIStage.prod);
},
child: const Text('Production'),
),
const SizedBox(width: 8),
ElevatedButton(
onPressed: () {
_plugin.setAPIStage(APIStage.stg);
},
child: const Text('Staging'),
),
],
),
const SizedBox(height: 16),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: () {
_plugin.initialize(
bluxApplicationId: '66a38b6a233aab065644296f',
bluxAPIKey:
'0QwVM7OdHcP1JlUm34acWQLTXnLLpInEncy3PT2QvtE',
requestPermissionsOnLaunch: true,
);
},
child: const Text('Initialize'),
),
ElevatedButton(
onPressed: () {
_plugin.signIn(userId: 'luna');
},
child: const Text('Sign In'),
),
ElevatedButton(
onPressed: () {
_plugin.signOut();
},
child: const Text('Sign Out'),
),
],
),
const SizedBox(height: 16),
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 AddOrderEvent Event Multiple'),
),
],
),
const SizedBox(height: 16),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Builder(
builder: (innerContext) => ElevatedButton(
onPressed: () {
Navigator.push(
innerContext,
MaterialPageRoute(
builder: (_) => const BluxWebView(
initialUrl:
'https://diandrous-hypogenic-alivia.ngrok-free.dev/?application_id=66fac6b03e71e06835703c25&api_key=Is5r2sK-HBQe4sX343twQopcccevFm0Ci6nu9tA9',
// 'https://diandrous-hypogenic-alivia.ngrok-free.dev/?application_id=66a38b6a233aab065644296f&api_key=0QwVM7OdHcP1JlUm34acWQLTXnLLpInEncy3PT2QvtE',
),
),
);
},
child: const Text('Open WebView (webview_flutter)'),
),
),
Builder(
builder: (innerContext) => ElevatedButton(
onPressed: () {
Navigator.push(
innerContext,
MaterialPageRoute(
builder: (_) => const BluxInAppWebView(
initialUrl:
'https://diandrous-hypogenic-alivia.ngrok-free.dev/?application_id=66fac6b03e71e06835703c25&api_key=Is5r2sK-HBQe4sX343twQopcccevFm0Ci6nu9tA9',
// 'https://diandrous-hypogenic-alivia.ngrok-free.dev/?application_id=66a38b6a233aab065644296f&api_key=0QwVM7OdHcP1JlUm34acWQLTXnLLpInEncy3PT2QvtE',
),
),
);
},
child: const Text(
'Open WebView (flutter_inappwebview)',
),
),
),
],
),
],
),
),
),
),
);
}
}