Skip to content

Commit fba34a2

Browse files
committed
Still migrating to nullsafety
1 parent a746ff4 commit fba34a2

File tree

5 files changed

+69
-75
lines changed

5 files changed

+69
-75
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
## 2.0.2-dev
12
## 2.0.1-dev
23
## 2.0.0-dev
34
Upgrading to nullsafety

lib/src/rest_client.dart

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,37 +43,28 @@ class RestClient extends FlutterFeathersjs {
4343

4444
dio.interceptors
4545
.add(InterceptorsWrapper(onRequest: (options, handler) async {
46-
// Do something before request is sent
47-
//Adding stored token early with SharedPreferences
46+
// Setting on every request the Bearer Token in the header
4847
var oldToken = await utils.getAccessToken();
4948
dio.options.headers["Authorization"] = "Bearer $oldToken";
50-
return options; //continue
49+
return handler.next(options); //continue
5150
// If you want to resolve the request with some custom data,
52-
// you can return a `Response` object or return `dio.resolve(data)`.
51+
// you can resolve a `Response` object eg: return `dio.resolve(response)`.
5352
// If you want to reject the request with a error message,
54-
// you can return a `DioError` object or return `dio.reject(errMsg)`
55-
}, onResponse: (response, handler) async {
56-
// Do something with response data
57-
return response; // continue
58-
}, onError: (e, handler) async {
53+
// you can reject a `DioError` object eg: return `dio.reject(dioError)`
54+
}, onResponse: (response, handler) {
55+
// Return exactly what response feather send
56+
return handler.next(response); // continue
57+
// If you want to reject the request with a error message,
58+
// you can reject a `DioError` object eg: return `dio.reject(dioError)`
59+
}, onError: (DioError e, handler) {
5960
// Do something with response error
60-
61-
if (e.response != null) {
62-
if (!Foundation.kReleaseMode) {
63-
//Only send the error message from feathers js server not for Dio
64-
print(e.response);
65-
}
66-
67-
return handler.resolve(e.response.data);
68-
//return e.response.data; //continue
69-
} else {
70-
if (!Foundation.kReleaseMode) {
71-
// Something happened in setting up or sending the request that triggered an Error
72-
//By returning null, it means that error is from client
73-
//return null;
74-
}
75-
return e;
61+
if (!Foundation.kReleaseMode) {
62+
//Only send the error message from feathers js server not for Dio
63+
print(e.response);
7664
}
65+
return handler.next(e); //continue
66+
// If you want to resolve the request with some custom data,
67+
// you can resolve a `Response` object eg: return `dio.resolve(response)`.
7768
}));
7869
}
7970

@@ -221,8 +212,8 @@ class RestClient extends FlutterFeathersjs {
221212
try {
222213
response = await this.dio.get("/$serviceName", queryParameters: query);
223214
} catch (e) {
224-
// print("Error in rest::find");
225-
// print(e);
215+
print("Error in rest::find");
216+
print(e);
226217
}
227218
return response;
228219
}
@@ -254,7 +245,7 @@ class RestClient extends FlutterFeathersjs {
254245
///@ `fileFieldName`: the file | files field which must be send to the server
255246
///
256247
///[@var files: a List map of {"filePath": the file path, "fileName": the file ame}]
257-
/// // Or if multiple files
248+
// Or if multiple files
258249
/// var files =
259250
/// [
260251
///

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_feathersjs
22
description: Communicate with your feathers js server from flutter.
3-
version: 2.0.1-dev
3+
version: 2.0.2-dev
44
homepage: https://github.com/Dahkenangnon/flutter_feathersjs.dart
55
repository: https://github.com/Dahkenangnon/flutter_feathersjs.dart
66

test/feathersjs_test.dart

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -22,57 +22,58 @@ void main() async {
2222
/// Auth or reAuth
2323
///
2424
////////////////////////////////////////////////////
25-
// Authenticate user and comment this line
25+
// // Authenticate user and comment this line
2626
var rep = await flutterFeathersjs.authenticate(
27-
strategy: "phone",
28-
userNameFieldName: "tel",
29-
userName: user["tel"],
27+
// strategy: "phone",
28+
// userNameFieldName: "tel",
29+
userName: user["email"],
3030
password: user["password"]);
31-
//Then use this one to reuse access token as it still valide
32-
//var reAuthResp = await flutterFeathersjs.rest.reAuthenticate();
31+
// //Then use this one to reuse access token as it still valide
32+
var reAuthResp = await flutterFeathersjs.reAuthenticate();
3333

34-
////////////////////////////////////////////////////
35-
///
36-
/// Singleton testing
37-
///
38-
////////////////////////////////////////////////////
34+
// print("Hello");
35+
// ////////////////////////////////////////////////////
36+
// ///
37+
// /// Singleton testing
38+
// ///
39+
// ////////////////////////////////////////////////////
3940

40-
// // Singleton pattern if the flutterFeathersjs class
41+
// // // Singleton pattern if the flutterFeathersjs class
4142
// test('Testing singleton ', () {
4243
// FlutterFeathersjs flutterFeathersjs1 = FlutterFeathersjs();
4344
// expect(identical(flutterFeathersjs1, flutterFeathersjs), true);
4445
// });
4546

46-
// // ////////////////////////////////////////////////////
47-
// // ///
48-
// // /// reAuth
49-
// // ////////////////////////////////////////////////////
47+
// // // ////////////////////////////////////////////////////
48+
// // // ///
49+
// // // /// reAuth
50+
// // // ////////////////////////////////////////////////////
5051

51-
// //Testing the authentication method
52+
// // //Testing the authentication method
5253
// test(' reAuthentication method', () async {
53-
// var reps = await flutterFeathersjs.reAuthenticate();
54-
// if (!reps["error"]) {
55-
// print('client is authed');
56-
// print("----------Authed user :------");
57-
// print(reps["message"]);
58-
// print("----------Authed user :------");
59-
// } else if (reps["error_zone"] == Constants.BOTH_CLIENT_AUTHED)
60-
// print("Blabal");
61-
// else {
62-
// print(reps["error_zone"]);
63-
// print(reps["message"]);
64-
// print("frm secktio");
65-
// print(reps["scketResponse"]);
66-
// print("frm rest");
67-
// print(reps["restResponse"]);
68-
// }
54+
// var reps = await flutterFeathersjs.reAuthenticate();
55+
// if (!reps["error"]) {
56+
// print('client is authed');
57+
// print("----------Authed user :------");
58+
// print(reps["message"]);
59+
// print("----------Authed user :------");
60+
// } else if (reps["error_zone"] == Constants.BOTH_CLIENT_AUTHED)
61+
// print("Blabal");
62+
// else {
63+
// print(reps["error_zone"]);
64+
// print(reps["message"]);
65+
// print("frm secktio");
66+
// print(reps["scketResponse"]);
67+
// print("frm rest");
68+
// print(reps["restResponse"]);
69+
// }
6970
// });
7071

71-
// ////////////////////////////////////////////////////
72-
// ///
73-
// /// Rest client methods
74-
// ///
75-
// ///////////////////////////////////////////////////
72+
// // // ////////////////////////////////////////////////////
73+
// // // ///
74+
// // // /// Rest client methods
75+
// // // ///
76+
// // // ///////////////////////////////////////////////////
7677

7778
// test('Testing singleton on Rest client', () {
7879
// RestClient so1 = RestClient()..init(baseUrl: BASE_URL);
@@ -83,11 +84,12 @@ void main() async {
8384
// expect(identical(so1, so2), true);
8485
// });
8586

86-
// test(' \n rest Find all method \n', () async {
87-
// var rep2 = await flutterFeathersjs.rest.find(serviceName: "v1/news");
88-
// print("\n Founds news are: \n");
89-
// print(rep2.data);
90-
// });
87+
test(' \n rest Find all method \n', () async {
88+
var rep2 =
89+
await flutterFeathersjs.rest.find(serviceName: "v1/news", query: {});
90+
print("\n Founds news are: \n");
91+
print(rep2.data['data']);
92+
});
9193

9294
// test(' \n rest find with with query params \n ', () async {
9395
// var rep2 = await flutterFeathersjs.rest.find(
@@ -128,7 +130,6 @@ void main() async {
128130
// serviceName: "v1/news",
129131
// data: data2Send,
130132
// containsFile: true,
131-
// hasSingleFile: true,
132133
// fileFieldName: "file",
133134
// files: files);
134135
// print("\n The new news menu created is: \n");
@@ -168,6 +169,7 @@ void main() async {
168169

169170
// test('find method', () async {
170171
// var rep2 = await flutterFeathersjs.scketio.find(
172+
// query: {},
171173
// serviceName: "v1/news",
172174
// );
173175
// print("Printing news:");

test/fixtures.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//User credentials used for auth purpose
22
Map<String, String> user = {
33
"strategy": "local",
4-
"email": "email@email.com",
5-
"password": "email@email.com",
4+
"email": "ep@ep.com",
5+
"password": "ep@ep.com",
66
"tel": "+229000000"
77
};
88

0 commit comments

Comments
 (0)