appboxo_sdk 0.2.9 copy "appboxo_sdk: ^0.2.9" to clipboard
appboxo_sdk: ^0.2.9 copied to clipboard

A Flutter plugin to integrate the Appboxo for iOS and Android.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:appboxo_sdk/appboxo_sdk.dart';
import 'package:fluttertoast/fluttertoast.dart';

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

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

class _MyAppState extends State<MyApp> {
  Future<void> Function()? subscription;

  @override
  void dispose() {
    subscription?.call();
    super.dispose();
  }

  @override
  void initState() {
    super.initState();
    Appboxo.setConfig("602248", userId:"24", multitaskMode: false);
    //'multitaskMode' works only on Android. By default 'true', each miniapp appears as a task in the Recents screen.
    Appboxo.customEvents().listen((CustomEvent event) {
      print(event.toJson().toString());
      Fluttertoast.showToast(
        msg: event.payload["message"] ?? event.type,
        toastLength: Toast.LENGTH_SHORT,
        timeInSecForIosWeb: 1,
        backgroundColor: Colors.black,
        textColor: Colors.white,
        fontSize: 16.0,
      );
      Appboxo.sendEvent(event);
    });
    Appboxo.paymentEvents().listen((event) {
      event.status = "success";
      Appboxo.sendPaymentEvent(event);
    });

    Appboxo.miniapps().listen((result) {
      print('miniapps - ${result.miniapps.toString()}');
      result.miniapps?.forEach((data) => print(data.name));
      print('error - ${result.error}');
    });
    Appboxo.getMiniapps();

    subscription = Appboxo.lifecycleHooksListener(
      onAuth: (appId) {
        print(appId);
        print('onAuth');
      },
      onLaunch: (appId) {
        print(appId);
        print('onLaunch');
      },
      onResume: (appId) {
        print(appId);
        print('onResume');
      },
      onPause: (appId) {
        print(appId);
        print('onPause');
      },
      onClose: (appId) {
        print(appId);
        print('onClose');
      },
      onError: (appId, error) {
        print(appId);
        print(error);
        print('onError');
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Appboxo SDK Test'),
        ),
        body: Center(
          child: ElevatedButton(
            onPressed: () {
              Appboxo.openMiniapp("app16973", data: {
                'title': 'Title'
              }, extraUrlParams: {
                'key': 'value'
              }, colors: {
                'primary_color': '#000000',
                'secondary_color': '#0000FF',
                'tertiary_color': '#00FF00'
              }, enableSplash: false);
            },
            child: const Text(
              'Run miniapp',
              style: const TextStyle(
                color: Colors.white,
                fontSize: 16,
              ),
            ),
          ),
        ),
      ),
    );
  }
}
3
likes
0
points
64
downloads

Publisher

verified publisherappboxo.com

Weekly Downloads

A Flutter plugin to integrate the Appboxo for iOS and Android.

Homepage

License

unknown (license)

Dependencies

flutter

More

Packages that depend on appboxo_sdk