Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[wifi_info_flutter_plugin_interface] implement wifi platform interface #3134

Merged
merged 5 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
## [0.0.1] - TODO: Add release date.
## 0.0.1

* TODO: Describe initial release.
* Initial release of package. Includes support for retrieving wifi name, wifi BSSID, wifi ip address
and requesting location service authorization.
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
# wifi_info_flutter_platform_interface

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

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

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

For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
To implement a new platform-specific implementation of `wifi_info_flutter`, extend
[`WifiInfoFlutterPlatform`][2] with an implementation that performs the
platform-specific behavior, and when you register your plugin, set the default
`WifiInfoFlutterPlatform` by calling
`WifiInfoFlutterPlatform.instance = MyPlatformWifiInfoFlutter()`.

# Note on breaking changes

Strongly prefer non-breaking changes (such as adding a method to the interface)
over breaking changes for this package.

See https://flutter.dev/go/platform-interface-breaking-changes for a discussion
on why a less-clean interface is preferable to a breaking change.

[1]: ../
[2]: lib/wifi_info_flutter_platform_interface.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/// The status of the location service authorization.
enum LocationAuthorizationStatus {
/// The authorization of the location service is not determined.
notDetermined,

/// This app is not authorized to use location.
restricted,

/// User explicitly denied the location service.
denied,

/// User authorized the app to access the location at any time.
authorizedAlways,

/// User authorized the app to access the location when the app is visible to them.
authorizedWhenInUse,

/// Status unknown.
unknown
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';

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

import '../wifi_info_flutter_platform_interface.dart';

/// An implementation of [WifiInfoFlutterPlatform] that uses method channels.
class MethodChannelWifiInfoFlutter extends WifiInfoFlutterPlatform {
/// The method channel used to interact with the native platform.
@visibleForTesting
MethodChannel methodChannel =
MethodChannel('plugins.flutter.io/wifi_info_flutter');

@override
Future<String> getWifiName() async {
return methodChannel.invokeMethod<String>('wifiName');
}

@override
Future<String> getWifiBSSID() {
return methodChannel.invokeMethod<String>('wifiBSSID');
}

@override
Future<String> getWifiIP() {
return methodChannel.invokeMethod<String>('wifiIPAddress');
}

@override
Future<LocationAuthorizationStatus> requestLocationServiceAuthorization({
bool requestAlwaysLocationUsage = false,
}) {
return methodChannel.invokeMethod<String>(
'requestLocationServiceAuthorization', <bool>[
requestAlwaysLocationUsage
]).then(_parseLocationAuthorizationStatus);
}

@override
Future<LocationAuthorizationStatus> getLocationServiceAuthorization() {
return methodChannel
.invokeMethod<String>('getLocationServiceAuthorization')
.then(_parseLocationAuthorizationStatus);
}
}

/// Convert a String to a LocationAuthorizationStatus value.
LocationAuthorizationStatus _parseLocationAuthorizationStatus(String result) {
return LocationAuthorizationStatus.values.firstWhere(
(LocationAuthorizationStatus status) => result == describeEnum(status),
orElse: () => LocationAuthorizationStatus.unknown,
);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,74 @@
library wifi_info_flutter_platform_interface;
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/// A Calculator.
class Calculator {
/// Returns [value] plus 1.
int addOne(int value) => value + 1;
import 'dart:async';

import 'package:plugin_platform_interface/plugin_platform_interface.dart';

import 'src/enums.dart';
import 'src/method_channel_wifi_info_flutter.dart';

export 'src/enums.dart';

/// The interface that implementations of wifi_info_flutter must implement.
///
/// Platform implementations should extend this class rather than implement it
/// as `wifi_info_flutter` does not consider newly added methods to be breaking
/// changes. Extending this class (using `extends`) ensures that the subclass
/// will get the default implementation, while platform implementations that
/// `implements` this interface will be broken by newly added
/// [ConnectivityPlatform] methods.
abstract class WifiInfoFlutterPlatform extends PlatformInterface {
/// Constructs a WifiInfoFlutterPlatform.
WifiInfoFlutterPlatform() : super(token: _token);

static final Object _token = Object();

static WifiInfoFlutterPlatform _instance = MethodChannelWifiInfoFlutter();

/// The default instance of [WifiInfoFlutterPlatform] to use.
///
/// Defaults to [MethodChannelWifiInfoFlutter].
static WifiInfoFlutterPlatform get instance => _instance;

/// Set the default instance of [WifiInfoFlutterPlatform] to use.
///
/// Platform-specific plugins should set this with their own platform-specific
/// class that extends [WifiInfoFlutterPlatform] when they register
/// themselves.
static set instance(WifiInfoFlutterPlatform instance) {
PlatformInterface.verifyToken(instance, _token);
_instance = instance;
}

/// Obtains the wifi name (SSID) of the connected network
Future<String> getWifiName() {
throw UnimplementedError('getWifiName() has not been implemented.');
}

/// Obtains the wifi BSSID of the connected network.
Future<String> getWifiBSSID() {
throw UnimplementedError('getWifiBSSID() has not been implemented.');
}

/// Obtains the IP address of the connected wifi network
Future<String> getWifiIP() {
throw UnimplementedError('getWifiIP() has not been implemented.');
}

/// Request to authorize the location service (Only on iOS).
Future<LocationAuthorizationStatus> requestLocationServiceAuthorization(
{bool requestAlwaysLocationUsage = false}) {
throw UnimplementedError(
'requestLocationServiceAuthorization() has not been implemented.',
);
}

/// Get the current location service authorization (Only on iOS).
Future<LocationAuthorizationStatus> getLocationServiceAuthorization() {
throw UnimplementedError(
'getLocationServiceAuthorization() has not been implemented.',
);
}
}
Original file line number Diff line number Diff line change
@@ -1,53 +1,21 @@
name: wifi_info_flutter_platform_interface
description: A new Flutter package project.
version: 0.0.1
description: A common platform interface for the wifi_info_flutter plugin.
version: 1.0.0
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
homepage: https://github.com/flutter/plugins/tree/master/packages/wifi_info_flutter/wifi_info_flutter_platform_interface
publish_to: none

environment:
sdk: ">=2.7.0 <3.0.0"
flutter: ">=1.17.0 <2.0.0"

dependencies:
plugin_platform_interface: ^1.0.3
flutter:
sdk: flutter

dev_dependencies:
pedantic: ^1.9.2
flutter_test:
sdk: flutter

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

# To add assets to your package, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#
# For details regarding assets in packages, see
# https://flutter.dev/assets-and-images/#from-packages
#
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.

# To add custom fonts to your package, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts in packages, see
# https://flutter.dev/custom-fonts/#from-packages
Loading