Skip to content

Commit

Permalink
adding data connection checker in homescreen too;
Browse files Browse the repository at this point in the history
  • Loading branch information
bugudiramu committed Sep 5, 2019
1 parent f4fa46e commit 63a106d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 11 deletions.
46 changes: 45 additions & 1 deletion lib/ui/articles.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:data_connection_checker/data_connection_checker.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'dart:async';
Expand Down Expand Up @@ -54,7 +55,8 @@ class _AllNewsState extends State<AllNews> with SingleTickerProviderStateMixin {
@override
void initState() {
super.initState();

// Check the internet connectivity
this.checkDataConnectivity();
// **** invoking both api calls when the app started to build ****
this.getData();
this.getAllData();
Expand Down Expand Up @@ -127,6 +129,48 @@ class _AllNewsState extends State<AllNews> with SingleTickerProviderStateMixin {
}
}

Future<void> checkDataConnectivity() async {
// **** Check the connectivity ****
var result = await DataConnectionChecker().hasConnection;
if (result == true) {
print("Connected");
} else {
showDialog(
context: context,
builder: (_) {
return AlertDialog(
semanticLabel: "No Internet Dialog",
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50.0)),
content: Image.asset("images/no_internet.gif"),
title: Column(
children: <Widget>[
Container(
alignment: Alignment.center,
child: Text(
"No Internet",
style: Theme.of(context).textTheme.headline,
),
),
],
),
actions: <Widget>[
FlatButton(
child: Text("Ok"),
onPressed: () {
Navigator.of(context).pop();
Navigator.of(context).pop();
},
)
],
);
});

print('No internet :( Reason:');
print(DataConnectionChecker().lastTryResults);
}
}

@override
Widget build(BuildContext context) {
// **** Default Tab controller ****
Expand Down
18 changes: 8 additions & 10 deletions lib/ui/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ class _LoginState extends State<Login> with SingleTickerProviderStateMixin {
builder: (_) {
return AlertDialog(
semanticLabel: "No Internet Dialog",

shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50.0)),
content: Image.asset("images/no_internet.gif"),
Expand All @@ -248,17 +247,16 @@ class _LoginState extends State<Login> with SingleTickerProviderStateMixin {
style: Theme.of(context).textTheme.headline,
),
),

],
),
// actions: <Widget>[
// FlatButton(
// child: Text("Ok"),
// onPressed: () {
// Navigator.of(context).pop();
// },
// )
// ],
actions: <Widget>[
FlatButton(
child: Text("Ok"),
onPressed: () {
Navigator.of(context).pop();
},
)
],
);
});
/*Alert(
Expand Down

0 comments on commit 63a106d

Please sign in to comment.