diff --git a/analysis_options.yaml b/analysis_options.yaml index b3b4347..2d0294a 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -51,7 +51,6 @@ linter: # - always_specify_types - annotate_overrides # - avoid_annotating_with_dynamic # conflicts with always_specify_types - - avoid_as # - avoid_bool_literals_in_conditional_expressions # not yet tested # - avoid_catches_without_on_clauses # we do this commonly # - avoid_catching_errors # we do this commonly diff --git a/example/flutter_example/.flutter-plugins-dependencies b/example/flutter_example/.flutter-plugins-dependencies new file mode 100644 index 0000000..b2dea06 --- /dev/null +++ b/example/flutter_example/.flutter-plugins-dependencies @@ -0,0 +1 @@ +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"network_info_plus","path":"/Users/tonu/.pub-cache/hosted/pub.dartlang.org/network_info_plus-3.0.5/","native_build":true,"dependencies":[]}],"android":[{"name":"network_info_plus","path":"/Users/tonu/.pub-cache/hosted/pub.dartlang.org/network_info_plus-3.0.5/","native_build":true,"dependencies":[]}],"macos":[{"name":"network_info_plus","path":"/Users/tonu/.pub-cache/hosted/pub.dartlang.org/network_info_plus-3.0.5/","native_build":true,"dependencies":[]}],"linux":[{"name":"network_info_plus","path":"/Users/tonu/.pub-cache/hosted/pub.dartlang.org/network_info_plus-3.0.5/","native_build":false,"dependencies":[]}],"windows":[{"name":"network_info_plus","path":"/Users/tonu/.pub-cache/hosted/pub.dartlang.org/network_info_plus-3.0.5/","native_build":true,"dependencies":[]}],"web":[{"name":"network_info_plus","path":"/Users/tonu/.pub-cache/hosted/pub.dartlang.org/network_info_plus-3.0.5/","dependencies":[]}]},"dependencyGraph":[{"name":"network_info_plus","dependencies":[]}],"date_created":"2023-12-11 17:29:33.945557","version":"3.3.9"} \ No newline at end of file diff --git a/example/flutter_example/android/app/src/main/AndroidManifest.xml b/example/flutter_example/android/app/src/main/AndroidManifest.xml index b8c4588..0bc7ff4 100644 --- a/example/flutter_example/android/app/src/main/AndroidManifest.xml +++ b/example/flutter_example/android/app/src/main/AndroidManifest.xml @@ -7,7 +7,7 @@ additional functionality it is fine to subclass or reimplement FlutterApplication and put your custom class here. --> - + diff --git a/example/flutter_example/android/app/src/main/java/com/example/flutter_example/MainActivity.java b/example/flutter_example/android/app/src/main/java/com/example/flutter_example/MainActivity.java index 87f5993..403a2e7 100644 --- a/example/flutter_example/android/app/src/main/java/com/example/flutter_example/MainActivity.java +++ b/example/flutter_example/android/app/src/main/java/com/example/flutter_example/MainActivity.java @@ -1,13 +1,21 @@ package com.example.flutter_example; -import android.os.Bundle; -import io.flutter.app.FlutterActivity; +import androidx.annotation.NonNull; + +import io.flutter.embedding.android.FlutterActivity; +import io.flutter.embedding.engine.FlutterEngine; +import io.flutter.plugin.common.MethodChannel; import io.flutter.plugins.GeneratedPluginRegistrant; public class MainActivity extends FlutterActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - GeneratedPluginRegistrant.registerWith(this); - } + @Override + public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { + GeneratedPluginRegistrant.registerWith(flutterEngine); + new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), CHANNEL) + .setMethodCallHandler( + (call, result) -> { + // Your existing code + } + ); + } } diff --git a/example/flutter_example/ios/Flutter/flutter_export_environment.sh b/example/flutter_example/ios/Flutter/flutter_export_environment.sh new file mode 100755 index 0000000..67710dd --- /dev/null +++ b/example/flutter_example/ios/Flutter/flutter_export_environment.sh @@ -0,0 +1,13 @@ +#!/bin/sh +# This is a generated file; do not edit or check into version control. +export "FLUTTER_ROOT=/Users/tonu/development/flutter" +export "FLUTTER_APPLICATION_PATH=/Users/tonu/Desktop/Workspace/Klikit/App/ping_discover_network/example/flutter_example" +export "COCOAPODS_PARALLEL_CODE_SIGN=true" +export "FLUTTER_TARGET=lib/main.dart" +export "FLUTTER_BUILD_DIR=build" +export "FLUTTER_BUILD_NAME=1.0.0" +export "FLUTTER_BUILD_NUMBER=1" +export "DART_OBFUSCATION=false" +export "TRACK_WIDGET_CREATION=true" +export "TREE_SHAKE_ICONS=false" +export "PACKAGE_CONFIG=.dart_tool/package_config.json" diff --git a/example/flutter_example/lib/main.dart b/example/flutter_example/lib/main.dart index 293626b..9b6943c 100644 --- a/example/flutter_example/lib/main.dart +++ b/example/flutter_example/lib/main.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; +import 'package:network_info_plus/network_info_plus.dart'; import 'package:ping_discover_network/ping_discover_network.dart'; -import 'package:wifi/wifi.dart'; void main() => runApp(MyApp()); @@ -38,12 +38,12 @@ class _MyHomePageState extends State { String ip; try { - ip = await Wifi.ip; + ip = await NetworkInfo().getWifiIP() ?? ''; print('local ip:\t$ip'); } catch (e) { final snackBar = SnackBar( content: Text('WiFi is not connected', textAlign: TextAlign.center)); - Scaffold.of(ctx).showSnackBar(snackBar); + ScaffoldMessenger.of(ctx).showSnackBar(snackBar); return; } setState(() { @@ -79,7 +79,7 @@ class _MyHomePageState extends State { ..onError((dynamic e) { final snackBar = SnackBar( content: Text('Unexpected exception', textAlign: TextAlign.center)); - Scaffold.of(ctx).showSnackBar(snackBar); + ScaffoldMessenger.of(ctx).showSnackBar(snackBar); }); } @@ -107,7 +107,7 @@ class _MyHomePageState extends State { SizedBox(height: 10), Text('Local ip: $localIp', style: TextStyle(fontSize: 16)), SizedBox(height: 15), - RaisedButton( + TextButton( child: Text( '${isDiscovering ? 'Discovering...' : 'Discover'}'), onPressed: isDiscovering ? null : () => discover(context)), diff --git a/example/flutter_example/pubspec.lock b/example/flutter_example/pubspec.lock new file mode 100644 index 0000000..6797431 --- /dev/null +++ b/example/flutter_example/pubspec.lock @@ -0,0 +1,229 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + args: + dependency: transitive + description: + name: args + url: "https://pub.dartlang.org" + source: hosted + version: "2.4.1" + async: + dependency: transitive + description: + name: async + url: "https://pub.dartlang.org" + source: hosted + version: "2.9.0" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.1" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + collection: + dependency: transitive + description: + name: collection + url: "https://pub.dartlang.org" + source: hosted + version: "1.16.0" + cupertino_icons: + dependency: "direct main" + description: + name: cupertino_icons + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.3" + dbus: + dependency: transitive + description: + name: dbus + url: "https://pub.dartlang.org" + source: hosted + version: "0.7.10" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.1" + ffi: + dependency: transitive + description: + name: ffi + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.2" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + js: + dependency: transitive + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.4" + matcher: + dependency: transitive + description: + name: matcher + url: "https://pub.dartlang.org" + source: hosted + version: "0.12.12" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.5" + meta: + dependency: transitive + description: + name: meta + url: "https://pub.dartlang.org" + source: hosted + version: "1.8.0" + network_info_plus: + dependency: "direct main" + description: + name: network_info_plus + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.5" + network_info_plus_platform_interface: + dependency: transitive + description: + name: network_info_plus_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.3" + nm: + dependency: transitive + description: + name: nm + url: "https://pub.dartlang.org" + source: hosted + version: "0.5.0" + path: + dependency: transitive + description: + name: path + url: "https://pub.dartlang.org" + source: hosted + version: "1.8.2" + petitparser: + dependency: transitive + description: + name: petitparser + url: "https://pub.dartlang.org" + source: hosted + version: "5.1.0" + ping_discover_network: + dependency: "direct main" + description: + path: "../.." + relative: true + source: path + version: "0.2.0+1" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.5" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + source_span: + dependency: transitive + description: + name: source_span + url: "https://pub.dartlang.org" + source: hosted + version: "1.9.0" + stack_trace: + dependency: transitive + description: + name: stack_trace + url: "https://pub.dartlang.org" + source: hosted + version: "1.10.0" + stream_channel: + dependency: transitive + description: + name: stream_channel + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + string_scanner: + dependency: transitive + description: + name: string_scanner + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + term_glyph: + dependency: transitive + description: + name: term_glyph + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.1" + test_api: + dependency: transitive + description: + name: test_api + url: "https://pub.dartlang.org" + source: hosted + version: "0.4.12" + vector_math: + dependency: transitive + description: + name: vector_math + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.2" + xml: + dependency: transitive + description: + name: xml + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.0" +sdks: + dart: ">=2.18.0 <3.0.0" + flutter: ">=2.11.0" diff --git a/example/flutter_example/pubspec.yaml b/example/flutter_example/pubspec.yaml index 6ee1810..8c79b49 100644 --- a/example/flutter_example/pubspec.yaml +++ b/example/flutter_example/pubspec.yaml @@ -1,5 +1,6 @@ name: flutter_example description: A new Flutter project. +publish_to: none version: 1.0.0+1 @@ -12,7 +13,7 @@ dependencies: cupertino_icons: ^0.1.2 ping_discover_network: path: ../../ - wifi: ^0.1.5 + network_info_plus: ^3.0.5 dev_dependencies: flutter_test: diff --git a/lib/src/network_analyzer.dart b/lib/src/network_analyzer.dart index b806e14..6aa9a7b 100644 --- a/lib/src/network_analyzer.dart +++ b/lib/src/network_analyzer.dart @@ -45,7 +45,7 @@ class NetworkAnalyzer { } // Check if connection timed out or we got one of predefined errors - if (e.osError == null || _errorCodes.contains(e.osError.errorCode)) { + if (e.osError == null || _errorCodes.contains(e.osError?.errorCode)) { yield NetworkAddress(host, false); } else { // Error 23,24: Too many open files in system @@ -83,7 +83,7 @@ class NetworkAnalyzer { } // Check if connection timed out or we got one of predefined errors - if (e.osError == null || _errorCodes.contains(e.osError.errorCode)) { + if (e.osError == null || _errorCodes.contains(e.osError?.errorCode)) { out.sink.add(NetworkAddress(host, false)); } else { // Error 23,24: Too many open files in system diff --git a/pubspec.lock b/pubspec.lock new file mode 100644 index 0000000..e15edce --- /dev/null +++ b/pubspec.lock @@ -0,0 +1,139 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + async: + dependency: transitive + description: + name: async + url: "https://pub.dartlang.org" + source: hosted + version: "2.9.0" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.1" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + collection: + dependency: transitive + description: + name: collection + url: "https://pub.dartlang.org" + source: hosted + version: "1.16.0" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.1" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + matcher: + dependency: transitive + description: + name: matcher + url: "https://pub.dartlang.org" + source: hosted + version: "0.12.12" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.5" + meta: + dependency: transitive + description: + name: meta + url: "https://pub.dartlang.org" + source: hosted + version: "1.8.0" + path: + dependency: transitive + description: + name: path + url: "https://pub.dartlang.org" + source: hosted + version: "1.8.2" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + source_span: + dependency: transitive + description: + name: source_span + url: "https://pub.dartlang.org" + source: hosted + version: "1.9.0" + stack_trace: + dependency: transitive + description: + name: stack_trace + url: "https://pub.dartlang.org" + source: hosted + version: "1.10.0" + stream_channel: + dependency: transitive + description: + name: stream_channel + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + string_scanner: + dependency: transitive + description: + name: string_scanner + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + term_glyph: + dependency: transitive + description: + name: term_glyph + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.1" + test_api: + dependency: transitive + description: + name: test_api + url: "https://pub.dartlang.org" + source: hosted + version: "0.4.12" + vector_math: + dependency: transitive + description: + name: vector_math + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.2" +sdks: + dart: ">=2.17.0-0 <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 9c95788..0117166 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,11 +1,10 @@ name: ping_discover_network description: Library that allows to ping IP subnet and discover network devices. Could be used to find printers and other devices and services in a local network. version: 0.2.0+1 -author: Andrey Ushakov homepage: https://github.com/andrey-ushakov/ping_discover_network environment: - sdk: ">=2.1.0 <3.0.0" + sdk: ">=2.14.0 <4.0.0" dependencies: flutter: