midtrans_sdk 0.3.4 icon indicating copy to clipboard operation
midtrans_sdk: ^0.3.4 copied to clipboard

A Flutter plugin for Midtrans Mobile SDK. Supports iOS and Android.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:midtrans_sdk/midtrans_sdk.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart' as DotEnv;

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await DotEnv.load();
  runApp(MyApp());
}

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

class _MyAppState extends State<MyApp> {
  MidtransSDK? _midtrans;

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

  void initSDK() async {
    _midtrans = await MidtransSDK.init(
      config: MidtransConfig(
        clientKey: DotEnv.env['MIDTRANS_CLIENT_KEY'] ?? "",
        merchantBaseUrl: DotEnv.env['MIDTRANS_MERCHANT_BASE_URL'] ?? "",
        colorTheme: ColorTheme(
          colorPrimary: Theme.of(context).accentColor,
          colorPrimaryDark: Theme.of(context).accentColor,
          colorSecondary: Theme.of(context).accentColor,
        ),
      ),
    );
    _midtrans?.setUIKitCustomSetting(
      skipCustomerDetailsPages: true,
    );
    _midtrans!.setTransactionFinishedCallback((result) {
      print(result.toJson());
    });
  }

  @override
  void dispose() {
    _midtrans?.removeTransactionFinishedCallback();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: ElevatedButton(
            child: Text("Pay Now"),
            onPressed: () async {
              _midtrans?.startPaymentUiFlow(
                token: DotEnv.env['SNAP_TOKEN'],
              );
            },
          ),
        ),
      ),
    );
  }
}
21
likes
120
pub points
73%
popularity

Publisher

verified publisher icontomykho.dev

A Flutter plugin for Midtrans Mobile SDK. Supports iOS and Android.

Repository (GitHub)

Documentation

API reference

License

Icon for licenses.MIT (LICENSE)

Dependencies

flutter, json_annotation, json_serializable

More

Packages that depend on midtrans_sdk