Skip to content

Commit

Permalink
hive,Flutter local notification, connectivity.
Browse files Browse the repository at this point in the history
  • Loading branch information
Moktadir authored and Moktadir committed Aug 8, 2023
1 parent 5e8ee2c commit cf10c93
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
8 changes: 4 additions & 4 deletions lib/app/components/custom_snackbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class CustomSnackBar {
Get.snackbar(
title,
message,
duration: duration ?? const Duration(milliseconds: 1500),
duration: duration ?? const Duration(milliseconds: 3000),
margin: const EdgeInsets.only(top: 10, left: 10, right: 10),
colorText: Colors.white,
backgroundColor: Colors.green,
Expand All @@ -26,7 +26,7 @@ class CustomSnackBar {
Get.snackbar(
title,
message,
duration: duration ?? const Duration(milliseconds: 1500),
duration: duration ?? const Duration(milliseconds: 3000),
margin: const EdgeInsets.only(top: 10, left: 10, right: 10),
colorText: Colors.white,
backgroundColor: color ?? Colors.redAccent,
Expand All @@ -44,7 +44,7 @@ class CustomSnackBar {
Duration? duration}) {
Get.rawSnackbar(
title: title,
duration: duration ?? const Duration(milliseconds: 1500),
duration: duration ?? const Duration(milliseconds: 3000),
snackStyle: SnackStyle.GROUNDED,
backgroundColor: color ?? Colors.green,
onTap: (snack) {
Expand All @@ -62,7 +62,7 @@ class CustomSnackBar {
Duration? duration}) {
Get.rawSnackbar(
title: title,
duration: duration ?? const Duration(milliseconds: 1500),
duration: duration ?? const Duration(milliseconds: 3000),
snackStyle: SnackStyle.GROUNDED,
backgroundColor: color ?? Colors.redAccent,
onTap: (snack) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class HomeController extends GetxController with ExceptionHandler {

getPostList() async {
showLoading();

if (await NetworkConnectivity.isNetworkAvailable()) {
// Fetch posts from the API

var response =
await DioClient().get(url: ApiUrl.allPosts).catchError(handleError);

Expand All @@ -37,18 +37,24 @@ class HomeController extends GetxController with ExceptionHandler {
hideLoading();
} else {
// If offline, try to load from Hive
CustomSnackBar.showCustomToast(message: "No network!");

var posts = MyHive.getAllPosts();

if (posts.isNotEmpty) {
// Use posts from Hive if available
postList.assignAll(posts);

hideLoading();
CustomSnackBar.showCustomErrorToast(message: "No network!");
return;
} else {
isError.value = true;

hideLoading();
showErrorDialog("Oops!", "Connection problem");
return;
}
}
hideLoading();
}

@override
Expand Down

0 comments on commit cf10c93

Please sign in to comment.