Code refactor
This commit is contained in:
parent
2ee4bdada4
commit
00403a1608
|
|
@ -245,7 +245,7 @@ class AuthRepository {
|
||||||
secret: secret, data: json.encode(data));
|
secret: secret, data: json.encode(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
return await compute<dynamic, dynamic>(SerializationUtils.computeDecode,
|
return await compute<dynamic, dynamic>(SerializationUtils.deserializeWith,
|
||||||
<dynamic>[LoginResponse.serializer, response]);
|
<dynamic>[LoginResponse.serializer, response]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ class ClientRepository {
|
||||||
final dynamic response = await webClient.get(url, credentials.token);
|
final dynamic response = await webClient.get(url, credentials.token);
|
||||||
|
|
||||||
final ClientItemResponse clientResponse = await compute<dynamic, dynamic>(
|
final ClientItemResponse clientResponse = await compute<dynamic, dynamic>(
|
||||||
SerializationUtils.computeDecode,
|
SerializationUtils.deserializeWith,
|
||||||
<dynamic>[ClientItemResponse.serializer, response]);
|
<dynamic>[ClientItemResponse.serializer, response]);
|
||||||
|
|
||||||
return clientResponse.data;
|
return clientResponse.data;
|
||||||
|
|
@ -45,11 +45,19 @@ class ClientRepository {
|
||||||
|
|
||||||
final dynamic response = await webClient.get(url, credentials.token);
|
final dynamic response = await webClient.get(url, credentials.token);
|
||||||
|
|
||||||
final ClientListResponse clientResponse = await compute<dynamic, dynamic>(
|
// Change this
|
||||||
SerializationUtils.computeDecode,
|
final ClientListResponse clientResponse1 =
|
||||||
|
serializers.deserializeWith(ClientListResponse.serializer, response);
|
||||||
|
|
||||||
|
// To this
|
||||||
|
final ClientListResponse clientResponse2 = await compute<dynamic, dynamic>(
|
||||||
|
SerializationUtils.deserializeWith,
|
||||||
<dynamic>[ClientListResponse.serializer, response]);
|
<dynamic>[ClientListResponse.serializer, response]);
|
||||||
|
|
||||||
return clientResponse.data;
|
print(clientResponse1);
|
||||||
|
print(clientResponse2);
|
||||||
|
|
||||||
|
return clientResponse2.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<ClientEntity>> bulkAction(
|
Future<List<ClientEntity>> bulkAction(
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ class CreditRepository {
|
||||||
credentials.token);
|
credentials.token);
|
||||||
|
|
||||||
final InvoiceItemResponse creditResponse = await compute<dynamic, dynamic>(
|
final InvoiceItemResponse creditResponse = await compute<dynamic, dynamic>(
|
||||||
SerializationUtils.computeDecode,
|
SerializationUtils.deserializeWith,
|
||||||
<dynamic>[InvoiceItemResponse.serializer, response]);
|
<dynamic>[InvoiceItemResponse.serializer, response]);
|
||||||
|
|
||||||
return creditResponse.data;
|
return creditResponse.data;
|
||||||
|
|
@ -48,7 +48,7 @@ class CreditRepository {
|
||||||
final dynamic response = await webClient.get(url, credentials.token);
|
final dynamic response = await webClient.get(url, credentials.token);
|
||||||
|
|
||||||
final InvoiceListResponse creditResponse = await compute<dynamic, dynamic>(
|
final InvoiceListResponse creditResponse = await compute<dynamic, dynamic>(
|
||||||
SerializationUtils.computeDecode,
|
SerializationUtils.deserializeWith,
|
||||||
<dynamic>[InvoiceListResponse.serializer, response]);
|
<dynamic>[InvoiceListResponse.serializer, response]);
|
||||||
|
|
||||||
return creditResponse.data;
|
return creditResponse.data;
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ class ExpenseRepository {
|
||||||
'${credentials.url}/expenses/$entityId', credentials.token);
|
'${credentials.url}/expenses/$entityId', credentials.token);
|
||||||
|
|
||||||
final ExpenseItemResponse expenseResponse = await compute<dynamic, dynamic>(
|
final ExpenseItemResponse expenseResponse = await compute<dynamic, dynamic>(
|
||||||
SerializationUtils.computeDecode,
|
SerializationUtils.deserializeWith,
|
||||||
<dynamic>[ExpenseItemResponse.serializer, response]);
|
<dynamic>[ExpenseItemResponse.serializer, response]);
|
||||||
|
|
||||||
return expenseResponse.data;
|
return expenseResponse.data;
|
||||||
|
|
@ -50,7 +50,7 @@ class ExpenseRepository {
|
||||||
final dynamic response = await webClient.get(url, credentials.token);
|
final dynamic response = await webClient.get(url, credentials.token);
|
||||||
|
|
||||||
final ExpenseListResponse expenseResponse = await compute<dynamic, dynamic>(
|
final ExpenseListResponse expenseResponse = await compute<dynamic, dynamic>(
|
||||||
SerializationUtils.computeDecode,
|
SerializationUtils.deserializeWith,
|
||||||
<dynamic>[ExpenseListResponse.serializer, response]);
|
<dynamic>[ExpenseListResponse.serializer, response]);
|
||||||
|
|
||||||
return expenseResponse.data;
|
return expenseResponse.data;
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ class InvoiceRepository {
|
||||||
credentials.token);
|
credentials.token);
|
||||||
|
|
||||||
final InvoiceItemResponse invoiceResponse = await compute<dynamic, dynamic>(
|
final InvoiceItemResponse invoiceResponse = await compute<dynamic, dynamic>(
|
||||||
SerializationUtils.computeDecode,
|
SerializationUtils.deserializeWith,
|
||||||
<dynamic>[InvoiceItemResponse.serializer, response]);
|
<dynamic>[InvoiceItemResponse.serializer, response]);
|
||||||
|
|
||||||
return invoiceResponse.data;
|
return invoiceResponse.data;
|
||||||
|
|
@ -49,7 +49,7 @@ class InvoiceRepository {
|
||||||
final dynamic response = await webClient.get(url, credentials.token);
|
final dynamic response = await webClient.get(url, credentials.token);
|
||||||
|
|
||||||
final InvoiceListResponse invoiceResponse = await compute<dynamic, dynamic>(
|
final InvoiceListResponse invoiceResponse = await compute<dynamic, dynamic>(
|
||||||
SerializationUtils.computeDecode,
|
SerializationUtils.deserializeWith,
|
||||||
<dynamic>[InvoiceListResponse.serializer, response]);
|
<dynamic>[InvoiceListResponse.serializer, response]);
|
||||||
|
|
||||||
return invoiceResponse.data;
|
return invoiceResponse.data;
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ class PaymentRepository {
|
||||||
final dynamic response = await webClient.get(url, credentials.token);
|
final dynamic response = await webClient.get(url, credentials.token);
|
||||||
|
|
||||||
final PaymentItemResponse paymentResponse = await compute<dynamic, dynamic>(
|
final PaymentItemResponse paymentResponse = await compute<dynamic, dynamic>(
|
||||||
SerializationUtils.computeDecode,
|
SerializationUtils.deserializeWith,
|
||||||
<dynamic>[PaymentItemResponse.serializer, response]);
|
<dynamic>[PaymentItemResponse.serializer, response]);
|
||||||
|
|
||||||
return paymentResponse.data;
|
return paymentResponse.data;
|
||||||
|
|
@ -48,7 +48,7 @@ class PaymentRepository {
|
||||||
final dynamic response = await webClient.get(url, credentials.token);
|
final dynamic response = await webClient.get(url, credentials.token);
|
||||||
|
|
||||||
final PaymentListResponse paymentResponse = await compute<dynamic, dynamic>(
|
final PaymentListResponse paymentResponse = await compute<dynamic, dynamic>(
|
||||||
SerializationUtils.computeDecode,
|
SerializationUtils.deserializeWith,
|
||||||
<dynamic>[PaymentListResponse.serializer, response]);
|
<dynamic>[PaymentListResponse.serializer, response]);
|
||||||
|
|
||||||
return paymentResponse.data;
|
return paymentResponse.data;
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ class ProductRepository {
|
||||||
final dynamic response = await webClient.get(url, credentials.token);
|
final dynamic response = await webClient.get(url, credentials.token);
|
||||||
|
|
||||||
final ProductItemResponse productResponse = await compute<dynamic, dynamic>(
|
final ProductItemResponse productResponse = await compute<dynamic, dynamic>(
|
||||||
SerializationUtils.computeDecode,
|
SerializationUtils.deserializeWith,
|
||||||
<dynamic>[ProductItemResponse.serializer, response]);
|
<dynamic>[ProductItemResponse.serializer, response]);
|
||||||
|
|
||||||
return productResponse.data;
|
return productResponse.data;
|
||||||
|
|
@ -45,7 +45,7 @@ class ProductRepository {
|
||||||
final dynamic response = await webClient.get(url, credentials.token);
|
final dynamic response = await webClient.get(url, credentials.token);
|
||||||
|
|
||||||
final ProductListResponse productResponse = await compute<dynamic, dynamic>(
|
final ProductListResponse productResponse = await compute<dynamic, dynamic>(
|
||||||
SerializationUtils.computeDecode,
|
SerializationUtils.deserializeWith,
|
||||||
<dynamic>[ProductListResponse.serializer, response]);
|
<dynamic>[ProductListResponse.serializer, response]);
|
||||||
|
|
||||||
return productResponse.data;
|
return productResponse.data;
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ class ProjectRepository {
|
||||||
'${credentials.url}/projects/$entityId', credentials.token);
|
'${credentials.url}/projects/$entityId', credentials.token);
|
||||||
|
|
||||||
final ProjectItemResponse projectResponse = await compute<dynamic, dynamic>(
|
final ProjectItemResponse projectResponse = await compute<dynamic, dynamic>(
|
||||||
SerializationUtils.computeDecode,
|
SerializationUtils.deserializeWith,
|
||||||
<dynamic>[ProjectItemResponse.serializer, response]);
|
<dynamic>[ProjectItemResponse.serializer, response]);
|
||||||
|
|
||||||
return projectResponse.data;
|
return projectResponse.data;
|
||||||
|
|
@ -47,7 +47,7 @@ class ProjectRepository {
|
||||||
final dynamic response = await webClient.get(url, credentials.token);
|
final dynamic response = await webClient.get(url, credentials.token);
|
||||||
|
|
||||||
final ProjectListResponse projectResponse = await compute<dynamic, dynamic>(
|
final ProjectListResponse projectResponse = await compute<dynamic, dynamic>(
|
||||||
SerializationUtils.computeDecode,
|
SerializationUtils.deserializeWith,
|
||||||
<dynamic>[ProjectListResponse.serializer, response]);
|
<dynamic>[ProjectListResponse.serializer, response]);
|
||||||
|
|
||||||
return projectResponse.data;
|
return projectResponse.data;
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ class QuoteRepository {
|
||||||
credentials.token);
|
credentials.token);
|
||||||
|
|
||||||
final InvoiceItemResponse quoteResponse = await compute<dynamic, dynamic>(
|
final InvoiceItemResponse quoteResponse = await compute<dynamic, dynamic>(
|
||||||
SerializationUtils.computeDecode,
|
SerializationUtils.deserializeWith,
|
||||||
<dynamic>[InvoiceItemResponse.serializer, response]);
|
<dynamic>[InvoiceItemResponse.serializer, response]);
|
||||||
|
|
||||||
return quoteResponse.data;
|
return quoteResponse.data;
|
||||||
|
|
@ -49,7 +49,7 @@ class QuoteRepository {
|
||||||
final dynamic response = await webClient.get(url, credentials.token);
|
final dynamic response = await webClient.get(url, credentials.token);
|
||||||
|
|
||||||
final InvoiceListResponse quoteResponse = await compute<dynamic, dynamic>(
|
final InvoiceListResponse quoteResponse = await compute<dynamic, dynamic>(
|
||||||
SerializationUtils.computeDecode,
|
SerializationUtils.deserializeWith,
|
||||||
<dynamic>[InvoiceListResponse.serializer, response]);
|
<dynamic>[InvoiceListResponse.serializer, response]);
|
||||||
|
|
||||||
return quoteResponse.data;
|
return quoteResponse.data;
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ class TaskRepository {
|
||||||
'${credentials.url}/tasks/$entityId', credentials.token);
|
'${credentials.url}/tasks/$entityId', credentials.token);
|
||||||
|
|
||||||
final TaskItemResponse taskResponse = await compute<dynamic, dynamic>(
|
final TaskItemResponse taskResponse = await compute<dynamic, dynamic>(
|
||||||
SerializationUtils.computeDecode,
|
SerializationUtils.deserializeWith,
|
||||||
<dynamic>[TaskItemResponse.serializer, response]);
|
<dynamic>[TaskItemResponse.serializer, response]);
|
||||||
|
|
||||||
return taskResponse.data;
|
return taskResponse.data;
|
||||||
|
|
@ -49,7 +49,7 @@ class TaskRepository {
|
||||||
final dynamic response = await webClient.get(url, credentials.token);
|
final dynamic response = await webClient.get(url, credentials.token);
|
||||||
|
|
||||||
final TaskListResponse taskResponse = await compute<dynamic, dynamic>(
|
final TaskListResponse taskResponse = await compute<dynamic, dynamic>(
|
||||||
SerializationUtils.computeDecode,
|
SerializationUtils.deserializeWith,
|
||||||
<dynamic>[TaskListResponse.serializer, response]);
|
<dynamic>[TaskListResponse.serializer, response]);
|
||||||
|
|
||||||
return taskResponse.data;
|
return taskResponse.data;
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ class VendorRepository {
|
||||||
credentials.token);
|
credentials.token);
|
||||||
|
|
||||||
final VendorItemResponse vendorResponse = await compute<dynamic, dynamic>(
|
final VendorItemResponse vendorResponse = await compute<dynamic, dynamic>(
|
||||||
SerializationUtils.computeDecode,
|
SerializationUtils.deserializeWith,
|
||||||
<dynamic>[VendorItemResponse.serializer, response]);
|
<dynamic>[VendorItemResponse.serializer, response]);
|
||||||
|
|
||||||
return vendorResponse.data;
|
return vendorResponse.data;
|
||||||
|
|
@ -45,7 +45,7 @@ class VendorRepository {
|
||||||
final dynamic response = await webClient.get(url, credentials.token);
|
final dynamic response = await webClient.get(url, credentials.token);
|
||||||
|
|
||||||
final VendorListResponse vendorResponse = await compute<dynamic, dynamic>(
|
final VendorListResponse vendorResponse = await compute<dynamic, dynamic>(
|
||||||
SerializationUtils.computeDecode,
|
SerializationUtils.deserializeWith,
|
||||||
<dynamic>[VendorListResponse.serializer, response]);
|
<dynamic>[VendorListResponse.serializer, response]);
|
||||||
|
|
||||||
return vendorResponse.data;
|
return vendorResponse.data;
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,11 @@
|
||||||
import 'package:invoiceninja_flutter/data/models/serializers.dart';
|
import 'package:invoiceninja_flutter/data/models/serializers.dart';
|
||||||
|
|
||||||
class SerializationUtils {
|
class SerializationUtils {
|
||||||
static dynamic computeDecode(dynamic list) {
|
static dynamic deserializeWith(dynamic list) {
|
||||||
return serializers.deserializeWith<dynamic>(list[0], list[1]);
|
return serializers.deserializeWith<dynamic>(list[0], list[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static dynamic computeEncode(dynamic list) {
|
static dynamic serializeWith(dynamic list) {
|
||||||
return serializers.serializeWith<dynamic>(list[0], list[1]);
|
return serializers.serializeWith<dynamic>(list[0], list[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue