Skip to content

Commit

Permalink
refactor: preserve "WiFiScan" original package name (with uppercased f)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alystrasz committed Feb 27, 2024
1 parent 08a90fc commit ec396cd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
10 changes: 5 additions & 5 deletions packages/wifi_scan/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class _MyAppState extends State<MyApp> {
// check if "can" startScan
if (shouldCheckCan) {
// check if can-startScan
final can = await WifiScan.instance.canStartScan();
final can = await WiFiScan.instance.canStartScan();
// if can-not, then show error
if (can != CanStartScan.yes) {
if (mounted) kShowSnackBar(context, "Cannot start scan: $can");
Expand All @@ -37,7 +37,7 @@ class _MyAppState extends State<MyApp> {
}

// call startScan API
final result = await WifiScan.instance.startScan();
final result = await WiFiScan.instance.startScan();
if (mounted) kShowSnackBar(context, "startScan: $result");
// reset access points.
setState(() => accessPoints = <WiFiAccessPoint>[]);
Expand All @@ -46,7 +46,7 @@ class _MyAppState extends State<MyApp> {
Future<bool> _canGetScannedResults(BuildContext context) async {
if (shouldCheckCan) {
// check if can-getScannedResults
final can = await WifiScan.instance.canGetScannedResults();
final can = await WiFiScan.instance.canGetScannedResults();
// if can-not, then show error
if (can != CanGetScannedResults.yes) {
if (mounted) kShowSnackBar(context, "Cannot get scanned results: $can");
Expand All @@ -60,14 +60,14 @@ class _MyAppState extends State<MyApp> {
Future<void> _getScannedResults(BuildContext context) async {
if (await _canGetScannedResults(context)) {
// get scanned results
final results = await WifiScan.instance.getScannedResults();
final results = await WiFiScan.instance.getScannedResults();
setState(() => accessPoints = results);
}
}

Future<void> _startListeningToScanResults(BuildContext context) async {
if (await _canGetScannedResults(context)) {
subscription = WifiScan.instance.onScannedResultsAvailable
subscription = WiFiScan.instance.onScannedResultsAvailable
.listen((result) => setState(() => accessPoints = result));
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/wifi_scan/lib/wifi_scan_method_channel.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/services.dart';
import 'package:wifi_scan/wifi_scan.dart';

class MethodChannelWifiScan extends WifiScan {
class MethodChannelWifiScan extends WiFiScan {
final _channel = const MethodChannel('wifi_scan');
final _scannedResultsAvailableChannel =
const EventChannel('wifi_scan/onScannedResultsAvailable');
Expand Down
14 changes: 7 additions & 7 deletions packages/wifi_scan/lib/wifi_scan_platform_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ import 'package:wifi_scan/src/accesspoint.dart';
import 'package:wifi_scan/src/can.dart';
import 'package:wifi_scan/wifi_scan_method_channel.dart';

abstract class WifiScan extends PlatformInterface {
WifiScan() : super(token: _token);
abstract class WiFiScan extends PlatformInterface {
WiFiScan() : super(token: _token);
static final Object _token = Object();

static WifiScan _instance = MethodChannelWifiScan();
static WiFiScan _instance = MethodChannelWifiScan();

/// The default instance of [WifiScan] to use.
/// The default instance of [WiFiScan] to use.
///
/// Defaults to [MethodChannelWifiScan].
static WifiScan get instance => _instance;
static WiFiScan get instance => _instance;

/// Platform-specific plugins should set this with their own platform-specific
/// class that extends [WifiScan] when they register themselves.
/// class that extends [WiFiScan] when they register themselves.
// TODO(amirh): Extract common platform interface logic.
// https://github.com/flutter/flutter/issues/43368
static set instance(WifiScan instance) {
static set instance(WiFiScan instance) {
PlatformInterface.verifyToken(instance, _token);
_instance = instance;
}
Expand Down
12 changes: 6 additions & 6 deletions packages/wifi_scan/test/wifi_scan_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ void main() {
];
for (int i = 0; i < canCodes.length; i++) {
mockHandlers["canStartScan"] = (_) => canCodes[i];
expect(await WifiScan.instance.canStartScan(), enumValues[i]);
expect(await WiFiScan.instance.canStartScan(), enumValues[i]);
}

// -ve test
final badCanCodes = [null, -1, 6, 7];
for (int i = 0; i < badCanCodes.length; i++) {
mockHandlers["canStartScan"] = (_) => badCanCodes[i];
expect(() async => await WifiScan.instance.canStartScan(),
expect(() async => await WiFiScan.instance.canStartScan(),
throwsUnsupportedError);
}
});

test('startScan', () async {
mockHandlers["startScan"] = (_) => true;
expect(await WifiScan.instance.startScan(), true);
expect(await WiFiScan.instance.startScan(), true);
});

test("canGetScannedResults", () async {
Expand All @@ -62,14 +62,14 @@ void main() {
];
for (int i = 0; i < canCodes.length; i++) {
mockHandlers["canGetScannedResults"] = (_) => canCodes[i];
expect(await WifiScan.instance.canGetScannedResults(), enumValues[i]);
expect(await WiFiScan.instance.canGetScannedResults(), enumValues[i]);
}

// -ve test
final badCanCodes = [null, -1, 6, 7];
for (int i = 0; i < badCanCodes.length; i++) {
mockHandlers["canGetScannedResults"] = (_) => badCanCodes[i];
expect(() async => await WifiScan.instance.canGetScannedResults(),
expect(() async => await WiFiScan.instance.canGetScannedResults(),
throwsUnsupportedError);
}
});
Expand All @@ -93,7 +93,7 @@ void main() {
"is80211mcResponder": null,
}
];
final scannedNetworks = await WifiScan.instance.getScannedResults();
final scannedNetworks = await WiFiScan.instance.getScannedResults();
expect(scannedNetworks.length, 1);
});

Expand Down

0 comments on commit ec396cd

Please sign in to comment.