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

PlatformAndroid

A test plugin publish for flutter.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'dart:async';
import 'package:flutter/services.dart';
import 'package:testpluginflutter/testpluginflutter.dart';
import 'package:testpluginflutter/testpluginflutter_method_channel.dart';
import 'package:testpluginflutter/testpluginflutter_platform_interface.dart';

import 'package:nfc_manager/nfc_manager.dart';
import 'package:testpluginflutter/testpluginflutter_method_channel.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);


  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  var _nfcStatus = NfcStatus.unknown;
  final _qaMobileAccessPlugin = Testpluginflutter();
  bool _started = false;
  ValueNotifier<dynamic> result = ValueNotifier(null);
  @override
  void initState() {
    super.initState();
    initPlatformState();


  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    var nfcStatus = NfcStatus.unknown;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      platformVersion =
          await _qaMobileAccessPlugin.getPlatformVersion() ?? 'Unknown platform version';

      nfcStatus = await MethodChannelTestpluginflutter.nfcStatus;
    } 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;
      _nfcStatus = nfcStatus;

      initPlatformState();

    });
  }



  @override
  void didUpdateWidget(covariant MyApp oldWidget) {
    // TODO: implement didUpdateWidget
    super.didUpdateWidget(oldWidget);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('QA Mobile Access'),
        ),
        body: Container(
          alignment: Alignment.center,
          child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Text('Version: $_platformVersion'),
                SizedBox(height: 20.0),
                ValueListenableBuilder<dynamic>(
                  valueListenable: result,
                  builder: (context, value, _) =>
                      Text('Card#:${value ?? ''}'),
                ),
                SizedBox(height: 20.0),
                Text('Status: $_nfcStatus'),
                SizedBox(height: 40.0),
                ElevatedButton(
                    child: Text(_started ? "Stop NFC Service" : "Start NFC Service"),
                    onPressed: startStopEmulator),
                ElevatedButton(
                    child: Text("Tag Read"),
                    onPressed: _tagRead),
              ]),
        ),
      ),
    );
  }

  void startStopEmulator() async {
    if (_started) {
      await MethodChannelTestpluginflutter.stopNfcService();
    } else {
      //Shared Pref card, manualInput
      await MethodChannelTestpluginflutter.startNfcService(result.value,true);
    }
    setState(() {
      _started = !_started;
    });
  }

  void readCardNumber() async
  {
    String? s = await MethodChannelTestpluginflutter.readCardNumber();
    result.value = s?.toUpperCase();
  }

  void _tagRead() {
    NfcManager.instance.startSession(onDiscovered: (NfcTag tag) async {
      String? s = await MethodChannelTestpluginflutter.byteToHex(tag.data['nfca']['identifier']);
      result.value = s?.toUpperCase();
      //NfcManager.instance.stopSession();

      await MethodChannelTestpluginflutter.stopNfcService();
      _started = false;

    });
  }


}
1
likes
105
points
6
downloads

Publisher

unverified uploader

Weekly Downloads

A test plugin publish for flutter.

Documentation

API reference

License

unknown (license)

Dependencies

flutter, nfc_manager, plugin_platform_interface

More

Packages that depend on testpluginflutter

Packages that implement testpluginflutter