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

nfc plugin to manage nfc tag and set password , remove password and auth with password.

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:nfc_manager_new/nfc_manager_new.dart';
import 'package:nfc_manager_new/nfc_manager_utlity.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 _nfcManagerNewPlugin = NfcManagerNew();

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

  // 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 _nfcManagerNewPlugin.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) {
    var size = MediaQuery.of(context).size;
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            InkWell(
              onTap: () async {
                final isRemovePassword = await NfcManager.instance.startSession(
                    alertMessage:
                        'Hold the NFC tag on the upper back of your iPhone',
                    onDiscovered: (NfcTag tag) async {
                      final isRemovePassword =
                          await NfcManagerUtility.removePasswordWithTag(
                              tag: tag);
                      print("isRemovePassword: $isRemovePassword");
                      if (isRemovePassword) {
                        await NfcManager.instance.stopSession(
                            alertMessage: "Password remove successfully ");
                      }
                    });
              },
              child: button(size,
                  color: Colors.orangeAccent,
                  text: 'Password remove ',
                  textColor: Colors.white),
            ),
            InkWell(
              onTap: () async {
                final isRemovePassword = await NfcManager.instance.startSession(
                    alertMessage:
                        'Hold the NFC tag on the upper back of your iPhone',
                    onDiscovered: (NfcTag tag) async {
                      final isSetPassword =
                          await NfcManagerUtility.setPasswordWithTag(
                              tag: tag, password: "1111");
                      print("isSetPassword: $isSetPassword");
                      if (isSetPassword) {
                        await NfcManager.instance.stopSession(
                            alertMessage: "Password set successfully ");
                      }
                    });
              },
              child: button(size,
                  color: Colors.orangeAccent,
                  text: 'Password set',
                  textColor: Colors.white),
            ),
            InkWell(
              onTap: () async {
                final isRemovePassword = await NfcManager.instance.startSession(
                    alertMessage:
                        'Hold the NFC tag on the upper back of your iPhone',
                    onDiscovered: (NfcTag tag) async {
                      final isAuthTag = await NfcManagerUtility.authTag(
                          tag: tag, password: "1111");
                      print("isAuthTag: $isAuthTag");
                      if (isAuthTag) {
                        await NfcManager.instance.stopSession(
                            alertMessage: "Password Auth successfully ");
                      } else {
                        await NfcManager.instance
                            .stopSession(errorMessage: "Password can not auth");
                      }
                    });
              },
              child: button(size,
                  color: Colors.orangeAccent,
                  text: 'Password Auth',
                  textColor: Colors.white),
            ),
          ],
        ),
      ),
    );
  }

  Container button(Size size,
      {required Color color, required Color textColor, required String text}) {
    return Container(
        margin: const EdgeInsets.symmetric(vertical: 10),
        alignment: Alignment.center,
        width: size.width * 0.8,
        padding: EdgeInsets.all(20),
        decoration: BoxDecoration(
            color: color, borderRadius: BorderRadius.circular(20)),
        child: Text(
          "$text".toUpperCase(),
          style: TextStyle(color: textColor),
        ));
  }
}
2
likes
100
points
23
downloads

Publisher

unverified uploader

Weekly Downloads

nfc plugin to manage nfc tag and set password , remove password and auth with password.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

unknown (license)

Dependencies

convert, flutter, plugin_platform_interface

More

Packages that depend on nfc_manager_new