Skip to content

Commit 4f7eb55

Browse files
bparrishMinesEgor
authored and
Egor
committed
[wifi_info_flutter_plugin_interface] implement wifi platform interface (flutter#3134)
1 parent 9a89e78 commit 4f7eb55

File tree

9 files changed

+299
-95
lines changed

9 files changed

+299
-95
lines changed

packages/wifi_info_flutter/wifi_info_flutter/example/test/widget_test.dart

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
## [0.0.1] - TODO: Add release date.
1+
## 0.0.1
22

3-
* TODO: Describe initial release.
3+
* Initial release of package. Includes support for retrieving wifi name, wifi BSSID, wifi ip address
4+
and requesting location service authorization.
Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
# wifi_info_flutter_platform_interface
22

3-
A new Flutter package project.
3+
A common platform interface for the [`wifi_info_flutter`][1] plugin.
44

5-
## Getting Started
5+
This interface allows platform-specific implementations of the `wifi_info_flutter`
6+
plugin, as well as the plugin itself, to ensure they are supporting the
7+
same interface.
68

7-
This project is a starting point for a Dart
8-
[package](https://flutter.dev/developing-packages/),
9-
a library module containing code that can be shared easily across
10-
multiple Flutter or Dart projects.
9+
# Usage
1110

12-
For help getting started with Flutter, view our
13-
[online documentation](https://flutter.dev/docs), which offers tutorials,
14-
samples, guidance on mobile development, and a full API reference.
11+
To implement a new platform-specific implementation of `wifi_info_flutter`, extend
12+
[`WifiInfoFlutterPlatform`][2] with an implementation that performs the
13+
platform-specific behavior, and when you register your plugin, set the default
14+
`WifiInfoFlutterPlatform` by calling
15+
`WifiInfoFlutterPlatform.instance = MyPlatformWifiInfoFlutter()`.
16+
17+
# Note on breaking changes
18+
19+
Strongly prefer non-breaking changes (such as adding a method to the interface)
20+
over breaking changes for this package.
21+
22+
See https://flutter.dev/go/platform-interface-breaking-changes for a discussion
23+
on why a less-clean interface is preferable to a breaking change.
24+
25+
[1]: ../
26+
[2]: lib/wifi_info_flutter_platform_interface.dart
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2020 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
/// The status of the location service authorization.
6+
enum LocationAuthorizationStatus {
7+
/// The authorization of the location service is not determined.
8+
notDetermined,
9+
10+
/// This app is not authorized to use location.
11+
restricted,
12+
13+
/// User explicitly denied the location service.
14+
denied,
15+
16+
/// User authorized the app to access the location at any time.
17+
authorizedAlways,
18+
19+
/// User authorized the app to access the location when the app is visible to them.
20+
authorizedWhenInUse,
21+
22+
/// Status unknown.
23+
unknown
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2020 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:async';
6+
7+
import 'package:flutter/foundation.dart';
8+
import 'package:flutter/services.dart';
9+
10+
import '../wifi_info_flutter_platform_interface.dart';
11+
12+
/// An implementation of [WifiInfoFlutterPlatform] that uses method channels.
13+
class MethodChannelWifiInfoFlutter extends WifiInfoFlutterPlatform {
14+
/// The method channel used to interact with the native platform.
15+
@visibleForTesting
16+
MethodChannel methodChannel =
17+
MethodChannel('plugins.flutter.io/wifi_info_flutter');
18+
19+
@override
20+
Future<String> getWifiName() async {
21+
return methodChannel.invokeMethod<String>('wifiName');
22+
}
23+
24+
@override
25+
Future<String> getWifiBSSID() {
26+
return methodChannel.invokeMethod<String>('wifiBSSID');
27+
}
28+
29+
@override
30+
Future<String> getWifiIP() {
31+
return methodChannel.invokeMethod<String>('wifiIPAddress');
32+
}
33+
34+
@override
35+
Future<LocationAuthorizationStatus> requestLocationServiceAuthorization({
36+
bool requestAlwaysLocationUsage = false,
37+
}) {
38+
return methodChannel.invokeMethod<String>(
39+
'requestLocationServiceAuthorization', <bool>[
40+
requestAlwaysLocationUsage
41+
]).then(_parseLocationAuthorizationStatus);
42+
}
43+
44+
@override
45+
Future<LocationAuthorizationStatus> getLocationServiceAuthorization() {
46+
return methodChannel
47+
.invokeMethod<String>('getLocationServiceAuthorization')
48+
.then(_parseLocationAuthorizationStatus);
49+
}
50+
}
51+
52+
/// Convert a String to a LocationAuthorizationStatus value.
53+
LocationAuthorizationStatus _parseLocationAuthorizationStatus(String result) {
54+
return LocationAuthorizationStatus.values.firstWhere(
55+
(LocationAuthorizationStatus status) => result == describeEnum(status),
56+
orElse: () => LocationAuthorizationStatus.unknown,
57+
);
58+
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,74 @@
1-
library wifi_info_flutter_platform_interface;
1+
// Copyright 2020 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
24

3-
/// A Calculator.
4-
class Calculator {
5-
/// Returns [value] plus 1.
6-
int addOne(int value) => value + 1;
5+
import 'dart:async';
6+
7+
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
8+
9+
import 'src/enums.dart';
10+
import 'src/method_channel_wifi_info_flutter.dart';
11+
12+
export 'src/enums.dart';
13+
14+
/// The interface that implementations of wifi_info_flutter must implement.
15+
///
16+
/// Platform implementations should extend this class rather than implement it
17+
/// as `wifi_info_flutter` does not consider newly added methods to be breaking
18+
/// changes. Extending this class (using `extends`) ensures that the subclass
19+
/// will get the default implementation, while platform implementations that
20+
/// `implements` this interface will be broken by newly added
21+
/// [ConnectivityPlatform] methods.
22+
abstract class WifiInfoFlutterPlatform extends PlatformInterface {
23+
/// Constructs a WifiInfoFlutterPlatform.
24+
WifiInfoFlutterPlatform() : super(token: _token);
25+
26+
static final Object _token = Object();
27+
28+
static WifiInfoFlutterPlatform _instance = MethodChannelWifiInfoFlutter();
29+
30+
/// The default instance of [WifiInfoFlutterPlatform] to use.
31+
///
32+
/// Defaults to [MethodChannelWifiInfoFlutter].
33+
static WifiInfoFlutterPlatform get instance => _instance;
34+
35+
/// Set the default instance of [WifiInfoFlutterPlatform] to use.
36+
///
37+
/// Platform-specific plugins should set this with their own platform-specific
38+
/// class that extends [WifiInfoFlutterPlatform] when they register
39+
/// themselves.
40+
static set instance(WifiInfoFlutterPlatform instance) {
41+
PlatformInterface.verifyToken(instance, _token);
42+
_instance = instance;
43+
}
44+
45+
/// Obtains the wifi name (SSID) of the connected network
46+
Future<String> getWifiName() {
47+
throw UnimplementedError('getWifiName() has not been implemented.');
48+
}
49+
50+
/// Obtains the wifi BSSID of the connected network.
51+
Future<String> getWifiBSSID() {
52+
throw UnimplementedError('getWifiBSSID() has not been implemented.');
53+
}
54+
55+
/// Obtains the IP address of the connected wifi network
56+
Future<String> getWifiIP() {
57+
throw UnimplementedError('getWifiIP() has not been implemented.');
58+
}
59+
60+
/// Request to authorize the location service (Only on iOS).
61+
Future<LocationAuthorizationStatus> requestLocationServiceAuthorization(
62+
{bool requestAlwaysLocationUsage = false}) {
63+
throw UnimplementedError(
64+
'requestLocationServiceAuthorization() has not been implemented.',
65+
);
66+
}
67+
68+
/// Get the current location service authorization (Only on iOS).
69+
Future<LocationAuthorizationStatus> getLocationServiceAuthorization() {
70+
throw UnimplementedError(
71+
'getLocationServiceAuthorization() has not been implemented.',
72+
);
73+
}
774
}
Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,21 @@
11
name: wifi_info_flutter_platform_interface
2-
description: A new Flutter package project.
3-
version: 0.0.1
2+
description: A common platform interface for the wifi_info_flutter plugin.
3+
version: 1.0.0
4+
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
5+
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
46
homepage: https://github.com/flutter/plugins/tree/master/packages/wifi_info_flutter/wifi_info_flutter_platform_interface
7+
publish_to: none
58

69
environment:
710
sdk: ">=2.7.0 <3.0.0"
811
flutter: ">=1.17.0 <2.0.0"
912

1013
dependencies:
14+
plugin_platform_interface: ^1.0.3
1115
flutter:
1216
sdk: flutter
1317

1418
dev_dependencies:
19+
pedantic: ^1.9.2
1520
flutter_test:
1621
sdk: flutter
17-
18-
# For information on the generic Dart part of this file, see the
19-
# following page: https://dart.dev/tools/pub/pubspec
20-
21-
# The following section is specific to Flutter.
22-
flutter:
23-
24-
# To add assets to your package, add an assets section, like this:
25-
# assets:
26-
# - images/a_dot_burr.jpeg
27-
# - images/a_dot_ham.jpeg
28-
#
29-
# For details regarding assets in packages, see
30-
# https://flutter.dev/assets-and-images/#from-packages
31-
#
32-
# An image asset can refer to one or more resolution-specific "variants", see
33-
# https://flutter.dev/assets-and-images/#resolution-aware.
34-
35-
# To add custom fonts to your package, add a fonts section here,
36-
# in this "flutter" section. Each entry in this list should have a
37-
# "family" key with the font family name, and a "fonts" key with a
38-
# list giving the asset and other descriptors for the font. For
39-
# example:
40-
# fonts:
41-
# - family: Schyler
42-
# fonts:
43-
# - asset: fonts/Schyler-Regular.ttf
44-
# - asset: fonts/Schyler-Italic.ttf
45-
# style: italic
46-
# - family: Trajan Pro
47-
# fonts:
48-
# - asset: fonts/TrajanPro.ttf
49-
# - asset: fonts/TrajanPro_Bold.ttf
50-
# weight: 700
51-
#
52-
# For details regarding fonts in packages, see
53-
# https://flutter.dev/custom-fonts/#from-packages

0 commit comments

Comments
 (0)