nfc_io 1.0.2+1 copy "nfc_io: ^1.0.2+1" to clipboard
nfc_io: ^1.0.2+1 copied to clipboard

A new flutter plugin to help developers looking to use internal hardware inside Android devices (For now, iOS coming soon) for reading NFC tags.

example/lib/main.dart

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

import 'package:nfc_io/nfc_io.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool isReading = false;
  NfcData data;
  StreamSubscription _subscription;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('NFC IO example app'),
        ),
        body: Center(
          child: Column(
            children: <Widget>[
              Text('Status: ${data?.status ?? "Not ready yet"}'),
              Text('Card ID: ${data?.id ?? "Unavailable"}'),
              Text('Card Content: ${data?.content ?? "Unavailable"}'),
              SizedBox(
                height: 40,
              ),
              RawMaterialButton(
                child: Row(
                  children: <Widget>[
                    Icon(isReading ? Icons.stop : Icons.play_arrow),
                    SizedBox(width: 16,),
                    Text(isReading ? "Stop Scanning" : "Start Scanning"),
                  ],
                ),
                onPressed: () async {
                  if (!isReading) {
                    _subscription = NfcIo.startReading.listen((data) {
                      setState(() {
                        this.data = data;
                      });
                    });
                  } else {
                    if (_subscription != null) {
                      _subscription.cancel();
                      var result = await NfcIo.stopReading;
                      setState(() {
                        this.data = result;
                      });
                    }
                  }
                  setState(() {
                    isReading = !isReading;
                  });
                },
              )
            ],
          ),
        ),
      ),
    );
  }
}
6
likes
30
pub points
46%
popularity

Publisher

unverified uploader

A new flutter plugin to help developers looking to use internal hardware inside Android devices (For now, iOS coming soon) for reading NFC tags.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on nfc_io