You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import'dart:async';
import'dart:developer'as developer;
import'dart:io';
import'package:flutter/foundation.dart';
import'package:flutter/material.dart';
import'package:flutter/services.dart';
import'package:network_info_plus/network_info_plus.dart';
import'package:permission_handler/permission_handler.dart';
// Sets a platform override for desktop to avoid exceptions. See// https://flutter.dev/desktop#target-platform-override for more info.void_enablePlatformOverrideForDesktop() {
if (!kIsWeb && (Platform.isWindows ||Platform.isLinux)) {
debugDefaultTargetPlatformOverride =TargetPlatform.fuchsia;
}
}
voidmain() {
_enablePlatformOverrideForDesktop();
runApp(constMyApp());
}
classMyAppextendsStatelessWidget {
constMyApp({super.key});
// This widget is the root of your application.@overrideWidgetbuild(BuildContext context) {
returnMaterialApp(
title:'Flutter Demo',
theme:ThemeData(
useMaterial3:true,
colorSchemeSeed:constColor(0x9f4376f8),
),
home:constMyHomePage(title:'Flutter Demo Home Page'),
);
}
}
classMyHomePageextendsStatefulWidget {
constMyHomePage({super.key, this.title});
finalString? title;
@overrideState<MyHomePage> createState() =>_MyHomePageState();
}
class_MyHomePageStateextendsState<MyHomePage> {
String _connectionStatus ='Unknown';
finalNetworkInfo _networkInfo =NetworkInfo();
@overridevoidinitState() {
super.initState();
_initNetworkInfo();
}
@overrideWidgetbuild(BuildContext context) {
returnScaffold(
appBar:AppBar(
title:constText('NetworkInfoPlus example'),
elevation:4,
),
body:Center(
child:Column(
mainAxisSize:MainAxisSize.min,
children: [
constText(
'Network info',
style:TextStyle(
fontSize:16,
fontWeight:FontWeight.bold,
),
),
constSizedBox(height:16),
Text(_connectionStatus),
],
)),
);
}
Future<void> _initNetworkInfo() async {
String? wifiName,
wifiBSSID,
wifiIPv4,
wifiIPv6,
wifiGatewayIP,
wifiBroadcast,
wifiSubmask;
try {
if (!kIsWeb && (Platform.isAndroid ||Platform.isIOS)) {
// Request permissions as recommended by the plugin documentation:// https://github.com/fluttercommunity/plus_plugins/tree/main/packages/network_info_plus/network_info_plusif (awaitPermission.locationWhenInUse.request().isGranted) {
wifiName =await _networkInfo.getWifiName();
} else {
wifiName ='Unauthorized to get Wifi Name';
}
} else {
wifiName =await _networkInfo.getWifiName();
}
} onPlatformExceptioncatch (e) {
developer.log('Failed to get Wifi Name', error: e);
wifiName ='Failed to get Wifi Name';
}
try {
if (!kIsWeb && (Platform.isAndroid ||Platform.isIOS)) {
// Request permissions as recommended by the plugin documentation:// https://github.com/fluttercommunity/plus_plugins/tree/main/packages/network_info_plus/network_info_plusif (awaitPermission.locationWhenInUse.request().isGranted) {
wifiBSSID =await _networkInfo.getWifiBSSID();
} else {
wifiBSSID ='Unauthorized to get Wifi BSSID';
}
} else {
wifiName =await _networkInfo.getWifiName();
}
} onPlatformExceptioncatch (e) {
developer.log('Failed to get Wifi BSSID', error: e);
wifiBSSID ='Failed to get Wifi BSSID';
}
try {
wifiIPv4 =await _networkInfo.getWifiIP();
} onPlatformExceptioncatch (e) {
developer.log('Failed to get Wifi IPv4', error: e);
wifiIPv4 ='Failed to get Wifi IPv4';
}
try {
wifiIPv6 =await _networkInfo.getWifiIPv6();
} onPlatformExceptioncatch (e) {
developer.log('Failed to get Wifi IPv6', error: e);
wifiIPv6 ='Failed to get Wifi IPv6';
}
try {
wifiSubmask =await _networkInfo.getWifiSubmask();
} onPlatformExceptioncatch (e) {
developer.log('Failed to get Wifi submask address', error: e);
wifiSubmask ='Failed to get Wifi submask address';
}
try {
wifiBroadcast =await _networkInfo.getWifiBroadcast();
} onPlatformExceptioncatch (e) {
developer.log('Failed to get Wifi broadcast', error: e);
wifiBroadcast ='Failed to get Wifi broadcast';
}
try {
wifiGatewayIP =await _networkInfo.getWifiGatewayIP();
} onPlatformExceptioncatch (e) {
developer.log('Failed to get Wifi gateway address', error: e);
wifiGatewayIP ='Failed to get Wifi gateway address';
}
setState(() {
_connectionStatus ='Wifi Name: $wifiName\n''Wifi BSSID: $wifiBSSID\n''Wifi IPv4: $wifiIPv4\n''Wifi IPv6: $wifiIPv6\n''Wifi Broadcast: $wifiBroadcast\n''Wifi Gateway: $wifiGatewayIP\n''Wifi Submask: $wifiSubmask\n';
});
}
}
Logs
http://127.0.0.1:9100?uri=http://127.0.0.1:57153/-kg
bKNFv1EY=/
[+1429 ms] Checking for available port on
io.flutter.plugins.networkInfoExample.alfaTest._dart
VmService._tcp.local
[ +118 ms] Checking for available port on
io.flutter.plugins.networkInfoExample.alfaTest._dart
VmService._tcp.local
[ +423 ms] Checking for available port on
io.flutter.plugins.networkInfoExample.alfaTest
(2)._dartVmService._tcp.local
[+1000 ms] Checking for available port on
io.flutter.plugins.networkInfoExample.alfaTest
(2)._dartVmService._tcp.local
[ +108 ms] Checking for available port on
io.flutter.plugins.networkInfoExample.alfaTest
(2)._dartVmService._tcp.local
[+1892 ms] Checking for available port on
io.flutter.plugins.networkInfoExample.alfaTest
(2)._dartVmService._tcp.local
[ +53 ms] Checking for available port on
io.flutter.plugins.networkInfoExample.alfaTest
(2)._dartVmService._tcp.local
[ +46 ms] Checking for available port on
io.flutter.plugins.networkInfoExample.alfaTest._dart
VmService._tcp.local
[ +56 ms] Checking for available port on
io.flutter.plugins.networkInfoExample.alfaTest._dart
VmService._tcp.local
[+3842 ms] Checking for available port on
io.flutter.plugins.networkInfoExample.alfaTest
(2)._dartVmService._tcp.local
[ +46 ms] Checking for available port on
io.flutter.plugins.networkInfoExample.alfaTest
(2)._dartVmService._tcp.local
Flutter Doctor
[!] Flutter (Channel stable, 3.22.4-0.0.pre.1, on
macOS 14.5 23F79 darwin-arm64, locale
zh-Hant-TW)
! Upstream repository unknown source is not a
standard remote.
Set environment variable "FLUTTER_GIT_URL" to
unknown source to dismiss this error.
[✓] Android toolchain - develop for Android devices
(Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
[✗] Chrome - develop for the web (Cannot find Chrome
executable at /Applications/Google
Chrome.app/Contents/MacOS/Google Chrome)
! Cannot find Chrome. Try setting
CHROME_EXECUTABLE to a Chrome executable.
[✓] Android Studio (version 2023.3)
[✓] VS Code (version 1.92.2)
[✓] Connected device (3 available)
! Error: Browsing on the local area network for
Alvin的iPad. Ensure the device is unlocked and
attached with a cable or associated with the
same local area network as this Mac.
The device must be opted into Developer Mode
to connect wirelessly. (code -27)
[✓] Network resources
Checklist before submitting a bug
I searched issues in this repository and couldn't find such bug/problem
I Google'd a solution and I couldn't find it
I searched on StackOverflow for a solution and I couldn't find it
I read the README.md file of the plugin
I'm using the latest version of the plugin
All dependencies are up to date with flutter pub upgrade
I did a flutter clean
I tried running the example project
The text was updated successfully, but these errors were encountered:
Your screenshot does not correspond to what you say in the subject line.
If Permission.locationWhenInUse.request().isGranted is false, the app will display Unauthorized to get Wifi Name which is what you see in the screenshot.
Thank you for the clarification.
Sorry for the confusion in my previous message. I just want to confirm that the sample project is expected to display “Unauthorized to get Wifi Name” when Permission.locationWhenInUse.request().isGranted is false. Is that correct?
I understand that the sample project primarily demonstrates how to use the library, so handling permission requests is outside its scope. I’m just making sure I understand the intended behavior.
Platform
iPhone 13 Mini running iOS 17.5.1
Plugin
network_info_plus
Version
4.0.1
Flutter SDK
3.22.4
Steps to reproduce
Code Sample
Logs
Flutter Doctor
Checklist before submitting a bug
flutter pub upgrade
flutter clean
The text was updated successfully, but these errors were encountered: