diff --git a/lib/features/card/business_logic_layer/card_controller.dart b/lib/features/card/business_logic_layer/card_controller.dart index 72e8922..b1ca00a 100644 --- a/lib/features/card/business_logic_layer/card_controller.dart +++ b/lib/features/card/business_logic_layer/card_controller.dart @@ -66,7 +66,7 @@ class CardController extends GetxController { RxFuture favoriteState = RxFuture(null); Future toggleFavorite(int id, bool removeFromFavorite, - {void Function(void)? onSuccess}) async { + {void Function(void)? onSuccess, void Function(Object)? onError}) async { List temp = cardState.result.data; for (int i = 0; i < temp.length; i++) { if (temp[i].id == id) { @@ -87,7 +87,7 @@ class CardController extends GetxController { removeFromFavorite ? await cardService.removeFromFavorite(id) : await cardService.addToFavorite(id); - }, onSuccess: onSuccess); + }, onSuccess: onSuccess, onError: onError); } ///-------------my cards------------/// diff --git a/lib/features/card/presentation_layer/widgets/favorite.dart b/lib/features/card/presentation_layer/widgets/favorite.dart index c7ecd7f..fadf31c 100644 --- a/lib/features/card/presentation_layer/widgets/favorite.dart +++ b/lib/features/card/presentation_layer/widgets/favorite.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:get/get.dart'; import 'package:taafee_mobile/common/extensions/widget_extension.dart'; +import 'package:taafee_mobile/common/widgets/toast.dart'; import 'package:taafee_mobile/features/auth/business_logic_layer/auth_controller.dart'; import 'package:taafee_mobile/features/card/business_logic_layer/card_controller.dart'; import 'package:taafee_mobile/features/card/data_layer/model/card_model.dart'; @@ -102,6 +103,12 @@ class FavoriteWidget extends StatelessWidget { favoriteController.toggleFavoriteCard(cardModel.id); cardController.toggleFavorite(cardModel.id, true, onSuccess: (val) { // favoriteController.getFavorites(); + }, onError: (err) { + if (err.toString() == 'You Have no Internet Connection') { + Toast.showToast('no_internert_connection'.tr); + } else { + Toast.showToast('unknown_error'.tr); + } }); }); } else { @@ -117,6 +124,12 @@ class FavoriteWidget extends StatelessWidget { cardController.toggleFavorite(cardModel.id, false, onSuccess: (val) { // favoriteController.getFavorites(); + }, onError: (err) { + if (err.toString() == 'You Have no Internet Connection') { + Toast.showToast('no_internert_connection'.tr); + } else { + Toast.showToast('unknown_error'.tr); + } }); }); }