Skip to content

Commit

Permalink
http operation comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Anas Iqbal committed Jun 5, 2021
1 parent f243f18 commit 6f40624
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/fakeApis/fake_api_class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class FakeApiClass {
// Cetrgory API
Future<dynamic> getFoodCategories() async {
await Future.delayed(const Duration(seconds: 5));

/// if I were using real api would have verified the response first if it was 200 < 300 then would continue else I would have thrown error if http code was 400 - 500 and usually i have make exception handler classes for this for even when thorwing the error reading the error key after understanding form backend
String resp =
"{\"foodCategories\":[{\"name\":\"https:\/\/images.unsplash.com\/photo-1560717869-37296557a131?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2850&q=80\",\"image\":\"Asian\"},{\"name\":\"https:\/\/images.unsplash.com\/photo-1565299624946-b28f40a0ae38?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=828&q=80\",\"image\":\"Italian\"},{\"name\":\"https:\/\/images.unsplash.com\/photo-1570466199120-80bba1eabad7?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80\",\"image\":\"Maxican\"},{\"name\":\"https:\/\/images.unsplash.com\/photo-1526318896980-cf78c088247c?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=668&q=80\",\"image\":\"Chinnese\"},{\"name\":\"https:\/\/images.unsplash.com\/photo-1499028344343-cd173ffc68a9?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1350&q=80\",\"image\":\"Fast Food\"},{\"name\":\"https:\/\/images.unsplash.com\/photo-1484980972926-edee96e0960d?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=668&q=80\",\"image\":\"Turkish\"}]}";
var result = jsonDecode(resp);
Expand All @@ -13,6 +15,8 @@ class FakeApiClass {
Future<dynamic> getFoodDetails() async {
await Future.delayed(const Duration(seconds: 5));
return getFoodDetailFakeResp();

/// if I were using real api would have verified the response first if it was 200 < 300 then would continue else I would have thrown error if http code was 400 - 500 and usually i have make exception handler classes for this for even when thorwing the error reading the error key after understanding form backend
}

dynamic getFoodDetailFakeResp() {
Expand Down
1 change: 1 addition & 0 deletions lib/screens/home/home_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class HomeController extends GetxController {
var resp = await _foodService.getFoodCategory();
listCategories.value = resp.foodCategories;
} catch (e) {
// this is where when I throw exception from api class this is where i handle the msg and show dialog or do some operation on the bassis of error code
//ExceptionHandler(e);
} finally {
isLoading(false);
Expand Down

0 comments on commit 6f40624

Please sign in to comment.