wifi_connect 0.2.0

Flutter WiFi Connect #

Easily connect to a specified WiFi AP programmatically, using this plugin.

import 'package:wifi_connect/wifi_connect.dart';
WifiConnect.connect(context, 'ssid', 'password');

It's that simple. No fussing with permissions, enabling WiFi, location and all that boring stuff.


var connectedTo = WifiConnect.getConnectedSSID(context);
print('Connected to: $connectedTo');

And behold, the mighty WifiScannerMixin!

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

class _MyAppState extends State<MyApp> with WifiScannerMixin<MyApp> {
 @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Text("Connected to '$connectedSSID'"),
        )       
      )   
    );
  }

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

example/lib/main.dart

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

void main() {
  runApp(Wrapper(child: MyApp()));
}

class Wrapper extends StatelessWidget {
  final Widget child;

  const Wrapper({Key key, @required this.child}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Padding(
          padding: const EdgeInsets.all(10),
          child: child,
        ),
      ),
    );
  }
}

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

class _MyAppState extends State<MyApp> with WifiScannerMixin<MyApp> {
  @override
  Widget build(BuildContext context) {
    return ListView(
      children: <Widget>[
        TextField(
          controller: ssidControl,
          decoration: InputDecoration(labelText: 'SSID'),
        ),
        TextField(
          controller: passwordControl,
          decoration: InputDecoration(labelText: 'Password'),
        ),
        Divider(),
        CheckboxListTile(
          title: Text('hidden'),
          value: hidden,
          controlAffinity: ListTileControlAffinity.leading,
          onChanged: (value) {
            setState(() {
              hidden = value;
            });
          },
        ),
        Divider(),
        RaisedButton(
          child: Text("connect"),
          onPressed: connect,
        ),
        Divider(),
        if (connectedSSID.isEmpty)
          Text('Wifi is disconnected.')
        else
          Text("Connected to '$connectedSSID'"),
        Text('Status: $connectSuccess'),
      ],
    );
  }

  String connectSuccess;
  var hidden = false;
  var ssidControl = TextEditingController(text: 'Gecko1234');
  var passwordControl = TextEditingController(text: 'password');

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

  void showMessage(String msg) {
    showDialog(
      context: context,
      builder: (context) {
        return AlertDialog(
          content: Text(msg),
        );
      },
    );
  }

  Future<void> connect() async {
    setState(() {
      connectSuccess = '...';
    });
    try {
      await WifiConnect.connect(
        context,
        ssid: ssidControl.text,
        password: passwordControl.text,
        hidden: hidden,
        securityType: hidden ? SecurityType.wpa : SecurityType.auto,
      );
    } on WifiConnectException catch (e) {
      print('error: $e');
      setState(() {
        connectSuccess = e.status.toString();
      });
      return;
    }
    print('sucess!');
    setState(() {
      connectSuccess = 'Success!';
    });
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  wifi_connect: ^0.2.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:wifi_connect/wifi_connect.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
51
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
40
Overall:
Weighted score of the above. [more]
63
Learn more about scoring.

We analyzed this package on Mar 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health issues and suggestions

Document public APIs. (-0.09 points)

31 out of 32 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/src/dialogs.dart. (-0.50 points)

Analysis of lib/src/dialogs.dart reported 1 hint:

line 2 col 8: Don't import implementation files from another package.

Format lib/wifi_connect.dart.

Run flutter format to format lib/wifi_connect.dart.

Maintenance issues and suggestions

Provide a file named CHANGELOG.md. (-20 points)

Changelog entries help developers follow the progress of your package. See the example generated by stagehand.

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field https://github.com/pycampers/flutter-wifi-connect was unreachable.

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
plugin_scaffold ^2.0.0 2.0.0
use_location ^0.0.3 0.0.3
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test