blusalt_checkout 1.1.5 copy "blusalt_checkout: ^1.1.5" to clipboard
blusalt_checkout: ^1.1.5 copied to clipboard

Checkout SDK for Blusalt Payment

example/lib/main.dart

import 'dart:io';
import 'dart:async';

import 'package:blusalt_checkout/enums.dart';
import 'package:blusalt_checkout/blusalt_checkout.dart';
import 'package:blusalt_checkout/model.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:blusalt_checkout_example/json_viewer_widget.dart';

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

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

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

class _MyAppState extends State<MyApp> {
  final _checkoutPlugin = BlusaltCheckout();

  File? imageUri;
  TextEditingController apiKeyCC = TextEditingController(text: '');
  TextEditingController amountCC = TextEditingController(text: '1000');
  TextEditingController currencyCC = TextEditingController(text: 'NGN');
  TextEditingController walletIdCC = TextEditingController(text: 'master');
  TextEditingController companyEmail = TextEditingController();
  TextEditingController referenceController = TextEditingController();

  bool isDev = false;
  bool isPaymentPro = true; // See your dashboard for more detail

  final ImagePicker _picker = ImagePicker();

  BlusaltCheckoutResultResponse? resultResponse;

  @override
  void dispose() {
    super.dispose();
    apiKeyCC.dispose();
    amountCC.dispose();
    currencyCC.dispose();
    walletIdCC.dispose();
    companyEmail.dispose();
    referenceController.dispose();
  }

  pickCompanyLogo() async {
    if (imageUri != null) {
      setState(() {
        imageUri = null;
      });
      return;
    }

    final XFile? image = await _picker.pickImage(source: ImageSource.gallery);
    if (image != null) {
      setState(() {
        imageUri = File(image.path);
      });
    }
  }

  Future<BlusaltCheckoutResultResponse?> startCheckout() async {
    resultResponse = await _checkoutPlugin.startCheckoutSDK(
      apiKey: apiKeyCC.text,
      isDev: isDev,
      isPayment: isPaymentPro,
      amount: amountCC.text.isNotEmpty ? double.parse(amountCC.text) : 0,
      currency: currencyCC.text,
      walletId: walletIdCC.text,
      companyEmail: companyEmail.text.isEmpty ? null : companyEmail.text,
      reference: referenceController.text,
      companyLogo: imageUri != null ? (await imageUri?.readAsBytes()) : null,
      iosConfig: IosConfig(
        iosPresentationStyle: IosPresentationStyle.shrinkBottomModal,
      ),
    );
    if (resultResponse?.blusaltCheckoutProcess ==
        BlusaltCheckoutProcess.completed) {
      setState(() {});
    } else {
      debugPrint(resultResponse?.code ?? '');
      debugPrint(resultResponse?.message ?? '');
    }
    return resultResponse;
  }

  double? validateNumber(String value) {
    if (value.isEmpty) {
      return null;
    }

    return double.tryParse(value);
  }

