Skip to content

Commit

Permalink
Added no internet screen
Browse files Browse the repository at this point in the history
  • Loading branch information
tanweer919 committed Jul 29, 2020
1 parent 4b2d3fe commit fe9d23f
Show file tree
Hide file tree
Showing 15 changed files with 259 additions and 70 deletions.
10 changes: 10 additions & 0 deletions ios/Flutter/Generated 26.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This is a generated file; do not edit or check into version control.
FLUTTER_ROOT=/Users/tanweeranwar/Downloads/flutter/flutter
FLUTTER_APPLICATION_PATH=/Users/tanweeranwar/Documents/flutter/sportsmojo
FLUTTER_TARGET=lib/main.dart
FLUTTER_BUILD_DIR=build
SYMROOT=${SOURCE_ROOT}/../build/ios
OTHER_LDFLAGS=$(inherited) -framework Flutter
FLUTTER_FRAMEWORK_DIR=/Users/tanweeranwar/Downloads/flutter/flutter/bin/cache/artifacts/engine/ios
FLUTTER_BUILD_NAME=1.0.0
FLUTTER_BUILD_NUMBER=1
10 changes: 10 additions & 0 deletions ios/Flutter/Generated 27.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This is a generated file; do not edit or check into version control.
FLUTTER_ROOT=/Users/tanweeranwar/Downloads/flutter/flutter
FLUTTER_APPLICATION_PATH=/Users/tanweeranwar/Documents/flutter/sportsmojo
FLUTTER_TARGET=lib/main.dart
FLUTTER_BUILD_DIR=build
SYMROOT=${SOURCE_ROOT}/../build/ios
OTHER_LDFLAGS=$(inherited) -framework Flutter
FLUTTER_FRAMEWORK_DIR=/Users/tanweeranwar/Downloads/flutter/flutter/bin/cache/artifacts/engine/ios
FLUTTER_BUILD_NAME=1.0.0
FLUTTER_BUILD_NUMBER=1
11 changes: 11 additions & 0 deletions ios/Flutter/flutter_export_environment 26.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/tanweeranwar/Downloads/flutter/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/tanweeranwar/Documents/flutter/sportsmojo"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "OTHER_LDFLAGS=$(inherited) -framework Flutter"
export "FLUTTER_FRAMEWORK_DIR=/Users/tanweeranwar/Downloads/flutter/flutter/bin/cache/artifacts/engine/ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
11 changes: 11 additions & 0 deletions ios/Flutter/flutter_export_environment 27.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/tanweeranwar/Downloads/flutter/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/tanweeranwar/Documents/flutter/sportsmojo"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "OTHER_LDFLAGS=$(inherited) -framework Flutter"
export "FLUTTER_FRAMEWORK_DIR=/Users/tanweeranwar/Downloads/flutter/flutter/bin/cache/artifacts/engine/ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
37 changes: 37 additions & 0 deletions lib/commons/CustomRaisedButton.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:flutter/material.dart';

