diff --git a/packages/network_info_plus/network_info_plus/example/windows/CMakeLists.txt b/packages/network_info_plus/network_info_plus/example/windows/CMakeLists.txt index abf90408ef..790ed4d475 100644 --- a/packages/network_info_plus/network_info_plus/example/windows/CMakeLists.txt +++ b/packages/network_info_plus/network_info_plus/example/windows/CMakeLists.txt @@ -29,6 +29,11 @@ set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") # Use Unicode for all projects. add_definitions(-DUNICODE -D_UNICODE) +# Newer MSVC (VS 2026) turns the deprecation of into a +# hard error. permission_handler_windows still uses it, so silence it for all +# targets (including plugins) until that package is updated. +add_definitions(-D_SILENCE_EXPERIMENTAL_COROUTINE_DEPRECATION_WARNINGS) + # Compilation settings that should be applied to most targets. function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_17) diff --git a/packages/network_info_plus/network_info_plus/lib/src/network_info_plus_linux.dart b/packages/network_info_plus/network_info_plus/lib/src/network_info_plus_linux.dart index 3442674a8b..f77ed922bc 100644 --- a/packages/network_info_plus/network_info_plus/lib/src/network_info_plus_linux.dart +++ b/packages/network_info_plus/network_info_plus/lib/src/network_info_plus_linux.dart @@ -96,14 +96,16 @@ class NetworkInfoPlusLinuxPlugin extends NetworkInfoPlatform { } String? _getSubnetMask(List>? data) { - final prefix = data?.firstOrNull?['prefix'] as int; + final prefix = data?.firstOrNull?['prefix'] as int?; + if (prefix == null) return null; final mask = (0xffffffff << (32 - prefix)) & 0xffffffff; return mask.toIpString(); } String? _getBroadcast(List>? data) { - final ip = _getIpAddress(data)?.toIpInt() ?? 0; - final mask = _getSubnetMask(data)?.toIpInt() ?? 0; + final ip = _getIpAddress(data)?.toIpInt(); + final mask = _getSubnetMask(data)?.toIpInt(); + if (ip == null || mask == null) return null; return (ip | (mask ^ 0xffffffff)).toIpString(); } diff --git a/packages/network_info_plus/network_info_plus/test/network_info_plus_linux_test.dart b/packages/network_info_plus/network_info_plus/test/network_info_plus_linux_test.dart index 98e2d3a145..2830599a74 100644 --- a/packages/network_info_plus/network_info_plus/test/network_info_plus_linux_test.dart +++ b/packages/network_info_plus/network_info_plus/test/network_info_plus_linux_test.dart @@ -26,7 +26,7 @@ void main() { for (final (address, prefix, mask, broadcast) in cases) { test('$address/$prefix', () async { final plugin = NetworkInfoPlusLinuxPlugin() - ..createClient = () => _FakeClient(address: address, prefix: prefix); + ..createClient = () => _FakeClient.withAddress(address, prefix); expect(await plugin.getWifiSubmask(), mask); expect(await plugin.getWifiBroadcast(), broadcast); @@ -36,15 +36,36 @@ void main() { test('wifi IP and gateway are passed through', () async { final plugin = NetworkInfoPlusLinuxPlugin() - ..createClient = () => _FakeClient(address: '192.168.1.10', prefix: 22); + ..createClient = () => _FakeClient.withAddress('192.168.1.10', 22); expect(await plugin.getWifiIP(), '192.168.1.10'); expect(await plugin.getWifiGatewayIP(), '192.168.0.1'); }); + + group('missing IPv4 data returns null', () { + final cases = { + 'primaryConnection is null': () => null, + 'ip4Config is null': () => _FakeConnection(null), + 'addressData is empty': () => _FakeConnection(_FakeIp4Config([])), + }; + + for (final MapEntry(key: description, value: connection) in cases.entries) { + test(description, () async { + final plugin = NetworkInfoPlusLinuxPlugin() + ..createClient = () => _FakeClient(connection()); + + expect(await plugin.getWifiSubmask(), isNull); + expect(await plugin.getWifiBroadcast(), isNull); + expect(await plugin.getWifiIP(), isNull); + }); + } + }); } class _FakeClient extends Fake implements NetworkManagerClient { - _FakeClient({required String address, required int prefix}) + _FakeClient(this.primaryConnection); + + _FakeClient.withAddress(String address, int prefix) : primaryConnection = _FakeConnection( _FakeIp4Config([ {'address': address, 'prefix': prefix},