v1.0.16 utf8 decoding

This commit is contained in:
Tibor Bossanyi 2023-03-19 19:14:48 +01:00
parent f2f70a6db9
commit 27299ed266
5 changed files with 34 additions and 16 deletions

4
.gitignore vendored
View File

@ -28,5 +28,5 @@ migrate_working_dir/
.packages
build/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
/.flutter-plugins
/.flutter-plugins-dependencies

View File

@ -1,5 +1,8 @@
Workout Test and Diet 4 You Common Util Functions
Version 1.0.16
Webapi utf8 decode
Version 1.0.15
AppText and translations

View File

@ -24,10 +24,7 @@ class APIWebClient with Common, Logging {
var url = "${baseUrl}authenticate";
try {
final body = jsonEncode(<String, String>{
'username': email,
'password': password
});
final body = jsonEncode(<String, String>{'username': email, 'password': password});
var uri = Uri.parse(url);
var result = await http.post(uri, body: body, headers: {
"Content-Type": "application/json",
@ -78,7 +75,7 @@ class APIWebClient with Common, Logging {
} else {
throw Exception("Network Error, please try again later");
}
} on NotFoundException catch(e) {
} on NotFoundException catch (e) {
throw NotFoundException(message: "Not Found ${e.message}");
} on Exception catch (e) {
log("Post Exception: $e");
@ -100,18 +97,21 @@ class APIWebClient with Common, Logging {
var uri = Uri.parse(url);
var result = await http.get(uri, headers: {
"Content-Type": "application/json",
//"Accept-Charset": 'utf-8',
"Authorization": 'Bearer $authToken',
});
log(" ------------get response code: ${result.statusCode}");
if (result.statusCode == 200) {
return result.body;
List<int> bytes = result.body.codeUnits;
String decodedString = utf8.decode(bytes);
return decodedString;
} else if (result.statusCode == 404) {
throw const NotFoundException(message: "Not Found");
} else {
throw Exception("Network Error, please try again later");
}
} on NotFoundException catch(e) {
} on NotFoundException catch (e) {
throw NotFoundException(message: "Not Found ${e.message}");
} on Exception catch (e) {
log("Post Exception: $e");
@ -119,5 +119,4 @@ class APIWebClient with Common, Logging {
throw Exception("Network Error, please try again later");
}
}
}

View File

@ -1,6 +1,6 @@
name: workouttest_util
description: Workout Test app and web functions.
version: 1.0.15
version: 1.0.16
environment:
sdk: ">=2.18.6 <3.0.0"

View File

@ -1,3 +1,5 @@
import 'dart:convert';
import 'package:flutter_test/flutter_test.dart';
import 'package:workouttest_util/model/cache.dart';
import 'package:workouttest_util/service/api.dart';
@ -9,7 +11,6 @@ main() {
});
group('api', () {
test('connect api auth successfully', () async {
var api = APIClient();
var responseJson = await api.authenticateUser("bosi", "andio2009");
@ -27,5 +28,20 @@ main() {
final body = await api.get("app_package", "");
print(body);
});
test('test customer conversation in utf8', () async {
var api = APIWebClient();
var responseJson = await api.authenticateUser("bosi", "andio2009");
print(responseJson);
Cache().authToken = responseJson['token'];
final body = await api.get("customer_conversation/72", "");
List<int> bytes3 = base64.decode(body);
String decodedString = utf8.decode(bytes3);
print(decodedString);
final body2 = await api.get("meal/21", "");
print(body2);
});
});
}