Boa tarde!
Quando executo o código utilizando um endereço de IP não valido, igual o professor fez no video, o meu timeout retorna o seguinte erro:
TimeoutException (TimeoutException after 0:00:05.000000: Future not completed)
Alguem teve esse problema?
import 'dart:async';
import 'dart:convert';
import 'package:bytebank/models/contact.dart';
import 'package:bytebank/models/transaction.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:http_interceptor/http_interceptor.dart';
class LoggingInterceptor implements InterceptorContract {
@override
Future<RequestData> interceptRequest({required RequestData data}) async {
debugPrint('--> REQUEST');
debugPrint('URL : ${data.baseUrl}');
debugPrint('HEADERS : ${data.headers}');
debugPrint('BODY : ${data.body}');
return data;
}
@override
Future<ResponseData> interceptResponse({required ResponseData data}) async {
debugPrint('\n--> RESPONSE');
debugPrint('STATUS CODE : ${data.statusCode}');
debugPrint('HEADERS : ${data.headers}');
debugPrint('BODY : ${data.body}');
return data;
}
}
Future<List<Transaction>> findAll() async {
String url = 'http://19.168.70.102:8080/transactios';
final Client client =
InterceptedClient.build(interceptors: [LoggingInterceptor()]);
final Response response =
await client.get(Uri.parse(url)).timeout(const Duration(seconds: 5));
final List<Transaction> transactions = [];
if (response.statusCode == 200) {
final List<dynamic> decodedJson = jsonDecode(response.body);
for (Map<String, dynamic> element in decodedJson) {
transactions.add(
Transaction(
element['value'],
Contact(
0,
element['contact']['name'],
element['contact']['accountNumber'],
),
),
);
}
return transactions;
}
return transactions;
}