flutteresptouchplugin 0.0.3
flutteresptouchplugin: ^0.0.3 copied to clipboard

Flutter Android iOS

Esp32 wifi plugin for flutter

example/lib/main.dart

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

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

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

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

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  Map _wifiInfo = {};
  String _password;
  String status = '未连接';
  bool isconnecting = false;

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    Map wifiInfo;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await Flutteresptouchplugin.platformVersion;
      wifiInfo = await Flutteresptouchplugin.wifiInfo;
    } 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;
      _wifiInfo = wifiInfo;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(children: <Widget>[
            Text('Running on: $_platformVersion\n'),
            Text('当前wifi'),
            Text('SSID: ${_wifiInfo['ssid']}'),
            Text('bSSID: ${_wifiInfo['bssid']}'),
            SizedBox(height: 30),
            Container(
                width: 200,
                child: TextField(
                    decoration: InputDecoration(labelText: 'wifi密码'),
                    onChanged: (e) {
                      _password = e;
                    })),
            SizedBox(
              height: 20,
            ),
            FlatButton(
                onPressed: () {
                  if (isconnecting) {
                    stop();
                  } else {
                    String ssid = _wifiInfo['ssid'];
                    String bssid = _wifiInfo['bssid'];
                    connect(ssid, bssid, _password);
                  }
                },
                child: Text('连接设备'),
                shape: RoundedRectangleBorder(side: BorderSide(width: 1))),
            SizedBox(height: 40),
            Text(status)
          ]),
        ),
      ),
    );
  }

  connect(String ssid, String bssid, String password) async {
    isconnecting = true;
    setState(() {
      status = "连接中。。。";
    });

    List a = await Flutteresptouchplugin.startConnect(ssid, bssid, password);

    setState(() {
      status = "连接操作完成";
    });
    print(a);
  }

  stop() {
    Flutteresptouchplugin.cancelConnect();
    isconnecting = false;
    setState(() {
      status = "取消";
    });
  }
}
0
likes
80
pub points
8%
popularity

Esp32 wifi plugin for flutter

Homepage

Documentation

API reference

Uploader

xintaozhang88@gmail.com

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on flutteresptouchplugin