I'm using Chopper for http request on Flutter and as far as I know, there are two ways of creating a Chopper Client. One is adding services to its array and then expose it:
// my_chopper_client.dart
static ChopperClient getClient() {
final chopper = ChopperClient(
baseUrl: "https://example.com/",
services: [
ServiceOne.create(),
ServiceTwo.create(),
ServiceThree.create()
],
converter: JsonConverter()
);
return chopper;
}
// Some other file.dart
void login() {
ChopperClient client = MyChopperClient.getClient();
var serviceTwo = client.getService<ServiceTwo>();
var resp = await serviceTwo({"email": "[email protected]", "password": "123"});
print(resp.body);
}
And the other one is create a new instance of a Chopper client for each service:
// service_two.dart
static ServiceTwo create() {
final client = ChopperClient(
services: [
_$ServiceTwo(),
],
converter: JsonConverter(),
);
return _$ServiceTwo(client);
}
// some other file.dart
void login() async {
var serviceTwo = ServiceTwo.create();
var resp = await serviceTwo.login({"email": "[email protected]", "password": "123"});
print(resp.body);
}
My question is: Which way is better to get the best performance? It seems to me that the array approach may use more memory. Thanks in advance!