Skip to content

Commit

Permalink
GeoLocation API updated and speed test added
Browse files Browse the repository at this point in the history
  • Loading branch information
git-elliot committed Jul 6, 2021
1 parent afdb490 commit cb7ac19
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 73 deletions.
2 changes: 1 addition & 1 deletion android/local.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
flutter.versionCode=8
26 changes: 0 additions & 26 deletions assets/ipify.json

This file was deleted.

31 changes: 31 additions & 0 deletions assets/ipwhois.json
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GeoLocation API updated and speed test via browser added
16 changes: 6 additions & 10 deletions lib/api/isp_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -20,8 +18,8 @@ class ISPLoader {
}

Future<InternetProvider> _mimicLoad() async {
return rootBundle.loadStructuredData<InternetProvider>('assets/ipify.json',
(json) async {
return rootBundle.loadStructuredData<InternetProvider>(
'assets/ipwhois.json', (json) async {
return InternetProvider.fromMap(jsonDecode(json));
});
}
Expand All @@ -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));
}
Expand Down
1 change: 1 addition & 0 deletions lib/helper/secret_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
25 changes: 18 additions & 7 deletions lib/models/internet_provider.dart
Original file line number Diff line number Diff line change
@@ -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<String, dynamic> 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<String, dynamic> 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'];
}
23 changes: 17 additions & 6 deletions lib/pages/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,19 @@ class _SettingsPageState extends State<SettingsPage> {
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),
Expand All @@ -135,9 +146,9 @@ class _SettingsPageState extends State<SettingsPage> {
);
}

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';
}
76 changes: 55 additions & 21 deletions lib/ui/wifi_detail.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -148,29 +150,38 @@ class _WifiDetailState extends State<WifiDetail> {
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'),
)
],
);
}
Expand All @@ -185,4 +196,27 @@ class _WifiDetailState extends State<WifiDetail> {
],
);
}

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)],
),
],
);
}
}
21 changes: 21 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit cb7ac19

Please sign in to comment.