From cb7ac19806659498d25018f3c215fa33a7a41d51 Mon Sep 17 00:00:00 2001 From: Paras Date: Tue, 6 Jul 2021 14:18:10 +0530 Subject: [PATCH] GeoLocation API updated and speed test added --- android/local.properties | 2 +- assets/ipify.json | 26 ------- assets/ipwhois.json | 31 ++++++++ .../metadata/android/en-US/changelogs/8.txt | 1 + lib/api/isp_loader.dart | 16 ++-- lib/helper/secret_loader.dart | 1 + lib/models/internet_provider.dart | 25 ++++-- lib/pages/settings_page.dart | 23 ++++-- lib/ui/wifi_detail.dart | 76 ++++++++++++++----- pubspec.lock | 21 +++++ pubspec.yaml | 5 +- 11 files changed, 154 insertions(+), 73 deletions(-) delete mode 100644 assets/ipify.json create mode 100644 assets/ipwhois.json create mode 100644 fastlane/metadata/android/en-US/changelogs/8.txt diff --git a/android/local.properties b/android/local.properties index 3e5515b2..ef6ae666 100644 --- a/android/local.properties +++ b/android/local.properties @@ -2,4 +2,4 @@ sdk.dir=/Users/paras/Library/Android/sdk flutter.sdk=/Users/paras/Development/flutter flutter.buildMode=release flutter.versionName=1.0.0 -flutter.versionCode=7 \ No newline at end of file +flutter.versionCode=8 \ No newline at end of file diff --git a/assets/ipify.json b/assets/ipify.json deleted file mode 100644 index a1f95a38..00000000 --- a/assets/ipify.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "ip": "106.223.35.229", - "location": { - "country": "IN", - "region": "State of Haryāna", - "city": "Gurgaon", - "lat": 28.4601, - "lng": 77.02635, - "postalCode": "", - "timezone": "+05:30", - "geonameId": 1270642 - }, - "as": { - "asn": 45609, - "name": "BHARTI-MOBILITY-AS-AP", - "route": "106.223.32.0/22", - "domain": "", - "type": "" - }, - "isp": "Bharti Airtel Limited", - "proxy": { - "proxy": false, - "vpn": false, - "tor": false - } -} \ No newline at end of file diff --git a/assets/ipwhois.json b/assets/ipwhois.json new file mode 100644 index 00000000..5647c06f --- /dev/null +++ b/assets/ipwhois.json @@ -0,0 +1,31 @@ +{ + "ip": "8.8.4.4", + "success": true, + "type": "IPv4", + "continent": "North America", + "continent_code": "NA", + "country": "United States", + "country_code": "US", + "country_flag": "https://cdn.ipwhois.io/flags/us.svg", + "country_capital": "Washington", + "country_phone": "+1", + "country_neighbours": "CA,MX,CU", + "region": "California", + "city": "Mountain View", + "latitude": "37.3860517", + "longitude": "-122.0838511", + "asn": "AS15169", + "org": "Google LLC", + "isp": "Google LLC", + "timezone": "America/Los_Angeles", + "timezone_name": "Pacific Standard Time", + "timezone_dstOffset": "0", + "timezone_gmtOffset": "-28800", + "timezone_gmt": "GMT -8:00", + "currency": "US Dollar", + "currency_code": "USD", + "currency_symbol": "$", + "currency_rates": "1", + "currency_plural": "US dollars", + "completed_requests": 0 +} \ No newline at end of file diff --git a/fastlane/metadata/android/en-US/changelogs/8.txt b/fastlane/metadata/android/en-US/changelogs/8.txt new file mode 100644 index 00000000..ebe52553 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/8.txt @@ -0,0 +1 @@ +GeoLocation API updated and speed test via browser added \ No newline at end of file diff --git a/lib/api/isp_loader.dart b/lib/api/isp_loader.dart index 051bad50..874676d9 100644 --- a/lib/api/isp_loader.dart +++ b/lib/api/isp_loader.dart @@ -4,9 +4,7 @@ import 'package:flutter/foundation.dart'; import 'package:http/http.dart' as http; import 'package:shared_preferences/shared_preferences.dart'; -import 'package:vernet/helper/secret_loader.dart'; import 'package:vernet/models/internet_provider.dart'; -import 'package:vernet/models/secret.dart'; import 'package:flutter/services.dart' show rootBundle; class ISPLoader { @@ -20,8 +18,8 @@ class ISPLoader { } Future _mimicLoad() async { - return rootBundle.loadStructuredData('assets/ipify.json', - (json) async { + return rootBundle.loadStructuredData( + 'assets/ipwhois.json', (json) async { return InternetProvider.fromMap(jsonDecode(json)); }); } @@ -39,14 +37,12 @@ class ISPLoader { } } - Secret secret = await SecretLoader('assets/secrets.json').load(); - String uri = 'https://geo.ipify.org/api/v1?apiKey=' + - secret.ipifyKey + - '&ipAddress=' + - _ip; + // Secret secret = await SecretLoader('assets/secrets.json').load(); + String uri = + 'http://ipwhois.app/json/$_ip?objects=isp,country,region,city,latitude,longitude,country_flag,ip,type'; var response = await http.get(Uri.parse(uri)); if (response.statusCode == HttpStatus.ok) { - // print('Response fetched from ipify.org ${response.body}'); + // print('Response fetched from api ${response.body}'); sp.setString(_ip, response.body); return InternetProvider.fromMap(jsonDecode(response.body)); } diff --git a/lib/helper/secret_loader.dart b/lib/helper/secret_loader.dart index 6946d0ef..ec657d60 100644 --- a/lib/helper/secret_loader.dart +++ b/lib/helper/secret_loader.dart @@ -3,6 +3,7 @@ import 'dart:convert' show json; import 'package:flutter/services.dart' show rootBundle; import 'package:vernet/models/secret.dart'; +//TODO: remove this class, not required now. class SecretLoader { final String secretPath; diff --git a/lib/models/internet_provider.dart b/lib/models/internet_provider.dart index 0f52a561..22895f0b 100644 --- a/lib/models/internet_provider.dart +++ b/lib/models/internet_provider.dart @@ -1,28 +1,39 @@ class InternetProvider { String _isp; + String _ip; + String _ipType; Location _location; + String get isp => _isp; Location get location => _location; + String get ip => _ip; + String get ipType => _ipType; + InternetProvider.fromMap(Map json) : _isp = json['isp'], - _location = Location.fromMap(json['location']); + _ip = json['ip'], + _ipType = json['type'], + _location = Location.fromMap(json); } class Location { String _country; String _region; String _city; - double _lat; - double _lng; + String _lat; + String _lng; + String _flagUrl; String get address => _city + ', ' + _region + ', ' + _country; - double get lat => _lat; - double get lng => _lng; + String get lat => _lat; + String get lng => _lng; + String get flagUrl => _flagUrl; Location.fromMap(Map json) : _country = json['country'], _region = json['region'], _city = json['city'], - _lat = json['lat'], - _lng = json['lng']; + _lat = json['latitude'], + _lng = json['longitude'], + _flagUrl = json['country_flag']; } diff --git a/lib/pages/settings_page.dart b/lib/pages/settings_page.dart index 3273f4d4..828f2d81 100644 --- a/lib/pages/settings_page.dart +++ b/lib/pages/settings_page.dart @@ -114,8 +114,19 @@ class _SettingsPageState extends State { Card( child: ListTile( title: Text('Report Issues'), - subtitle: Text(_url), - onTap: _launchURL, + subtitle: Text(_issueUrl), + onTap: () { + _launchURL(_issueUrl); + }, + ), + ), + Card( + child: ListTile( + title: Text('Donate'), + subtitle: Text(_donateUrl), + onTap: () { + _launchURL(_donateUrl); + }, ), ), SizedBox(height: 10), @@ -135,9 +146,9 @@ class _SettingsPageState extends State { ); } - String _url = 'https://github.com/git-elliot/vernet/issues'; + String _issueUrl = 'https://github.com/git-elliot/vernet/issues'; + String _donateUrl = 'https://github.com/git-elliot/vernet#support-and-donate'; - void _launchURL() async => await canLaunch(_url) - ? await launch(_url) - : throw 'Could not launch $_url'; + void _launchURL(String url) async => + await canLaunch(url) ? await launch(url) : throw 'Could not launch $url'; } diff --git a/lib/ui/wifi_detail.dart b/lib/ui/wifi_detail.dart index c8cfa84a..8775acc9 100644 --- a/lib/ui/wifi_detail.dart +++ b/lib/ui/wifi_detail.dart @@ -1,8 +1,10 @@ import 'dart:io'; import 'package:flutter/material.dart'; +import 'package:flutter_svg/flutter_svg.dart'; import 'package:network_info_plus/network_info_plus.dart'; import 'package:permission_handler/permission_handler.dart'; +import 'package:url_launcher/url_launcher.dart'; import 'package:vernet/api/isp_loader.dart'; import 'package:vernet/models/internet_provider.dart'; import 'package:vernet/models/wifi_info.dart'; @@ -148,29 +150,38 @@ class _WifiDetailState extends State { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - SizedBox(height: 4), - Row( - children: [ - Icon(Icons.public), - SizedBox(width: 8), - Text(snapshot.data!.isp), - ], + CustomTile( + leading: Icon(Icons.public, + color: Theme.of(context).accentColor), + child: Text( + '${snapshot.data!.ip} - ${snapshot.data!.isp}'), ), - SizedBox(height: 4), - Row( - children: [ - Icon(Icons.location_on), - SizedBox(width: 8), - Text(snapshot.data!.location.address), - ], + CustomTile( + leading: SvgPicture.network( + snapshot.data!.location.flagUrl, + height: 18.0, + semanticsLabel: 'Country Flag', + placeholderBuilder: (BuildContext context) => + Container( + height: 18.0, + width: 18.0, + padding: const EdgeInsets.all(3.0), + child: + const CircularProgressIndicator(strokeWidth: 2), + ), + ), + child: Text(snapshot.data!.location.address), ), - SizedBox(height: 4), - // SizedBox(height: 8), - // ElevatedButton.icon( - // onPressed: () {}, - // icon: Icon(Icons.speed), - // label: Text('Test Speed'), - // ) + SizedBox(height: 5), + Divider(height: 3), + SizedBox(height: 10), + ElevatedButton.icon( + onPressed: () { + _launchURL('https://fast.com'); + }, + icon: Icon(Icons.speed), + label: Text('Speed Test'), + ) ], ); } @@ -185,4 +196,27 @@ class _WifiDetailState extends State { ], ); } + + void _launchURL(String url) async => + await canLaunch(url) ? await launch(url) : throw 'Could not launch $url'; +} + +class CustomTile extends StatelessWidget { + const CustomTile({Key? key, required this.leading, required this.child}) + : super(key: key); + + final Widget leading; + final Widget child; + + @override + Widget build(BuildContext context) { + return Column( + children: [ + SizedBox(height: 4), + Row( + children: [leading, SizedBox(width: 8), Expanded(child: child)], + ), + ], + ); + } } diff --git a/pubspec.lock b/pubspec.lock index 9769d0b3..ff3a1286 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -125,6 +125,13 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_svg: + dependency: "direct main" + description: + name: flutter_svg + url: "https://pub.dartlang.org" + source: hosted + version: "0.22.0" flutter_test: dependency: "direct dev" description: flutter @@ -275,6 +282,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0" + path_drawing: + dependency: transitive + description: + name: path_drawing + url: "https://pub.dartlang.org" + source: hosted + version: "0.5.1" + path_parsing: + dependency: transitive + description: + name: path_parsing + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.1" path_provider_linux: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 6f1290b4..9448968a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ 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.0+7 +version: 1.0.0+8 environment: sdk: ">=2.12.0 <3.0.0" @@ -35,6 +35,7 @@ dependencies: url_launcher: ^6.0.6 encrypt: ^5.0.0 crypto: ^3.0.1 + flutter_svg: ^0.22.0 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. @@ -59,7 +60,7 @@ flutter: assets: - ports_lists.json - secrets.json - - ipify.json + - ipwhois.json # - images/a_dot_ham.jpeg # An image asset can refer to one or more resolution-specific "variants", see