class CustomRaisedButton extends StatelessWidget {
String label;
bool inProgress;
VoidCallback onPressed;
double height, minWidth;
CustomRaisedButton(
{this.label,
this.inProgress = false,
this.height,
this.minWidth,
this.onPressed});
@override
Widget build(BuildContext context) {
return ButtonTheme(
height: height,
minWidth: minWidth,
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(20.0),
),
color: Theme.of(context).primaryColor,
child: inProgress
? CircularProgressIndicator(
valueColor:
new AlwaysStoppedAnimation<Color>(Color(0xfff5f5f5)),
)
: Text(
'$label',
style: TextStyle(color: Colors.white),
),
onPressed: onPressed,
),
);
}
}
63 changes: 35 additions & 28 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:sportsmojo/models/User.dart';
import 'start.dart';
import 'package:provider/provider.dart';
import 'Provider/AppProvider.dart';
Expand All @@ -8,38 +9,44 @@ import 'services/GetItLocator.dart';
import 'services/LocalStorage.dart';
import 'services/FirebaseService.dart';
import 'services/RemoteConfigService.dart';
void main() async{
import 'package:data_connection_checker/data_connection_checker.dart';
import 'screens/NoInternetScreen.dart';

void main() async {
final ThemeData theme = ThemeData(
primaryColor: Color(0xFF50C878),
primaryColorDark: Color(0XFFA0A5AA)
);
primaryColor: Color(0xFF50C878), primaryColorDark: Color(0XFFA0A5AA));
WidgetsFlutterBinding.ensureInitialized();
await setupLocator();
final leagueName = await LocalStorage.getString('leagueName');
User currentUser = null;
FirebaseService firebaseService = locator<FirebaseService>();
final RemoteConfigService _remoteConfigService = locator<RemoteConfigService>();
await _remoteConfigService.initialise();
final currentUser = await firebaseService.getCurrentUser();
AppProvider appProvider = locator<AppProvider>(param1: leagueName, param2: currentUser);
final RemoteConfigService _remoteConfigService =
locator<RemoteConfigService>();
final result = await DataConnectionChecker().hasConnection;
if (result) {
await _remoteConfigService.initialise();
currentUser = await firebaseService.getCurrentUser();
}

AppProvider appProvider =
locator<AppProvider>(param1: leagueName, param2: currentUser);

runApp(
MultiProvider(
providers: [
ChangeNotifierProvider(
create: (context) => appProvider,
)
],
child: FlutterEasyLoading(
child: MaterialApp(
debugShowCheckedModeBanner: false,
theme: theme,
home: Start(),
onGenerateRoute: Router().generateRoutes,
navigatorObservers: [
HeroController()
],
),
runApp(MultiProvider(
providers: [
ChangeNotifierProvider(
create: (context) => appProvider,
)
],
child: FlutterEasyLoading(
child: MaterialApp(
debugShowCheckedModeBanner: false,
theme: theme,
home: WillPopScope(
onWillPop: () => Future.value(false),
child: result ? Start() : NoInternetScreen()),
onGenerateRoute: Router().generateRoutes,
navigatorObservers: [HeroController()],
),
)
);
}
),
));
}
25 changes: 8 additions & 17 deletions lib/screens/DashboardScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import '../commons/custom_icons.dart';
import '../services/LocalStorage.dart';
import '../services/FirestoreService.dart';
import '../constants.dart';
import '../commons/CustomRaisedButton.dart';

class DashboardScreen extends StatefulWidget {
@override
Expand Down Expand Up @@ -107,25 +108,15 @@ class _DashboardScreenState extends State<DashboardScreen> {
)
],
),
ButtonTheme(
CustomRaisedButton(
height: 30,
minWidth: 75,
child: RaisedButton(
color: Theme.of(context).primaryColor,
shape: RoundedRectangleBorder(
borderRadius:
new BorderRadius.circular(15.0),
),
onPressed: () async {
await firebaseService.signOutGoogle();
model.currentUser = null;
},
child: Text(
'Logout',
style: TextStyle(
color: Colors.white, fontSize: 14),
),
),
label: 'Logout',
onPressed: () async {
await firebaseService.signOutGoogle();
model.currentUser = null;
},
inProgress: false,
)
],
),
Expand Down
107 changes: 107 additions & 0 deletions lib/screens/NoInternetScreen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../start.dart';
import 'package:data_connection_checker/data_connection_checker.dart';
import 'package:flushbar/flushbar.dart';
import '../services/GetItLocator.dart';
import '../services/RemoteConfigService.dart';
import '../services/FirebaseService.dart';
import '../commons/CustomRaisedButton.dart';
import '../Provider/AppProvider.dart';

class NoInternetScreen extends StatefulWidget {
@override
_NoInternetScreenState createState() => _NoInternetScreenState();
}

