dtb_link 0.0.11+18 copy "dtb_link: ^0.0.11+18" to clipboard
dtb_link: ^0.0.11+18 copied to clipboard

DTB Link - utility app enabling applications to connect and integrate with NFC card readers over Bluetooth

example/lib/main.dart

import 'package:dtb_link/dtb_link.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:percent_indicator/circular_percent_indicator.dart';
import 'config_page.dart';
import 'dtb_helper.dart';

enum EasyKey { sKey, echo, saleTran, voidTran }

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 _scrollController = ScrollController();

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((_) {
      debugPrint("initPlatformState");
      service.initOnEvent();
      initPlatformState();
    });
  }

  Future<void> initPlatformState() async {
    String platformVersion;
    try {
      debugPrint("platformVersion before");
      platformVersion = await service.dtbLink.getPlatformVersion() ??
          'Unknown platform version';
      debugPrint("platformVersion: $platformVersion");
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      theme: ThemeData(
        brightness: Brightness.dark,
        appBarTheme: const AppBarTheme(
          systemOverlayStyle:
              SystemUiOverlayStyle(statusBarBrightness: Brightness.dark),
          backgroundColor: Colors.transparent,
          centerTitle: false,
          titleSpacing: 10,
          elevation: 0,
        ),
        primaryColor: color20,
        scaffoldBackgroundColor: color01,
      ),
      home: Scaffold(
        appBar: AppBar(title: Text("DTB Link Flutter Demo $_platformVersion")),
        body: Column(
          children: [
            _buildConfig(),
            _buildEasyTransaction(),
            _buildTranHistory(),
          ],
        ),
      ),
    );
  }

  Widget _buildConfig() {
    return Container(
      decoration: const BoxDecoration(
        color: color02,
        borderRadius: BorderRadius.only(
            bottomLeft: Radius.circular(20), bottomRight: Radius.circular(20)),
        image: DecorationImage(
          image: AssetImage("assets/home_section_bg.png"),
          fit: BoxFit.fitWidth,
        ),
      ),
      child: Padding(
        padding: const EdgeInsets.all(16),
        child: Row(
          children: [
            Expanded(
              child: Column(
                children: [
                  buildDeviceInfo(),
                  //       _buildTerminalInfo(
                  //         context
                  //             .watch<DemoProvider>()
                  //             .terminalConfigPercent,
                  //         context
                  //             .watch<DemoProvider>()
                  //             .terminalConfigTitle,
                  //       ),
                  const SizedBox(height: 16),
                  ElevatedButton(
                    onPressed: () => Get.to(const ConfigPage()),
                    style: ElevatedButton.styleFrom(
                      shape: const StadiumBorder(),
                      backgroundColor: color20,
                      side: const BorderSide(color: color03, width: 3),
                    ),
                    child: const Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      mainAxisSize: MainAxisSize.max,
                      children: [
                        Text('Тохиргоо'),
                        Icon(Icons.chevron_right),
                      ],
                    ),
                  ),
                ],
              ),
            ),
            const SizedBox(width: 16),
            CircularPercentIndicator(
              radius: 80,
              lineWidth: 6,
              animation: true,
              percent: 0.755,
              startAngle: 180,
              backgroundColor: color03,
              animationDuration: 2000,
              center: Container(
                height: 138,
                width: 138,
                decoration:
                    const BoxDecoration(shape: BoxShape.circle, color: color01),
                child: Center(
                  child: Container(
                    height: 126,
                    width: 126,
                    decoration: const BoxDecoration(
                        shape: BoxShape.circle, color: color04),
                    child: const Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Text("Тохиргоо"),
                        Text(
                          "42.31%",
                          style: TextStyle(fontWeight: FontWeight.bold),
                        ),
                        Text(
                          "-42,aa",
                          style: TextStyle(color: color11),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
              circularStrokeCap: CircularStrokeCap.round,
              progressColor: color20,
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildEasyTransaction() {
    return Obx(() {
      final initData = service.initData.value;
      final Map<String, dynamic> lastTran = service.lastTran;
      debugPrint("lastTran: $lastTran");
      return Container(
        margin: const EdgeInsets.all(10),
        padding:
            const EdgeInsets.only(left: 10, right: 10, top: 20, bottom: 20),
        decoration: const BoxDecoration(
          color: color02,
          borderRadius: BorderRadius.all(Radius.circular(20)),
        ),
        child: Column(
          children: [
            const Row(
              mainAxisSize: MainAxisSize.max,
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text("Хялбар Гүйлгээ"),
                Icon(Icons.edit_note, color: color05),
              ],
            ),
            const SizedBox(height: 20),
            LayoutBuilder(builder: (context, constraint) {
              double width = constraint.maxWidth / 4 - 6;
              Size size = Size(width, width);
              return Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  EasyButton(
                    size: size,
                    onPressed: initData.netEncKey != null
                        ? () => _onAddLog(EasyKey.sKey, initData: initData)
                        : null,
                    child: const Text("SKey"),
                  ),
                  EasyButton(
                    size: size,
                    onPressed: initData.netEncKey != null
                        ? () => _onAddLog(EasyKey.echo, initData: initData)
                        : null,
                    child: const Text("Echo"),
                  ),
                  EasyButton(
                    size: size,
                    onPressed: initData.netEncKey != null
                        ? () => _onAddLog(EasyKey.saleTran, initData: initData)
                        : null,
                    child: const Text("Sale"),
                  ),
                  EasyButton(
                    size: size,
                    onPressed: lastTran.isEmpty
                        ? null
                        : () => _onAddLog(EasyKey.voidTran, initData: initData),
                    child: const Text("Void"),
                  ),
                ],
              );
            })
          ],
        ),
      );
    });
  }

  _onAddLog(EasyKey key, {required DataInitRet initData}) {
    service.addLog(key.name.toUpperCase()).then((_) => _scrollDown());
    if (key == EasyKey.sKey) {
      service.syncKey().then((keyRet) {
        service.addLog("${keyRet.toJson()}").then((_) => _scrollDown());
      });
    } else if (key == EasyKey.echo) {
      service.terminalEchoTest().then((ret) {
        service.addLog("$ret").then((_) => _scrollDown());
      });
    } else if (key == EasyKey.saleTran) {
      service.transactionSale().then((ret) {
        service.addLog("$ret").then((_) => _scrollDown());
      });
    } else if (key == EasyKey.voidTran) {
      service.transactionVoid().then((ret) {
        service.addLog("$ret").then((_) => _scrollDown());
      });
    }
  }

  Widget _buildTranHistory() {
    return Expanded(
      child: Container(
        margin: const EdgeInsets.only(left: 10, right: 10, bottom: 20),
        padding:
            const EdgeInsets.only(left: 10, right: 10, top: 20, bottom: 20),
        decoration: const BoxDecoration(
            color: color02,
            borderRadius: BorderRadius.all(Radius.circular(20))),
        child: Column(
          children: [
            const Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [Text("Комманд лог"), Icon(Icons.history)],
            ),
            Expanded(
              child: SizedBox(
                width: MediaQuery.of(context).size.width - 20,
                child: Scrollbar(
                  thumbVisibility: true,
                  controller: _scrollController,
                  child: SingleChildScrollView(
                    controller: _scrollController,
                    child: _buildLog(),
                  ),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }

  Widget _buildLog() {
    return Obx(() {
      final logData = service.logData;
      List<Widget> list = [];
      for (String log in logData) {
        list.add(Text(log));
      }
      return Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisSize: MainAxisSize.min,
        children: list,
      );
    });
  }

  void _scrollDown() {
    _scrollController.animateTo(
      _scrollController.position.maxScrollExtent,
      duration: const Duration(seconds: 1),
      curve: Curves.fastOutSlowIn,
    );
  }
}
0
likes
160
points
29
downloads

Publisher

verified publisherdatabank.mn

Weekly Downloads

DTB Link - utility app enabling applications to connect and integrate with NFC card readers over Bluetooth

Homepage

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

crypto, device_info_plus, device_marketing_names, flutter, http, intl, package_info_plus, path_provider, plugin_platform_interface, pointycastle, shared_preferences

More

Packages that depend on dtb_link