mo_mifare_plugin 0.0.1 copy "mo_mifare_plugin: ^0.0.1" to clipboard
mo_mifare_plugin: ^0.0.1 copied to clipboard

PlatformAndroid

Plugin to work with Mifare clasic memory card via Mobiocean POS machine

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:mo_mifare_plugin/mo_mifare_plugin.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 _platformVersion = 'Unknown';

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String responseString;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      //First start Reader
      responseString =
          await MoMifarePlugin.startNfc() ?? 'Unknown platform version';
      // 0 - open Success, -1 - open error

      //To Stop reader
      responseString =
          await MoMifarePlugin.closeNfc() ?? 'Unknown platform version';
      // 0 - close Success, -1 - close error

      //To read card and get card no after successfull open
      responseString =
          await MoMifarePlugin.startReading() ?? 'Unknown platform version';
      // -1 - time out error, -2 - unknown card, -3 - Exception else json data with card details

      //To halt any on going operation
      responseString =
          await MoMifarePlugin.haltOperation() ?? 'Unknown platform version';
      // 0 - halt Success, -1 - halt error

      //To auth card via password after successfull read
      var blockNo = 2;
      var authKey = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; //byte array keys
      responseString =
          await MoMifarePlugin.authBlock(blockNo: blockNo, authKey: authKey) ?? 'Unknown platform version';
      // -1 - time out error, -2 - unknown card, -3 - Exception {else} json data with card details

      //To read block after successfull authentication
      blockNo = 2;
      responseString =
          await MoMifarePlugin.readBlock(blockNo: blockNo) ?? 'Unknown platform version';
      // null - error {else} value in the block

      //To write block after successfull authentication
      blockNo = 2;
      var value = "Hello";
      responseString =
          await MoMifarePlugin.writeBlock(blockNo: blockNo, conent: value) ?? 'Unknown platform version';
      // 0 - success, -1 - error

    } on PlatformException {
      responseString = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text('Running on: $_platformVersion\n'),
        ),
      ),
    );
  }
}
0
likes
110
pub points
6%
popularity

Publisher

unverified uploader

Plugin to work with Mifare clasic memory card via Mobiocean POS machine

Homepage

Documentation

API reference

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on mo_mifare_plugin