favorite functionality exception handling
This commit is contained in:
parent
2133544b56
commit
52882c621c
|
|
@ -66,7 +66,7 @@ class CardController extends GetxController {
|
|||
|
||||
RxFuture<void> favoriteState = RxFuture(null);
|
||||
Future<void> toggleFavorite(int id, bool removeFromFavorite,
|
||||
{void Function(void)? onSuccess}) async {
|
||||
{void Function(void)? onSuccess, void Function(Object)? onError}) async {
|
||||
List<CardModel> 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------------///
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user