Created
November 24, 2022 04:38
-
-
Save thuycom205/96dbf12358893027ff0a11912d719ecd to your computer and use it in GitHub Desktop.
acfc
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
import 'dart:convert'; | |
import 'package:flutter/cupertino.dart'; | |
import 'package:http/http.dart' as http; | |
import 'package:magenest_store/constants/constants.dart'; | |
import 'package:magenest_store/models/customer/review.dart'; | |
import 'package:shared_preferences/shared_preferences.dart'; | |
import '../../service_locator.dart'; | |
import '../shared_service.dart'; | |
import '../web_service.dart'; | |
class MyReviewService extends WebService { | |
String reviewData = "/V1/mobileapi/customers/reviews"; | |
Map<String, String> _defaultHeaders = { | |
'Content-Type': 'application/json', | |
}; | |
ShareService shareService = locator.get<ShareService>(); | |
Future<List<Reviews>> fetchDataReviewData() async { | |
var token = await shareService.retrieveCustomerToken(); | |
String url = WebService.getInstance().apiEndpoint + reviewData; | |
// get from sing | |
var requestHeaders = Map<String, String>.from(_defaultHeaders); | |
requestHeaders.addAll({'Authorization': 'Bearer $token'}); | |
final response = await http.get( | |
Uri.parse(url), | |
headers: requestHeaders, | |
); | |
this.handleResponseException(response); | |
List<Reviews> _review = []; | |
List responseJson = json.decode(response.body); | |
if (responseJson[0].length > 0) { | |
responseJson[0].forEach((k, v) { | |
_review.add(Reviews.fromJson(v)); | |
}); | |
return _review; | |
} else { | |
return _review; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment