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

outdated

A new flutter plugin project.

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:nfc_hce_reader/nfc_hce_reader.dart';

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

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

class _MyAppState extends State<MyApp> {
  String _message = 'meme';
  StreamSubscription<String> _stream;

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

  Future<void> initPlatformState() async {
    bool isInitialized;
    try {
      isInitialized = await NfcHceReader.initializeNFCReading();
      _readNFC(context);
    } on PlatformException {

    }

    if (!mounted) return;


  }

  void _readNFC(BuildContext context) {
    StreamSubscription<String> subscription = NfcHceReader.readNFCStream()
        .listen((tag) {
      setState(() {
        _message = tag;
        _stream?.cancel();
      });
    },
        onDone: () {
          setState(() {
            _stream = null;
          });
        },
        onError: (e) {
          setState(() {
            _stream = null;
          });
        });
    setState(() {
      _stream = subscription;
    });
  }

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

Publisher

unverified uploader

A new flutter plugin project.

Homepage

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on nfc_hce_reader