You can see app, network logs to help your debugging 🐞
Test Screen | App Log Screen |
---|---|
Client Log Screen | Intergrated Log Screen |
Add dependency to pubspec.yaml
dependencies:
...
flutter_logger: ^1.0.0
Run in your terminal
flutter pub get
import 'package:flutter_logger/flutter_logger.dart';
// ...
// add FlutterLogger() to your top of you app in any child
chidren: [
// ...
/* REQUIRED */
FlutterLogger(),
// ...
]
// for app logs
// when error occurs in your application, you can see app logs
// for network logs
void didChangeDependencies() {
super.didChangeDependencies();
WidgetsBinding.instance.addPostFrameCallback((_) {
// network log case 1
// then call clientLogger.${method}('url', {data, ...})
clientLogger.get('exampleURL');
// ...
// network log case 2
// or make your own dio communication method just by insert ClientLogIntercepter()
doDioCommunication('exampleURL2', data: "data");
});
}
// ...
void doDioCommunication(String url, {data}) async {
final dio = Dio()
..interceptors.add(
/* REQUIRED */
// insert ClientLogInterCeptor() here!!!
ClientLogInterceptor(),
);
DateTime requestTime = DateTime.now().toLocal();
var request = HttpRequestModel(
requestTime,
dio.options.method,
dio.options.baseUrl + url,
dio.options.queryParameters,
dio.options.headers,
data,
);
try {
Response response = await dio.request(
url,
data: data,
queryParameters: dio.options.queryParameters,
options: Options(method: 'POST'),
);
DateTime responseTime = DateTime.now().toLocal();
response.headers['date']?[0] = responseTime.toString();
/* REQUIRED */
// make httpModel and get OutputCallbacks here
var httpModel = HttpModel(request, response);
Set<OutputCallback> outputCallbacks = ClientLogEvent.getOutputCallbacks;
// for showing in app
// add httpModel to outputCallbacks
for (var callback in outputCallbacks) {
callback(httpModel);
}
/* */
} on DioError catch (error) {
// must write here to see error debug too
// make httpModel and get OutputCallbacks here
var httpModel =
HttpModel(request, error.response, errorType: error.type.name);
Set<OutputCallback> outputCallbacks = ClientLogEvent.getOutputCallbacks;
// for showing in app
// add httpModel to outputCallbacks
for (var callback in outputCallbacks) {
callback(httpModel);
}
}
// other error handling
on Error catch (error) {
debugPrint(error as String);
}
}
More see at
MIT License
Copyright (c) 2022 Geonyeol Ryu