forked from jhomlala/catcher
-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1b99b9
commit 139e455
Showing
7 changed files
with
90 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,27 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:catcher_2/core/application_profile_manager.dart'; | ||
import 'package:dio/dio.dart'; | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:universal_io/io.dart'; | ||
|
||
class Catcher2Utils { | ||
/// From https://stackoverflow.com/a/56959146/5894824 | ||
static Future<bool> isInternetConnectionAvailable() async { | ||
try { | ||
final result = await InternetAddress.lookup('google.com'); | ||
return result.isNotEmpty && result[0].rawAddress.isNotEmpty; | ||
} catch (exception) { | ||
return false; | ||
if (ApplicationProfileManager.isWeb()) { | ||
return true; // TODO(HyperSpeeed): We could in theory handle this maybe? | ||
} else { | ||
try { | ||
final result = await InternetAddress.lookup('google.com'); | ||
return result.isNotEmpty && result[0].rawAddress.isNotEmpty; | ||
} catch (_) {} | ||
} | ||
return false; | ||
} | ||
|
||
static bool isCupertinoAppAncestor(BuildContext context) => | ||
context.findAncestorWidgetOfExactType<CupertinoApp>() != null; | ||
} | ||
|
||
/// From https://stackoverflow.com/a/70282800/5894824 | ||
extension IsOk on Response { | ||
bool get ok => statusCode != null && (statusCode! ~/ 100) == 2; | ||
} |