diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 00000000..b148779e --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,34 @@ +# lint analysis +include: package:lint/analysis_options.yaml + +analyzer: + errors: + missing_required_param: error + missing_return: error + must_be_immutable: error + exclude: + - "**/*.g.dart" + - "**/*.freezed.dart" + - "**/*.pb.dart" + - "**/*.pbenum.dart" + - "**/*.pbgrpc.dart" + - "**/*.pbjson.dart" + - "**/*.gr.dart" + - "**/*.config.dart" + + +linter: + rules: + # Use parameter order as in json response + # always_put_required_named_parameters_first: false + + avoid_classes_with_only_static_members: false + + sort_constructors_first: true + + prefer_single_quotes: true + + # Good packages document everything + public_member_api_docs: true + + lines_longer_than_80_chars: true diff --git a/android/build.gradle b/android/build.gradle index bc151583..8809e32f 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = '1.3.50' + ext.kotlin_version = '1.6.10' repositories { google() jcenter() diff --git a/lib/api/isp_loader.dart b/lib/api/isp_loader.dart index 960b463d..41eb2bba 100644 --- a/lib/api/isp_loader.dart +++ b/lib/api/isp_loader.dart @@ -1,11 +1,11 @@ import 'dart:convert'; import 'dart:io'; + import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart' show rootBundle; import 'package:http/http.dart' as http; - import 'package:shared_preferences/shared_preferences.dart'; import 'package:vernet/models/internet_provider.dart'; -import 'package:flutter/services.dart' show rootBundle; class ISPLoader { static Future loadIP(String url) async { @@ -19,7 +19,7 @@ class ISPLoader { Future _mimicLoad() async { return rootBundle.loadStructuredData( 'assets/ipwhois.json', (json) async { - return InternetProvider.fromMap(jsonDecode(json)); + return InternetProvider.fromMap(jsonDecode(json) as Map); }); } @@ -40,7 +40,8 @@ class ISPLoader { String? json = sp.getString(_ip); if (json != null && json.isNotEmpty) { // print('Response fetched from local $json'); - return InternetProvider.fromMap(jsonDecode(json)); + return InternetProvider.fromMap( + jsonDecode(json) as Map); } } @@ -51,7 +52,7 @@ class ISPLoader { String body = await compute(loadISP, url); if (body.isNotEmpty) { sp.setString(_ip, body); - return InternetProvider.fromMap(jsonDecode(body)); + return InternetProvider.fromMap(jsonDecode(body) as Map); } return null; } diff --git a/lib/api/update_checker.dart b/lib/api/update_checker.dart index 62fdf9b1..8a43c9eb 100644 --- a/lib/api/update_checker.dart +++ b/lib/api/update_checker.dart @@ -12,19 +12,20 @@ Future _checkUpdates(String v) async { 'https://api.github.com/repos/git-elliot/vernet/tags?per_page=1'); var response = await http.get(url); if (response.statusCode == HttpStatus.ok) { - List res = jsonDecode(response.body); + List res = jsonDecode(response.body) as List; debugPrint(res.toString()); if (res.length > 0) { - String tag = res[0]["name"]; + String tag = res[0]["name"] as String; if (tag.contains('v')) { tag = tag.substring(1); } - if (v.contains('-store')) { - List sp = v.split('-store'); - v = sp[0] + sp[1]; + String tempV = v; + if (tempV.contains('-store')) { + List sp = tempV.split('-store'); + tempV = sp[0] + sp[1]; } - debugPrint("tag: $tag , v: $v"); - return v.compareTo(tag) < 0; + debugPrint("tag: $tag , v: $tempV"); + return tempV.compareTo(tag) < 0; } } return false; diff --git a/lib/generated_plugin_registrant.dart b/lib/generated_plugin_registrant.dart index f7ac9644..a7b03493 100644 --- a/lib/generated_plugin_registrant.dart +++ b/lib/generated_plugin_registrant.dart @@ -2,6 +2,7 @@ // Generated file. Do not edit. // +// ignore_for_file: directives_ordering // ignore_for_file: lines_longer_than_80_chars import 'package:network_info_plus_web/network_info_plus_web.dart'; diff --git a/lib/helper/port_desc_loader.dart b/lib/helper/port_desc_loader.dart index 20358adb..4f5b48d1 100644 --- a/lib/helper/port_desc_loader.dart +++ b/lib/helper/port_desc_loader.dart @@ -1,15 +1,16 @@ import 'dart:convert'; + import 'package:flutter/foundation.dart'; -import 'package:vernet/models/port.dart'; import 'package:flutter/services.dart' show rootBundle; +import 'package:vernet/models/port.dart'; /// Do not put this method inside any class, be it top level function /// Because this method runs inside isolate. Future> _parsePortDesc(String json) async { - Map ports = jsonDecode(json); + Map ports = jsonDecode(json) as Map; Map mPorts = {}; for (String key in ports.keys) { - List port = ports[key]; + List port = ports[key] as List; if (port.length > 0) { mPorts[key] = Port.fromJson(port[0]); } diff --git a/lib/models/internet_provider.dart b/lib/models/internet_provider.dart index 22895f0b..083ad06d 100644 --- a/lib/models/internet_provider.dart +++ b/lib/models/internet_provider.dart @@ -10,9 +10,9 @@ class InternetProvider { String get ipType => _ipType; InternetProvider.fromMap(Map json) - : _isp = json['isp'], - _ip = json['ip'], - _ipType = json['type'], + : _isp = json['isp'] as String, + _ip = json['ip'] as String, + _ipType = json['type'] as String, _location = Location.fromMap(json); } @@ -30,10 +30,10 @@ class Location { String get flagUrl => _flagUrl; Location.fromMap(Map json) - : _country = json['country'], - _region = json['region'], - _city = json['city'], - _lat = json['latitude'], - _lng = json['longitude'], - _flagUrl = json['country_flag']; + : _country = json['country'] as String, + _region = json['region'] as String, + _city = json['city'] as String, + _lat = json['latitude'] as String, + _lng = json['longitude'] as String, + _flagUrl = json['country_flag'] as String; } diff --git a/lib/models/port.dart b/lib/models/port.dart index ee403fa4..0833b3f0 100644 --- a/lib/models/port.dart +++ b/lib/models/port.dart @@ -12,9 +12,9 @@ class Port { String get status => _status; Port.fromJson(dynamic map) - : _desc = map['description'], - _tcp = map['tcp'], - _udp = map['udp'], - _port = map['port'], - _status = map['status']; + : _desc = map['description'] as String, + _tcp = map['tcp'] as bool, + _udp = map['udp'] as bool, + _port = map['port'] as String, + _status = map['status'] as String; } diff --git a/lib/pages/base_page.dart b/lib/pages/base_page.dart index 975128b4..130064fe 100644 --- a/lib/pages/base_page.dart +++ b/lib/pages/base_page.dart @@ -8,7 +8,7 @@ abstract class BasePage extends State { String title(); String fieldLabel(); - _getDomainChip(String label) { + Widget _getDomainChip(String label) { return PopularChip( label: label, onPressed: () { diff --git a/lib/pages/host_scan_page.dart b/lib/pages/host_scan_page.dart index aaf874be..5262f265 100644 --- a/lib/pages/host_scan_page.dart +++ b/lib/pages/host_scan_page.dart @@ -23,33 +23,42 @@ class _HostScanPageState extends State double _progress = 0; StreamSubscription? _streamSubscription; + bool isScanning = true; + void _getDevices() async { _devices.clear(); final String? ip = await (NetworkInfo().getWifiIP()); if (ip != null && ip.isNotEmpty) { final String subnet = ip.substring(0, ip.lastIndexOf('.')); - final stream = HostScanner.discover(subnet, - firstSubnet: appSettings.firstSubnet, - lastSubnet: appSettings.lastSubnet, progressCallback: (progress) { - debugPrint('Progress : $progress'); - if (this.mounted) { + final stream = HostScanner.discover( + subnet, + firstSubnet: appSettings.firstSubnet, + lastSubnet: appSettings.lastSubnet, + progressCallback: (progress) { + debugPrint('Progress : $progress'); + if (this.mounted) { + setState(() { + _progress = progress; + }); + } + }, + ); + + _streamSubscription = stream.listen( + (ActiveHost device) { + debugPrint('Found device: ${device.ip}'); setState(() { - _progress = progress; + _devices.add(device); }); - } - }); - - _streamSubscription = stream.listen((ActiveHost device) { - debugPrint('Found device: ${device.ip}'); - setState(() { - _devices.add(device); - }); - }, onDone: () { - debugPrint('Scan completed'); - if (this.mounted) { - setState(() {}); - } - }); + }, + onDone: () { + debugPrint('Scan completed'); + if (this.mounted) { + setState(() {}); + } + isScanning = false; + }, + ); } } @@ -71,7 +80,7 @@ class _HostScanPageState extends State appBar: AppBar( title: Text('Scan for Devices'), actions: [ - HostScanner.isScanning + isScanning ? Container( margin: EdgeInsets.only(right: 20.0), child: new CircularPercentIndicator( @@ -100,7 +109,7 @@ class _HostScanPageState extends State 'No device found.\nTry changing first and last subnet in settings', textAlign: TextAlign.center, ); - } else if (HostScanner.isScanning && _devices.isEmpty) { + } else if (isScanning && _devices.isEmpty) { return CircularProgressIndicator.adaptive(); } @@ -110,7 +119,8 @@ class _HostScanPageState extends State child: ListView.builder( itemCount: _devices.length, itemBuilder: (context, index) { - ActiveHost device = SplayTreeSet.from(_devices).toList()[index]; + ActiveHost device = + SplayTreeSet.from(_devices).toList()[index] as ActiveHost; return ListTile( title: Text(device.make), subtitle: Text(device.ip), diff --git a/lib/pages/network_troubleshoot/ping_page.dart b/lib/pages/network_troubleshoot/ping_page.dart index c679186c..f96b920e 100644 --- a/lib/pages/network_troubleshoot/ping_page.dart +++ b/lib/pages/network_troubleshoot/ping_page.dart @@ -127,7 +127,7 @@ class _PingPageState extends BasePage { ); } - _getTime(Duration? time) { + String _getTime(Duration? time) { if (time != null) { final ms = time.inMicroseconds / Duration.millisecondsPerSecond; return '$ms ms'; diff --git a/lib/pages/network_troubleshoot/port_scan_page.dart b/lib/pages/network_troubleshoot/port_scan_page.dart index 0f1e0b64..96378ced 100644 --- a/lib/pages/network_troubleshoot/port_scan_page.dart +++ b/lib/pages/network_troubleshoot/port_scan_page.dart @@ -1,4 +1,5 @@ import 'dart:async'; + import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:network_tools/network_tools.dart'; @@ -123,7 +124,7 @@ class _PortScanPageState extends State _streamSubscription?.cancel(); } - _getCustomRangeChip(String label, String start, String end) { + Widget _getCustomRangeChip(String label, String start, String end) { return PopularChip( label: label, onPressed: () { @@ -133,7 +134,7 @@ class _PortScanPageState extends State ); } - _getSinglePortChip(String label, String port) { + Widget _getSinglePortChip(String label, String port) { return PopularChip( label: label, onPressed: () { @@ -142,7 +143,7 @@ class _PortScanPageState extends State ); } - _getDomainChip(String label) { + Widget _getDomainChip(String label) { return PopularChip( label: label, onPressed: () { @@ -151,7 +152,7 @@ class _PortScanPageState extends State ); } - _getFields() { + Widget _getFields() { if (_type == ScanType.single) { return TextFormField( keyboardType: TextInputType.number, @@ -185,6 +186,7 @@ class _PortScanPageState extends State ], ); } + return const Text(''); } String? validatePorts(String? value) { diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index 026851fa..f6f23bfe 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -2,6 +2,8 @@ // Generated file. Do not edit. // +// clang-format off + #include "generated_plugin_registrant.h" #include diff --git a/linux/flutter/generated_plugin_registrant.h b/linux/flutter/generated_plugin_registrant.h index 9bf74789..e0f0a47b 100644 --- a/linux/flutter/generated_plugin_registrant.h +++ b/linux/flutter/generated_plugin_registrant.h @@ -2,6 +2,8 @@ // Generated file. Do not edit. // +// clang-format off + #ifndef GENERATED_PLUGIN_REGISTRANT_ #define GENERATED_PLUGIN_REGISTRANT_ diff --git a/pubspec.lock b/pubspec.lock index c4d8a5c0..76e29839 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -14,7 +14,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.6.1" + version: "2.8.2" boolean_selector: dependency: transitive description: @@ -28,14 +28,14 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" clock: dependency: transitive description: @@ -56,14 +56,14 @@ packages: name: cupertino_icons url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "1.0.4" dart_ping: dependency: "direct main" description: name: dart_ping url: "https://pub.dartlang.org" source: hosted - version: "6.0.0" + version: "6.1.1" dbus: dependency: transitive description: @@ -113,7 +113,7 @@ packages: name: http url: "https://pub.dartlang.org" source: hosted - version: "0.13.3" + version: "0.13.4" http_parser: dependency: transitive description: @@ -128,20 +128,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.6.3" + lint: + dependency: "direct dev" + description: + name: lint + url: "https://pub.dartlang.org" + source: hosted + version: "1.8.1" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10" + version: "0.12.11" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.7.0" nested: dependency: transitive description: @@ -155,7 +162,7 @@ packages: name: network_info_plus url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "2.1.2" network_info_plus_linux: dependency: transitive description: @@ -169,14 +176,14 @@ packages: name: network_info_plus_macos url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.3.0" network_info_plus_platform_interface: dependency: transitive description: name: network_info_plus_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.1.0" network_info_plus_web: dependency: transitive description: @@ -197,49 +204,49 @@ packages: name: network_tools url: "https://pub.dartlang.org" source: hosted - version: "0.0.4" + version: "0.0.6" package_info_plus: dependency: "direct main" description: name: package_info_plus url: "https://pub.dartlang.org" source: hosted - version: "1.0.2" + version: "1.3.0" package_info_plus_linux: dependency: transitive description: name: package_info_plus_linux url: "https://pub.dartlang.org" source: hosted - version: "1.0.2" + version: "1.0.3" package_info_plus_macos: dependency: transitive description: name: package_info_plus_macos url: "https://pub.dartlang.org" source: hosted - version: "1.1.1" + version: "1.3.0" package_info_plus_platform_interface: dependency: transitive description: name: package_info_plus_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.0.2" package_info_plus_web: dependency: transitive description: name: package_info_plus_web url: "https://pub.dartlang.org" source: hosted - version: "1.0.2" + version: "1.0.4" package_info_plus_windows: dependency: transitive description: name: package_info_plus_windows url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.0.4" path: dependency: transitive description: @@ -281,21 +288,21 @@ packages: name: percent_indicator url: "https://pub.dartlang.org" source: hosted - version: "3.3.0-nullsafety.1" + version: "3.4.0" permission_handler: dependency: "direct main" description: name: permission_handler url: "https://pub.dartlang.org" source: hosted - version: "8.0.0+2" + version: "8.3.0" permission_handler_platform_interface: dependency: transitive description: name: permission_handler_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "3.5.0" + version: "3.7.0" petitparser: dependency: transitive description: @@ -330,21 +337,35 @@ packages: name: provider url: "https://pub.dartlang.org" source: hosted - version: "5.0.0" + version: "6.0.2" shared_preferences: dependency: "direct main" description: name: shared_preferences url: "https://pub.dartlang.org" source: hosted - version: "2.0.6" + version: "2.0.12" + shared_preferences_android: + dependency: transitive + description: + name: shared_preferences_android + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.10" + shared_preferences_ios: + dependency: transitive + description: + name: shared_preferences_ios + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.9" shared_preferences_linux: dependency: transitive description: name: shared_preferences_linux url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.4" shared_preferences_macos: dependency: transitive description: @@ -372,7 +393,7 @@ packages: name: shared_preferences_windows url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.4" sky_engine: dependency: transitive description: flutter @@ -419,7 +440,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.3.0" + version: "0.4.3" typed_data: dependency: transitive description: @@ -433,7 +454,21 @@ packages: name: url_launcher url: "https://pub.dartlang.org" source: hosted - version: "6.0.6" + version: "6.0.18" + url_launcher_android: + dependency: transitive + description: + name: url_launcher_android + url: "https://pub.dartlang.org" + source: hosted + version: "6.0.14" + url_launcher_ios: + dependency: transitive + description: + name: url_launcher_ios + url: "https://pub.dartlang.org" + source: hosted + version: "6.0.14" url_launcher_linux: dependency: transitive description: @@ -475,7 +510,7 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.1" win32: dependency: transitive description: @@ -498,5 +533,5 @@ packages: source: hosted version: "5.1.1" sdks: - dart: ">=2.13.0 <3.0.0" - flutter: ">=2.0.0" + dart: ">=2.15.0-7.0.dev <3.0.0" + flutter: ">=2.5.0" diff --git a/pubspec.yaml b/pubspec.yaml index 89ed1fef..94bd42cb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,34 +15,34 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.0.1+10 +version: 0.13.4 environment: sdk: ">=2.12.0 <3.0.0" dependencies: + dart_ping: ^6.1.1 flutter: sdk: flutter - network_info_plus: ^1.0.1 - permission_handler: ^8.0.0+2 - dart_ping: ^6.0.0 - percent_indicator: ^3.3.0-nullsafety.1 - shared_preferences: ^2.0.6 - provider: ^5.0.0 - network_tools: ^0.0.4 - # network_tools: - # path: ../network_tools - package_info_plus: ^1.0.2 - http: ^0.13.3 - url_launcher: ^6.0.6 + network_info_plus: ^2.1.2 + percent_indicator: ^3.4.0 + permission_handler: ^8.3.0 + shared_preferences: ^2.0.12 + network_tools: ^0.0.6 + provider: ^6.0.2 + package_info_plus: ^1.3.0 + http: ^0.13.4 + url_launcher: ^6.0.18 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^1.0.2 + cupertino_icons: ^1.0.4 dev_dependencies: flutter_test: sdk: flutter + # Collection of lint rules for Dart and Flutter projects. + lint: ^1.8.1 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec