Após executar o findAll() os logs de request aparecem, mas o de response não. Depois de algum tempo log de erro é exibido no console:
webclient.dart
import 'package:http/http.dart';
import 'package:http_interceptor/http_interceptor.dart';
final String baseUrl = 'http://192.168.0.6:8080/';
// final String baseUrl = 'http://localhost:8080/';
class LoggingInterceptor implements InterceptorContract {
@override
Future<RequestData> interceptRequest({RequestData data}) async {
print('Request');
print('url: ${data.url}');
print('headers: ${data.headers}');
return data;
}
@override
Future<ResponseData> interceptResponse({ResponseData data}) async {
print('Response');
print('headers: ${data.headers}');
print('body: ${data.body}');
print('status code: ${data.statusCode}');
return data;
}
}
void findAll() async {
Client client = HttpClientWithInterceptor.build(
interceptors: [
LoggingInterceptor(),
],
);
final Response response = await client.get('${baseUrl}transactions');
}
main.dart
import 'package:bytebank/screens/dashboard.dart';
import 'package:flutter/material.dart';
import 'package:bytebank/http/webclient.dart';
void main() {
runApp(BytebankApp());
findAll();
}
class BytebankApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primaryColor: Colors.green[900],
accentColor: Colors.blueAccent[700],
buttonTheme: ButtonThemeData(
buttonColor: Colors.blueAccent[700],
textTheme: ButtonTextTheme.primary,
),
),
home: Dashboard(),
);
}
}
Debug Console
Restarted application in 3.674ms.
I/flutter (14204): Request
I/flutter (14204): url: http://192.168.0.6:8080/transactions
I/flutter (14204): headers: {}
E/flutter (14204): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: SocketException: OS Error: Connection timed out, errno = 110, address = 192.168.0.6, port = 39916
E/flutter (14204):
No chrome, o retorno é o seguinte (http://192.168.0.6:8080/transactions):
[
{
"id": "c1c7bc51-30c8-4471-84dd-fcb75279020a",
"value": 200.00,
"contact": {
"name": "gui",
"accountNumber": 1000
},
"dateTime": "2021-03-26 14:25:36"
}
]