1
resposta

erro ao adicionar o transactions.add(transaction) (Compiler message: lib/http/webclient.dart:46:22: Error: The argument type 'Transaction' can't be assigned to the parameter type 'TransactionsList'. })

Poderiam me ajudar a resolver este erro, por favor? Abaixo webclient.dart

import 'dart:convert';

import 'package:http/http.dart';
import 'package:http_interceptor/http_interceptor.dart';
import 'package:minhasegundavia/models/contact.dart';
import 'package:minhasegundavia/models/transaction.dart';
import 'package:minhasegundavia/screens/transactions_list.dart';

class LoggingInterceptor implements InterceptorContract {
  @override
  Future<RequestData> interceptRequest({RequestData data}) async {
    print('Request');
    print('url: ${data.url}');
    print('headers: ${data.headers}');
    print('body: ${data.body}');
    return data;
  }

  @override
  Future<ResponseData> interceptResponse({ResponseData data}) async {
    print('Response');
    print('status code: ${data.statusCode}');
    print('headers: ${data.headers}');
    print('body: ${data.body}');
    return data;
  }
}

Future<List<Transaction>> findAll() async {
  final Client client =
      HttpClientWithInterceptor.build(interceptors: [LoggingInterceptor()]);
  final Response response =
      await client.get('http://192.168.0.11:8080/transactions');
  final List<dynamic> decodedJson = jsonDecode(response.body);
  final List<TransactionsList> transactions = List();
  for (Map<String, dynamic> transactionJson in decodedJson) {
    final Map<String, dynamic> contactJson = transactionJson['contact'];
    final Transaction transaction = Transaction(
      transactionJson['value'],
      Contact(
        0,
        contactJson['name'],
        contactJson['accountNumber'],
      ),
    );
    transactions.add(transaction); //Compiler message:
lib/http/webclient.dart:46:22: Error: The argument type 'Transaction' can't be assigned to the parameter type 'TransactionsList'.
  }
  return transactions; // Error: A value of type 'List<TransactionsList>' can't be assigned to a variable of type 'FutureOr<List<Transaction>>'.
}
1 resposta

Oi, tudo bem ?

Cara eu vi que sua dúvida é um pouco antiga, será que tu já resolveu ? Se sim pode compartilhar conosco ?