  int? validateDurationNumber(String value) {
    if (value.isEmpty) {
      return null;
    }

    return int.tryParse(value);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Plugin example app')),
        body: SingleChildScrollView(
          padding: const EdgeInsets.all(16),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              if (imageUri != null)
                Image.file(imageUri!, width: 100, height: 100)
              else
                const Padding(
                  padding: EdgeInsets.only(top: 20),
                  child: Text("No image selected"),
                ),
              const SizedBox(height: 14),

              TextField(
                controller: apiKeyCC,
                decoration: const InputDecoration(
                  border: OutlineInputBorder(),
                  hintText: "Enter api key",
                  hintStyle: TextStyle(color: Color(0xFFCCCCCC)),
                ),
                onChanged: (text) => setState(() {}),
              ),

              const SizedBox(height: 14),
              TextField(
                controller: amountCC,
                decoration: const InputDecoration(
                  border: OutlineInputBorder(),
                  hintText: "Enter amount",
                  hintStyle: TextStyle(color: Color(0xFFCCCCCC)),
                ),
                onChanged: (text) => setState(() {}),
              ),
              const SizedBox(height: 14),
              TextField(
                controller: currencyCC,
                decoration: const InputDecoration(
                  border: OutlineInputBorder(),
                  hintText: "Enter currency",
                  hintStyle: TextStyle(color: Color(0xFFCCCCCC)),
                ),
                onChanged: (text) => setState(() {}),
              ),
              const SizedBox(height: 14),
              TextField(
                controller: walletIdCC,
                decoration: const InputDecoration(
                  border: OutlineInputBorder(),
                  hintText: "Enter wallet Id",
                  hintStyle: TextStyle(color: Color(0xFFCCCCCC)),
                ),
                onChanged: (text) => setState(() {}),
              ),
              const SizedBox(height: 14),
              TextField(
                controller: referenceController,
                decoration: const InputDecoration(
                  border: OutlineInputBorder(),
                  hintText: "Enter reference (Optional)",
                  hintStyle: TextStyle(color: Color(0xFFCCCCCC)),
                ),
                onChanged: (text) => setState(() {}),
              ),
              const SizedBox(height: 14),
              TextField(
                controller: companyEmail,
                decoration: const InputDecoration(
                  border: OutlineInputBorder(),
                  hintText: "Enter company email",
                  hintStyle: TextStyle(color: Color(0xFFCCCCCC)),
                ),
                onChanged: (text) => setState(() {}),
              ),
              const SizedBox(height: 4),
              CustomCheckbox(
                label: "Point to Development Environment?",
                value: isDev,
                onCheck: (value) => setState(() => isDev = value),
              ),
              const SizedBox(height: 2),
              CustomCheckbox(
                label: "Is Payment Pro",
                value: isPaymentPro,
                onCheck: (value) => setState(() => isPaymentPro = value),
              ),

              const SizedBox(height: 24),
              Row(
                children: [
                  Expanded(
                    child: ElevatedButton(
                      onPressed: pickCompanyLogo,
                      style: ElevatedButton.styleFrom(
                        backgroundColor: Colors.blue,
                        minimumSize: const Size(double.infinity, 50),
                      ),
                      child: Text(
                        imageUri != null
                            ? 'Clear company logo'
                            : "Pick company logo",
                        textAlign: TextAlign.center,
                        style: TextStyle(color: Colors.white),
                      ),
                    ),
                  ),
                  const SizedBox(width: 16),
                  Expanded(
                    child: ElevatedButton(
                      onPressed: startCheckout,
                      style: ElevatedButton.styleFrom(
                        backgroundColor: Colors.blue,
                        minimumSize: const Size(double.infinity, 50),
                      ),
                      child: const Text(
                        "Start Checkout SDK",
                        textAlign: TextAlign.center,
                        style: TextStyle(color: Colors.white),
                      ),
                    ),
                  ),
                ],
              ),
              if (resultResponse?.blusaltCheckoutProcess ==
                  BlusaltCheckoutProcess.completed)
                const SizedBox(height: 34),
              if (resultResponse?.blusaltCheckoutProcess ==
                  BlusaltCheckoutProcess.completed)
                Text(
                  "Result",
                  textAlign: TextAlign.center,
                  style: const TextStyle(fontWeight: FontWeight.w500),
                ),
              if (resultResponse?.blusaltCheckoutProcess ==
                  BlusaltCheckoutProcess.completed)
                const SizedBox(height: 4),
              if (resultResponse?.blusaltCheckoutProcess ==
                  BlusaltCheckoutProcess.completed)
                JsonViewerWidget(jsonData: resultResponse?.toJson()),
              const SizedBox(height: 34),
              Image.asset(
                'assets/images/blusalt_logo.png',
                width: 100,
                height: 100,
                color: Colors.black,
              ),
              const SizedBox(height: 24),
            ],
          ),
        ),
      ),
    );
  }
}

class CustomCheckbox extends StatelessWidget {
  final String label;
  final bool value;
  final Function(bool) onCheck;

  const CustomCheckbox({
    Key? key,
    required this.label,
    required this.value,
    required this.onCheck,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        Checkbox(
          materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
          value: value,
          onChanged: (newValue) => onCheck(newValue ?? false),
        ),
        Expanded(
          child: Text(
            label,
            style: const TextStyle(fontWeight: FontWeight.w500),
          ),
        ),
      ],
    );
  }
}
0
likes
140
points
34
downloads

Publisher

unverified uploader

Weekly Downloads

Checkout SDK for Blusalt Payment

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, flutter_web_plugins, plugin_platform_interface, web

More

Packages that depend on blusalt_checkout

Packages that implement blusalt_checkout