b4u_pos_sdk 0.0.2 copy "b4u_pos_sdk: ^0.0.2" to clipboard
b4u_pos_sdk: ^0.0.2 copied to clipboard

B4U POS SDk for Android

example/lib/main.dart

import 'package:b4u_pos_sdk/model/qr_response.dart';
import 'package:flutter/material.dart';
import 'package:b4u_pos_sdk/b4u_pos_sdk.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

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

class _MyAppState extends State<MyApp> {
  String? amount;
  QrResponse? qrResponse;

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

  getQRFromPlugin() async {
    try {
      var response = await B4uPosSdk.getQR(double.parse(amount!));
      setState(() {
        qrResponse = response;
      });
    } catch (e) {
      print(e);
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: [
              if (qrResponse == null)
                Column(
                  children: [
                    SizedBox(
                      width: 220,
                      child: Row(
                        children: [
                          Expanded(
                            child: TextFormField(
                              cursorHeight: 28,
                              keyboardType: TextInputType.number,
                              textAlign: TextAlign.center,
                              decoration: const InputDecoration(
                                label: Text(
                                  "Enter amount",
                                  textAlign: TextAlign.center,
                                  style: TextStyle(fontSize: 20),
                                ),
                                alignLabelWithHint: true,
                                floatingLabelAlignment: FloatingLabelAlignment.center,
                              ),
                              onChanged: (value) {
                                setState(() {
                                  amount = value;
                                });
                              },
                            ),
                          ),
                          const Text(
                            'USD',
                            style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
                          )
                        ],
                      ),
                    ),
                    const SizedBox(height: 20),
                    ElevatedButton(
                      style: ButtonStyle(backgroundColor: MaterialStateProperty.all(Colors.orange)),
                      onPressed: () {
                        getQRFromPlugin();
                      },
                      child: const Text('Get QR from B4U'),
                    ),
                  ],
                ),
              if (qrResponse != null)
                Column(
                  children: [
                    Image.network(qrResponse!.qrPath!),
                    const Text('Transaction ID:'),
                    Text(qrResponse!.transactionId!),
                    const SizedBox(height: 15),
                    const Text('Amount:'),
                    Text(qrResponse!.bitcoinAmount!.toString() + ' = ' + amount! + ' USD'),
                    const SizedBox(height: 15),
                  ],
                )
            ],
          ),
        ),
      ),
    );
  }
}


// if (qrImage == null)
0
likes
100
pub points
0%
popularity

Publisher

unverified uploader

B4U POS SDk for Android

Homepage

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

dio, flutter, uuid

More

Packages that depend on b4u_pos_sdk