Skip to content

Commit

Permalink
Merge pull request #2 from aseef17/aseef17/master
Browse files Browse the repository at this point in the history
API Changes, UI Fixes and Offline Caching
  • Loading branch information
aseef17 authored Apr 20, 2020
2 parents 7a03aed + 3d71ba4 commit 45b875c
Show file tree
Hide file tree
Showing 46 changed files with 2,430 additions and 486 deletions.
Binary file modified assets/images/latest-numbers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/myth-busters.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/symptoms.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
PODS:
- connectivity (0.0.1):
- Flutter
- Reachability
- connectivity_macos (0.0.1):
- Flutter
- Flutter (1.0.0)
- FMDB (2.7.5):
- FMDB/standard (= 2.7.5)
Expand All @@ -7,6 +12,7 @@ PODS:
- Flutter
- path_provider_macos (0.0.1):
- Flutter
- Reachability (3.2)
- sqflite (0.0.1):
- Flutter
- FMDB (~> 2.7.2)
Expand All @@ -18,6 +24,8 @@ PODS:
- Flutter

DEPENDENCIES:
- connectivity (from `.symlinks/plugins/connectivity/ios`)
- connectivity_macos (from `.symlinks/plugins/connectivity_macos/ios`)
- Flutter (from `Flutter`)
- path_provider (from `.symlinks/plugins/path_provider/ios`)
- path_provider_macos (from `.symlinks/plugins/path_provider_macos/ios`)
Expand All @@ -29,8 +37,13 @@ DEPENDENCIES:
SPEC REPOS:
trunk:
- FMDB
- Reachability

EXTERNAL SOURCES:
connectivity:
:path: ".symlinks/plugins/connectivity/ios"
connectivity_macos:
:path: ".symlinks/plugins/connectivity_macos/ios"
Flutter:
:path: Flutter
path_provider:
Expand All @@ -47,10 +60,13 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/url_launcher_web/ios"

SPEC CHECKSUMS:
connectivity: 6e94255659cc86dcbef1d452ad3e0491bb1b3e75
connectivity_macos: e2e9731b6b22dda39eb1b128f6969d574460e191
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
path_provider: fb74bd0465e96b594bb3b5088ee4a4e7bb1f2a9d
path_provider_macos: f760a3c5b04357c380e2fddb6f9db6f3015897e0
Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96
sqflite: 4001a31ff81d210346b500c55b17f4d6c7589dd0
url_launcher: a1c0cc845906122c4784c542523d8cacbded5626
url_launcher_macos: fd7894421cd39320dce5f292fc99ea9270b2a313
Expand Down
2 changes: 2 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleDarkContent</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
Expand Down
4 changes: 4 additions & 0 deletions lib/constants/strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class Strings {

static const preventionTitle = 'Prevention';

static const symptomsTitle = 'Symptoms';

static const mythBusterTitle = 'Myth Busters';

/// ------------------------------------------------------
/// Font Styles for Statistics and StatisticsLoadingWidget
/// used in (ui/statistics) and (ui/statistics/widgets)
Expand Down
12 changes: 11 additions & 1 deletion lib/constants/text_styles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TextStyles {

/// ------------------------------------------------------
/// Font Styles for Statistics Screen
/// used in (ui/statistics)
/// used in (ui/statistics) and (ui/statistics/widgets)
///
static const statisticsHeadingTextStlye = TextStyle(
fontWeight: FontWeight.w700,
Expand All @@ -64,6 +64,16 @@ class TextStyles {
color: AppColors.offBlackColor,
);

static const statisticsLabelTextStyle = TextStyle(
fontWeight: FontWeight.w500,
color: AppColors.accentBlackColor,
);

static const statisticsToopTipTextStyle = TextStyle(
fontWeight: FontWeight.w500,
color: AppColors.whiteColor,
);

/// ------------------------------------------------------
/// Font Styles for Home Screen
/// used in (ui/home)
Expand Down
5 changes: 0 additions & 5 deletions lib/data/countries_list_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -542,11 +542,6 @@ const countriesListJSON = '''
"ISO2": "LV"
},
{
"Country": "Netherlands Antilles",
"Slug": "netherlands-antilles",
"ISO2": "AN"
},
{
"Country": "Peru",
"Slug": "peru",
"ISO2": "PE"
Expand Down
17 changes: 3 additions & 14 deletions lib/data/network/constants/endpoints.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@ class Endpoints {
// base url
static const baseUrlStatistics = "https://api.covid19api.com";

// base url to retreieve user's IP
static const baseUrlIP = "https://httpbin.org/ip";

// base url to retrive iso2 code based on IP
static const baseUrlCurrentCountry = 'https://freegeoip.live/json';

// base url to retrieve country flags
static const baseUrlCountryFlags = 'https://www.countryflags.io/';
// base url to retreieve user's country ISO2 code
static const baseUrlIPLookup = "https://ip.rootnet.in/lookup";

// base url for Covid-19 prevention Infographic
static const baseUrlPreventionInfographic =
Expand All @@ -38,10 +32,5 @@ class Endpoints {

static String get fetchCountryStatistics =>
baseUrlStatistics + _fetchCountryStatistics;

static String get fetchIP => baseUrlIP;

static String get fetchCurrentCountry => baseUrlCurrentCountry;

static String get fetchCountryFlags => baseUrlCountryFlags;
static String get fetchCurrentCountry => baseUrlIPLookup;
}
7 changes: 1 addition & 6 deletions lib/data/repository/base_repository.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:covid19/models/application/ip_model.dart';
import 'package:covid19/models/application/country_information_model.dart';
import 'package:covid19/models/statistics/countries_list_model.dart';
import 'package:covid19/models/statistics/statistics_response_model.dart';
Expand All @@ -10,12 +9,8 @@ import 'package:covid19/models/statistics/country_statistics_day_model.dart';
/// [TestRepository] and [UserRepository] extend the BaseRepository
/// to override and implement the API requests
abstract class BaseRepository {
/// Fetch List of all countries
Future<IPModel> fetchUserIP();

/// Fetch Current Country iso2 for the user
Future<CountryInformationModel> fetchUserCountryInformation(
{@required String ipAddress});
Future<CountryInformationModel> fetchUserCountryInformation();

/// Fetch List of all countries
Future<List<Countries>> fetchCountriesList();
Expand Down
13 changes: 2 additions & 11 deletions lib/data/repository/test_repository.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:covid19/data/repository/base_repository.dart';
import 'package:covid19/models/application/ip_model.dart';
import 'package:covid19/models/application/country_information_model.dart';
import 'package:covid19/models/statistics/countries_list_model.dart';
import 'package:covid19/models/statistics/country_statistics_day_model.dart';
Expand All @@ -15,22 +14,14 @@ class TestRepository implements BaseRepository {
await Future.delayed(const Duration(milliseconds: 1000));
}

@override
Future<IPModel> fetchUserIP() async {
_wait();
return IPModel(
origin: "103.69.21.105",
);
}

@override
Future<CountryInformationModel> fetchUserCountryInformation({
@required String ipAddress,
}) async {
_wait();
return CountryInformationModel(
countryName: "India",
countryCode: "IN",
ip: "127.0.0.1",
country: "IN",
);
}

Expand Down
24 changes: 6 additions & 18 deletions lib/data/repository/user_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
import 'package:covid19/data/countries_list_data.dart';
import 'package:covid19/data/network/constants/endpoints.dart';
import 'package:covid19/data/repository/base_repository.dart';
import 'package:covid19/models/application/ip_model.dart';
import 'package:covid19/models/statistics/statistics_response_model.dart';
import 'package:covid19/models/application/country_information_model.dart';
import 'package:covid19/models/statistics/countries_list_model.dart';
Expand All @@ -12,26 +11,13 @@ import 'package:covid19/utils/request_util.dart';

/// Extends the [BaseRepository] to implement the API request methods
class UserRepository implements BaseRepository {
@override
Future<IPModel> fetchUserIP() async {
final jsonResponse = await HttpRequestUtil.getRequest(
Endpoints.fetchIP,
);

HttpRequestUtil.handleResponseError(
jsonResponse,
'Error fetching User\'s IP',
);

return IPModel.fromJson(jsonResponse);
}

@override
Future<CountryInformationModel> fetchUserCountryInformation({
@required String ipAddress,
}) async {
final jsonResponse = await HttpRequestUtil.getRequest(
'${Endpoints.fetchCurrentCountry}/$ipAddress',
url: '${Endpoints.fetchCurrentCountry}',
shouldCache: false,
);

HttpRequestUtil.handleResponseError(
Expand All @@ -53,7 +39,8 @@ class UserRepository implements BaseRepository {
@required String iso2,
}) async {
final jsonResponse = await HttpRequestUtil.getRequest(
'${Endpoints.fetchHomeData}',
url: '${Endpoints.fetchHomeData}',
shouldCache: true,
);

HttpRequestUtil.handleResponseError(
Expand All @@ -70,7 +57,8 @@ class UserRepository implements BaseRepository {
CountryStatistics countryStatistics;

final responseMap = await HttpRequestUtil.getRequest(
'${Endpoints.fetchCountryStatistics}$iso2/status/confirmed',
url: '${Endpoints.fetchCountryStatistics}$iso2/status/confirmed',
shouldCache: true,
);

for (int i = 0; i < responseMap.length; i++) {
Expand Down
23 changes: 0 additions & 23 deletions lib/icons/covid19_icons.dart
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
/// Flutter icons Covid19
/// Copyright (C) 2020 by original authors @ fluttericon.com, fontello.com
/// This font was generated by FlutterIcon.com, which is derived from Fontello.
///
/// To use this font, place it in your fonts/ directory and include the
/// following in your pubspec.yaml
///
/// flutter:
/// fonts:
/// - family: Covid19
/// fonts:
/// - asset: fonts/Covid19.ttf
///
///
/// * Material Design Icons, Copyright (C) Google, Inc
/// Author: Google
/// License: Apache 2.0 (https://www.apache.org/licenses/LICENSE-2.0)
/// Homepage: https://design.google.com/icons/
/// * Entypo, Copyright (C) 2012 by Daniel Bruce
/// Author: Daniel Bruce
/// License: SIL (http://scripts.sil.org/OFL)
/// Homepage: http://www.entypo.com
///
import 'package:flutter/widgets.dart';

class Covid19Icons {
Expand Down
24 changes: 10 additions & 14 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:bloc/bloc.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:provider/provider.dart';
import 'package:covid19/constants/app_theme.dart';
import 'package:covid19/constants/colors.dart';
import 'package:covid19/constants/strings.dart';
Expand All @@ -13,10 +17,7 @@ import 'package:covid19/ui/static/static_error_screen.dart';
import 'package:covid19/utils/bloc/application_bloc.dart';
import 'package:covid19/utils/bloc/application_events.dart';
import 'package:covid19/utils/bloc/application_state.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:provider/provider.dart';
import 'package:covid19/utils/connection_status_singleton.dart';

/// [SimpleBloocDelegate] handles all the Bloc events delegated by the [BlocSupervisor]
class SimpleBlocDelegate extends BlocDelegate {
Expand Down Expand Up @@ -46,6 +47,11 @@ Future<void> main() async {

// Initialize WidgetsBinding before runApp
WidgetsFlutterBinding.ensureInitialized();

final ConnectionStatusSingleton connectionStatus =
ConnectionStatusSingleton.getInstance();
connectionStatus.initialize();

SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]).then(
Expand Down Expand Up @@ -107,16 +113,6 @@ class MyApp extends StatelessWidget {
userRepository: repository,
),
child: Scaffold(
// [AppBar] with 0 size used to set the statusbar background color and
// statusbat text/icon color
appBar: PreferredSize(
preferredSize: const Size.fromHeight(0.0),
child: AppBar(
backgroundColor: AppColors.whiteColor,
brightness: Brightness.light,
elevation: 0.0,
),
),
body: HomeNavigator(),
),
);
Expand Down
47 changes: 4 additions & 43 deletions lib/models/application/country_information_model.dart
Original file line number Diff line number Diff line change
@@ -1,57 +1,18 @@
/// [Json2Dart](https://javiercbk.github.io/json_to_dart/) was used to generate the model class
class CountryInformationModel {
String ip;
String countryCode;
String countryName;
String regionCode;
String regionName;
String city;
String zipCode;
String timeZone;
double latitude;
double longitude;
int metroCode;
String country;

CountryInformationModel(
{this.ip,
this.countryCode,
this.countryName,
this.regionCode,
this.regionName,
this.city,
this.zipCode,
this.timeZone,
this.latitude,
this.longitude,
this.metroCode});
CountryInformationModel({this.ip, this.country});

CountryInformationModel.fromJson(Map<String, dynamic> json) {
ip = json['ip'] as String;
countryCode = json['country_code'] as String;
countryName = json['country_name'] as String;
regionCode = json['region_code'] as String;
regionName = json['region_name'] as String;
city = json['city'] as String;
zipCode = json['zip_code'] as String;
timeZone = json['time_zone'] as String;
latitude = json['latitude'] as double;
longitude = json['longitude'] as double;
metroCode = json['metro_code'] as int;
country = json['country'] as String;
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = Map<String, dynamic>();
data['ip'] = ip;
data['country_code'] = countryCode;
data['country_name'] = countryName;
data['region_code'] = regionCode;
data['region_name'] = regionName;
data['city'] = city;
data['zip_code'] = zipCode;
data['time_zone'] = timeZone;
data['latitude'] = latitude;
data['longitude'] = longitude;
data['metro_code'] = metroCode;
data['country'] = country;
return data;
}
}
Loading

0 comments on commit 45b875c

Please sign in to comment.