Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
31cca08
[wifi_scan,ci] `wifi_scan` workflow added
daadu Dec 4, 2021
fdf0274
[wifi_scan] plugin created from template
daadu Dec 5, 2021
c7432c5
formatting
daadu Dec 5, 2021
05780d5
[wifi_scan,ci] disable "ios" job
daadu Dec 5, 2021
451539a
[wifi_scan] renamed `WifiScan` -> `WiFiScan`; made it singleton acces…
daadu Dec 5, 2021
baee899
- [wifi_scan] `CanRequestScan` and `CanGetScannedNetworks` enum added…
daadu Dec 5, 2021
eb94c6d
formatting
daadu Dec 5, 2021
689ce89
[wifi_scan] renamed: `requestScan` -> `startScan` and `CanRequestScan…
daadu Dec 5, 2021
88801d0
[wifi_scan] import fix
daadu Dec 5, 2021
fd2f54d
Merge branch 'master' into wifi_scan
daadu Dec 11, 2021
6148d74
[wifi_scan,test] separated `startScan` and `canStartScan` methods
daadu Dec 11, 2021
078f063
[ios] plugin support for iOS added
daadu Dec 11, 2021
c9e08e6
[wifi_scan] breaking it into seperate dart files - removed extension …
daadu Dec 12, 2021
3a29cbe
[wifi_scan] making "deserialization methods" private
daadu Dec 12, 2021
086bdf4
[android,ios] methods scaffolded
daadu Dec 12, 2021
f6b108a
formatting
daadu Dec 12, 2021
bca6e12
removing analysis_options.yaml file - not overriding the one in root
daadu Dec 12, 2021
5204b50
Merge remote-tracking branch 'origin/master' into wifi_scan
daadu Dec 12, 2021
652e759
- [android] implementing some methods - not tested yet
daadu Dec 14, 2021
b94c295
[android] minor fix
daadu Dec 14, 2021
3553043
- [android] minor fix
daadu Dec 14, 2021
7b45737
Merge branch 'master' into wifi_scan
daadu Dec 26, 2021
e10554c
docs: API docs added for all public member
daadu Jan 2, 2022
998aa58
docs: improve API docs
daadu Jan 2, 2022
6fd3081
minor: todo added
daadu Jan 2, 2022
222bd63
example: basic UI added
daadu Jan 2, 2022
d28c51e
- [can,tests] `CanStartScan` and `CanGetScannedNetworks`: added value…
daadu Jan 9, 2022
530905d
renaming
daadu Jan 9, 2022
1c4ff68
- [accesspoint] docs improved for `level`
daadu Jan 9, 2022
af346a1
[example] minor changes
daadu Jan 9, 2022
43b043a
formatting
daadu Jan 9, 2022
8fb2450
Merge branch 'master' of github.com:alternadom/WiFiFlutter into wifi_…
daadu Jan 10, 2022
4c108bd
Merge branch 'wifi_scan' of github.com:alternadom/WiFiFlutter into wi…
daadu Jan 10, 2022
2968707
[android] unregister `wifiScanReceiver` in `onDetachedFromEngine`
daadu Jan 10, 2022
7a3a66c
fix: sending result of `canGetScannedResults` - when asked for loc-perm
daadu Jan 10, 2022
1815cf1
minor
daadu Jan 10, 2022
50594ac
reformatting
daadu Jan 10, 2022
7a29169
[ios] docomment explaining dummy implementation
daadu Jan 11, 2022
437965d
[LICENSE] copied from wifi_iot
daadu Jan 15, 2022
e7da3f3
[README] added - with platform support, usage, resources, issues & fe…
daadu Jan 15, 2022
3e207f9
Merge branch 'master' into wifi_scan
daadu Jan 15, 2022
a9410f7
[README] added doc-link for `WiFiAccessPoint`; minor fix
daadu Jan 15, 2022
fc04201
[README] added link to Android guide on WiFi scan
daadu Jan 15, 2022
e23946c
[README] android - notes on throttling
daadu Jan 15, 2022
e1cbcbc
[readme] ios: clarify "dummy" implementation
daadu Jan 15, 2022
6c47dd4
[readme] ios: improve notes
daadu Jan 15, 2022
5566016
[readme] ios: link to dummy class
daadu Jan 15, 2022
ea58870
[readme] android: added guide link in API column
daadu Jan 15, 2022
3c51442
minor: change description - replace "networks" -> "access points"
daadu Jan 15, 2022
4ea3697
Merge remote-tracking branch 'upstream/wifi_scan' into wifi_scan
daadu Jan 15, 2022
4853131
[readme] using `switch` to handle `can` values
daadu Jan 15, 2022
fe8956c
[readme] added plugin-checklist link
daadu Jan 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions .github/workflows/wifi_scan.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Build wifi_scan example
name: wifi_scan

on:
pull_request:
paths:
- "packages/wifi_scan/**"
- ".github/workflows/wifi_scan.yaml"

env:
PLUGIN_SCOPE: "*wifi_scan*"
PLUGIN_EXAMPLE_SCOPE: "*wifi_scan_example*"

jobs:
android:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: "Checkout repository"
uses: actions/checkout@v2
- name: "Install Flutter"
run: ./.github/workflows/scripts/install-flutter.sh stable
- name: "Install Tools"
run: ./.github/workflows/scripts/install-tools.sh
- name: "Build Example"
run: ./.github/workflows/scripts/build-examples.sh android ./lib/main.dart

ios:
runs-on: macos-latest
timeout-minutes: 30
steps:
- name: "Checkout repository"
uses: actions/checkout@v2
- name: "Install Flutter"
run: ./.github/workflows/scripts/install-flutter.sh stable
- name: "Install Tools"
run: ./.github/workflows/scripts/install-tools.sh
- name: "Build Example"
run: ./.github/workflows/scripts/build-examples.sh ios ./lib/main.dart

# macos:
# runs-on: macos-latest
# timeout-minutes: 30
# steps:
# - name: "Checkout repository"
# uses: actions/checkout@v2
# - name: "Install Flutter"
# run: ./.github/workflows/scripts/install-flutter.sh stable
# - name: "Install Tools"
# run: ./.github/workflows/scripts/install-tools.sh
# - name: "Build Example"
# run: ./.github/workflows/scripts/build-examples.sh macos ./lib/main.dart

# linux:
# runs-on: ubuntu-latest
# timeout-minutes: 30
# steps:
# - name: "Checkout repository"
# uses: actions/checkout@v2
# - name: "Install Flutter"
# run: ./.github/workflows/scripts/install-flutter.sh stable
# - name: "Install Tools"
# run: ./.github/workflows/scripts/install-tools.sh
# - name: "Build Example"
# run: ./.github/workflows/scripts/build-examples.sh linux ./lib/main.dart

# windows:
# runs-on: ubuntu-latest
# timeout-minutes: 30
# steps:
# - name: "Checkout repository"
# uses: actions/checkout@v2
# - name: "Install Flutter"
# run: ./.github/workflows/scripts/install-flutter.sh stable
# - name: "Install Tools"
# run: ./.github/workflows/scripts/install-tools.sh
# - name: "Build Example"
# run: ./.github/workflows/scripts/build-examples.sh windows ./lib/main.dart

# web:
# runs-on: ubuntu-latest
# timeout-minutes: 30
# steps:
# - name: "Checkout repository"
# uses: actions/checkout@v2
# - name: "Install Flutter"
# run: ./.github/workflows/scripts/install-flutter.sh stable
# - name: "Install Tools"
# run: ./.github/workflows/scripts/install-tools.sh
# - name: "Build Example"
# run: ./.github/workflows/scripts/build-examples.sh web ./lib/main.dart
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ Flutter plugin for basic WiFi information and functionalities.
### `wifi_scan`
> [![wifi_scan][scan_workflow_badge]][scan_workflow] [![wifi_scan][scan_pub_badge]][scan_pub] [![pub points][scan_pub_points_badge]][scan_pub_points]

Flutter plugin to scan for WiFi networks.
Flutter plugin to scan for WiFi access points.

[[View Source][scan_code]]

#### Platform Support
| Android | iOS |
| :-----: | :-: |
| | ➖ |
| ✔️ | |

---

Expand Down
7 changes: 7 additions & 0 deletions packages/wifi_scan/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
.dart_tool/

.packages
.pub/

build/
10 changes: 10 additions & 0 deletions packages/wifi_scan/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: 18116933e77adc82f80866c928266a5b4f1ed645
channel: stable

project_type: plugin
3 changes: 3 additions & 0 deletions packages/wifi_scan/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.0.1

* TODO: Describe initial release.
21 changes: 21 additions & 0 deletions packages/wifi_scan/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 AlternaDom

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
144 changes: 144 additions & 0 deletions packages/wifi_scan/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<h3><a href="https://wifi.flutternetwork.dev/" ><img src="https://raw.githubusercontent.com/flutternetwork/WiFiFlutter/master/logo/logo%2Bname_vertical_color.png" alt="WiFiFlutter" height="112"/></a>| <code>wifi_scan</code></h3>

<p>
<a href="https://github.com/flutternetwork/WiFiFlutter/actions/workflows/wifi_scan.yaml">
<img src="https://github.com/flutternetwork/WiFiFlutter/actions/workflows/wifi_scan.yaml/badge.svg" alt="analysis">
</a>
<a href="https://pub.dev/packages/wifi_scan">
<img src="https://img.shields.io/pub/v/wifi_scan?logo=dart" alt="pub.dev">
</a>
<a href="https://pub.dev/packages/wifi_scan/score">
<img src="https://badges.bar/wifi_scan/pub%20points" alt="pub points">
</a>
<a href="https://pub.dev/packages/wifi_scan/score">
<img src="https://badges.bar/wifi_scan/popularity" alt="popularity">
</a>
<a href="https://pub.dev/packages/wifi_scan/score">
<img src="https://badges.bar/wifi_scan/likes" alt="likes">
</a>
</p>

---
This plugin allows Flutter apps to trigger WiFi scan and get scanned results.

> This plugin is part of [WiFiFlutter][wf_home] suite, enabling various WiFi services for Flutter.

## Platform Support

| Platform | Status | Min. Version | API | Notes |
| :------: | :----: |:------------:| :---: |:-----:|
| **Android** | ✔️ | 16 (J) | Scan related APIs in [`WifiManager`][android_WifiManager] *[[Guide][android_guide]]* | For SDK >= 26(O) scans are [throttled][android_throttling]. |
| **iOS** | ✔️ | 9.0 | No API available | Dummy implementation with [sane static returns][ios_dummy]. |

## Usage
The entry point for the plugin is the singleton instance `WiFiScan.instance`.

### Start scan
You can trigger full WiFi scan with `WiFiScan.startScan` API, as shown below:
```dart
// check if platform support and necessary requirements
final can = await WiFiScan.instance.canStartScan(askPermissions: true);
switch(can) {
case CanStartScan.yes:
// start full scan async-ly
final isScanning = await WiFiScan.instance.startScan();
//...
break;
// ... handle other cases of CanStartScan values
}
```

For more details, you can read documentation of [`WiFiScan.startScan`][doc_startScan], [`WiFiScan.canStartScan`][doc_canStartScan] and [`CanStartScan`][doc_enum_CanStartScan].

### Get scanned results
You can get scanned results with `WiFiScan.getScannedResults` API, as shown below:
```dart
// check if platform support and necessary requirements
final can = await WiFiScan.instance.canGetScannedResults(askPermissions: true);
switch(can) {
case CanGetScannedResults.yes:
// get scanned results
final accessPoints = await WiFiScan.instance.getScannedResults();
// ...
break;
// ... handle other cases of CanGetScannedResults values
}
```

> **NOTE:** `getScannedResults` API can be used independently of `startScan` API. This returns the latest available scanned results.

For more details, you can read documentation of [`WiFiScan.getScannedResults`][doc_getScannedResults], `WiFiAccessPoint`[doc_WiFiAccessPoint], [`WiFiScan.canGetScannedResults`][doc_canGetScannedResults] and [`CanGetScannedResults`][doc_enum_CanGetScannedResults].

### Get notified when scanned results available
You can get notified when new scanned results are available, as shown below:
```dart
// initialize accessPoints and subscription
List<WiFiAccessPoint> accessPoints = [];
StreamSubscription<List<WiFiAccessPoint>>? subscription;

void _startListeningToScannedResults(){
// check if platform support and necessary requirements
final can = await WiFiScan.instance.canGetScannedResults(askPermissions: true);
switch(can) {
case CanGetScannedResults.yes:
// listen to onScannedResultsAvailable stream
subscription = WiFiScan.instance.onScannedResultsAvailable.listen((results) {
// update accessPoints
setState(() => accessPoints = results);
});
// ...
break;
// ... handle other cases of CanGetScannedResults values
}
}

// make sure to cancel subscription after you are done
@override
dispose() {
super.dispose();
subscription?.cancel();
}
```

Additionally, `WiFiScan.onScannedResultsAvailable` API can also be used with Flutter's [`StreamBuilder`][flutter_StreamBuilder] widget.

> **NOTE:** `onScannedResultsAvailable` API can be used independently of `startScan` API. The notification can also be result of a full scan performed by platform or other app.

For more details, you can read documentation of [`WiFiScan.onScannedResultsAvailable`][doc_onScannedResultsAvailable], `WiFiAccessPoint`[doc_WiFiAccessPoint], [`WiFiScan.canGetScannedResults`][doc_canGetScannedResults] and [`CanGetScannedResults`][doc_enum_CanGetScannedResults].

## Resources
- 📖[API docs][docs]
- 💻[Example app][example]

## Issues and feedback

Please file WiFiFlutter specific issues, bugs, or feature requests in our [issue tracker][wf_issue].

To contribute a change to this plugin, please review plugin [checklist for 1.0][checklist], our [contribution guide][wf_contrib] and open a [pull request][wf_pull].

<!-- links -->
[wf_home]: https://wifi.flutternetwork.dev/
[wf_issue]: https://github.com/flutternetwork/WiFiFlutter/issues/new
[wf_contrib]: https://github.com/flutternetwork/WiFiFlutter/blob/master/CONTRIBUTING.md
[wf_pull]: https://github.com/flutternetwork/WiFiFlutter/pulls

[checklist]: https://github.com/flutternetwork/WiFiFlutter/issues/188
[docs]: https://pub.dev/documentation/wifi_scan/latest/wifi_scan/wifi_scan-library.html
[example]: https://github.com/flutternetwork/WiFiFlutter/tree/master/packages/wifi_scan/example

[doc_startScan]: https://pub.dev/documentation/wifi_scan/latest/wifi_scan/WiFiScan/startScan.html
[doc_canStartScan]: https://pub.dev/documentation/wifi_scan/latest/wifi_scan/WiFiScan/canStartScan.html
[doc_enum_CanStartScan]: https://pub.dev/documentation/wifi_scan/latest/wifi_scan/CanStartScan.html
[doc_getScannedResults]: https://pub.dev/documentation/wifi_scan/latest/wifi_scan/WiFiScan/getScannedResults.html
[doc_WiFiAccessPoint]: https://pub.dev/documentation/wifi_scan/latest/wifi_scan/WiFiAccessPoint.html
[doc_canGetScannedResults]: https://pub.dev/documentation/wifi_scan/latest/wifi_scan/WiFiScan/canGetScannedResults.html
[doc_enum_CanGetScannedResults]: https://pub.dev/documentation/wifi_scan/latest/wifi_scan/CanGetScannedResults.html
[doc_onScannedResultsAvailable]: https://pub.dev/documentation/wifi_scan/latest/wifi_scan/WiFiScan/onScannedResultsAvailable.html

[flutter_StreamBuilder]: https://api.flutter.dev/flutter/widgets/StreamBuilder-class.html

[android_guide]: https://developer.android.com/guide/topics/connectivity/wifi-scan
[android_throttling]: https://developer.android.com/guide/topics/connectivity/wifi-scan#wifi-scan-throttling
[android_WifiManager]: https://developer.android.com/reference/android/net/wifi/WifiManager

[ios_dummy]: https://github.com/flutternetwork/WiFiFlutter/blob/master/packages/wifi_scan/ios/Classes/SwiftWifiScanPlugin.swift
8 changes: 8 additions & 0 deletions packages/wifi_scan/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
50 changes: 50 additions & 0 deletions packages/wifi_scan/android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
group 'dev.flutternetwork.wifi.wifi_scan'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

rootProject.allprojects {
repositories {
google()
mavenCentral()
}
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 30

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

defaultConfig {
minSdkVersion 16
}
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
3 changes: 3 additions & 0 deletions packages/wifi_scan/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
1 change: 1 addition & 0 deletions packages/wifi_scan/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'wifi_scan'
10 changes: 10 additions & 0 deletions packages/wifi_scan/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dev.flutternetwork.wifi.wifi_scan">
<!-- required for: `WifiManager.getScanResult` -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<!-- required for: `WifiManager.startScan` -->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<!-- required for: `WifiManager.getScanResult`, `WifiManager.startScan` -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
</manifest>
Loading