mxnfc 0.0.3 copy "mxnfc: ^0.0.3" to clipboard
mxnfc: ^0.0.3 copied to clipboard

1.增加ios机型适配

example/lib/main.dart

import 'dart:async';
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:mxnfc/mxnfc.dart';
import 'package:mxnfc/nfcresultmodel.dart';

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 _mxnfcPlugin = Mxnfc.instance;

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

  readNFC(){
Mxnfc.instance.startScanNfc("贴近手臂顶部");
Mxnfc.instance.onMessageRecive(sucCallBack:(message) {
  if(message is String){
    print("message:$message");
    Map<String,dynamic> map = jsonDecode(message);
    if(map["key"]  == "success"){
      if(map["action"] == "startScanNfc"){ //扫描开始
          
      }else if(map["action"] == "read"){ //读取成功
        
      }
    }else{
      if(map["key"] == "error"){
       if(map["action"] == "startScanNfc"){ //扫描开始
          if(map["type"] == "noSupport"){ //不支持

          }else if(map["type"] == "timeout"){ //超时

          }
      }else if(map["action"] == "read"){ //失败
         
      }
      }
    }

    
  }
}, errCallBack:(error) {
  print("error:$error");
},);
 
}

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      platformVersion =
          await _mxnfcPlugin.getPlatformVersion() ?? 'Unknown platform version';
    } on PlatformException {
      platformVersion = '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 = platformVersion;
    });
  }

  @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'),
        ),
          floatingActionButton:FloatingActionButton(
          child: const Text("开始扫描"),
          onPressed: (){
              Mxnfc.instance.scanNfc(message: "贴近手臂底部",successCallBack:(m) {
              if(m is NFCResultModel){
                print("->>m:$m");
              }
              }, failedCallBack:(m) {
                if(m is NFCResultModel){
                  NFCResultModel m1 = m;
                     print("->>m:$m1 type:${m1.resultType}");
                }
                
              },);
          }),
      ),
    );
  }
}
1
likes
0
points
1
downloads

Publisher

unverified uploader

Weekly Downloads

1.增加ios机型适配

Homepage

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on mxnfc

Packages that implement mxnfc