flutter_nfc 1.0.0 copy "flutter_nfc: ^1.0.0" to clipboard
flutter_nfc: ^1.0.0 copied to clipboard

A new Flutter plugin, NFC functionality for Android and iOS.

example/lib/main.dart

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

void main() {
  runApp(MyApp());
}

///app
class MyApp extends StatelessWidget {
  // build
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter NFC',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter NFC'),
    );
  }
}

///home
class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

///homeState
class _MyHomePageState extends State<MyHomePage> {
  //输入框控制器
  TextEditingController writerController = TextEditingController();

  ///initState
  @override
  initState() {
    super.initState();
    //
    writerController.text = 'Flutter NFC Scan';
  }

  ///dispose
  @override
  void dispose() {
    writerController.dispose();
    super.dispose();
  }

  ///build
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text(
          "NFC",
          style: TextStyle(color: Colors.black, fontSize: 17),
        ),
      ),
      body: Column(
        children: <Widget>[
          TextField(
            controller: writerController,
          ),
          RaisedButton(
            onPressed: () {
              //NFC 监听
              FlutterNfc.onTagDiscovered().listen((value) {
                print("监听id: ${value.id}");
                print("监听content: ${value.content}");
              });
            },
            child: Text("NFC-监听"),
          ),
          RaisedButton(
            onPressed: () {
              ///NFC 读取
              FlutterNfc.read().then((value) {
                print("读取id: ${value.id}");
                print("读取content: ${value.content}");
              });
            },
            child: Text("NFC-读取"),
          ),
          RaisedButton(
            onPressed: () {
              ///NFC 写入
              FlutterNfc.write(" ", writerController.text).then((value) {
                print("写入: ${value.id}");
                print("写入: ${value.content}");
              });
            },
            child: Text("NFC-写入"),
          )
        ],
      ),
    );
  }
}
1
likes
40
pub points
30%
popularity

Publisher

unverified uploader

A new Flutter plugin, NFC functionality for Android and iOS.

Homepage

License

BSD-3-Clause (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_nfc