class _NoInternetScreenState extends State<NoInternetScreen> {
FirebaseService firebaseService = locator<FirebaseService>();
final RemoteConfigService _remoteConfigService =
locator<RemoteConfigService>();
bool inProgress = false;
@override
Widget build(BuildContext context) {
final appProvider = Provider.of<AppProvider>(context);
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: Container(
width: MediaQuery.of(context).size.width * 0.6,
child: Image.asset('assets/images/nointernet.png'),
),
),
Padding(
padding: const EdgeInsets.only(top:8.0, bottom: 4.0),
child: Text(
"No internet available",
style: TextStyle(
fontSize: 24,
color: Colors.black,
fontWeight: FontWeight.w500),
),
),
Padding(
padding: const EdgeInsets.only(bottom: 8.0, left: 14.0, right: 14.0),
child: Text(
"You are offline. Please turn on your mobile data to get updates.",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 18,
color: Theme.of(context).primaryColorDark,
fontWeight: FontWeight.w300),
),
),
CustomRaisedButton(
label: 'Refresh',
minWidth: 100,
height: 40,
inProgress: inProgress,
onPressed: () async{
setState(() {
inProgress = true;
});
bool result = await DataConnectionChecker().hasConnection;

if(result == true) {
await _remoteConfigService.initialise();
final currentUser = await firebaseService.getCurrentUser();
appProvider.currentUser = currentUser;
setState(() {
inProgress = false;
});
Navigator.of(context).pushReplacement(new MaterialPageRoute(
builder: (context) => Start()));
}
else {
setState(() {
inProgress = false;
});
Flushbar(
icon: Icon(
Icons.error,
size: 35,
color: Colors.white,
),
title: "Error",
message: 'You are offline',
flushbarPosition: FlushbarPosition.TOP,
backgroundColor: Colors.red,
duration: Duration(seconds: 3),
flushbarStyle: FlushbarStyle.FLOATING,
showProgressIndicator: true,
progressIndicatorBackgroundColor: Colors.white,
).show(context);
}
},
)
],
),
),
);
}
}
3 changes: 3 additions & 0 deletions lib/services/CustomRouter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import '../screens/LeagueTableScreen.dart';
import '../screens/DashboardScreen.dart';
import '../screens/FavouriteScreen1.dart';
import '../screens/IntroductionScreen.dart';
import '../start.dart';

class Router {
Route<dynamic> generateRoutes(RouteSettings settings) {
final List<String> validRoutes = [
'/start',
'/home',
'/score',
'/league',
Expand Down Expand Up @@ -59,6 +61,7 @@ class Router {
}
}
Map<String, Widget> screens = {
'/start': Start(),
'/home': HomeScreen(
message: favouriteTeamMessage,
),
Expand Down
2 changes: 1 addition & 1 deletion lib/services/HttpService.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class HttpService {
BaseOptions options = new BaseOptions(headers: {
'x-rapidapi-host': 'v3.football.api-sports.io',
'x-rapidapi-key': _remoteConfigService.getString(key: 'scoreApiKey')
}, baseUrl: 'https://v3.football.api-sports.io/');
}, baseUrl: _remoteConfigService.getString(key: 'scoreUrl'));
final _dio = new Dio(options);
return _dio;
}
Expand Down
3 changes: 1 addition & 2 deletions lib/services/NewsService.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ class NewsService {
List<News> newsList = [];
try {
final response = await dio.get(
'https://aniket.cognitiveservices.azure.com/bing/v7.0/news/search',
_remoteConfigService.getString(key: 'newsUrl'),
queryParameters: {
'q': query,
'mkt': 'en-GB',
'originalImg': 'true',
'count': '100',
'freshness': 'week',
Expand Down
4 changes: 3 additions & 1 deletion lib/services/RemoteConfigService.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class RemoteConfigService {
final Map<String, dynamic> defaults = {
'season': 2019,
'scoreApiKey': "",
'newsApiKey': ""
'newsApiKey': "",
'scoreUrl': "",
'newsUrl': ""
};
await _remoteConfig.setDefaults(defaults);
await _remoteConfig.fetch(expiration: Duration(hours: 1));
Expand Down
Loading

0 comments on commit fe9d23f

Please sign in to comment.