dio_http_logger

Pub Version

A powerful network interceptor for Dio, providing comprehensive logging of requests, responses and errors.

:zap: Screenshots

Screenshot 1 Screenshot 1 Screenshot 1 Screenshot 1 Screenshot 1

:zap:Features

  • Detailed Logging: Log request method, URL, headers, query parameters, request body, response status code, headers, request time, response time, request data size, response data size and response body.
  • Error stack-trace: Stack trace data directly from Dio in error requests.
  • Easy Integration: Add the interceptor to your Dio instance with just a few lines of code.

:zap:Installation

Add dio_http_logger to your pubspec.yaml file:

 dio: ">=4.0.0 <6.0.0" //use the latest version, 5.6.0 was my latest, old version user DioError instead of DioException.  
 ..... 
 dio_http_logger: ^latest_version

:zap:Getting Started

  1. Add DioNetworkLogger.instance.dioNetworkInterceptor to your dio object/instances.
final client = Dio(); 
client.interceptors.add(DioNetworkLogger.instance.dioNetworkInterceptor!);  
  1. Set the context for internal navigation on application start or naigation start.
DioNetworkLogger.instance.context = context;  
  1. Use DioNetworkLogger.instance.overLayButtonWidget widget to direct navigate to the library (Use it at the root view of your application, this will make the button appear in every screen).
runApp(    
    MaterialApp(    
      home: Stack(    
        children: [    
          const MyApp(),    
          DioNetworkLogger.instance.overLayButtonWidget  
		 ],      
	 ),    
    ) 
);  
  1. Or you can use DioNetworkLogger.instance.startNetworkLoggerScreen() to direct navigate to the library
//Use it on any callback  
onPressed: () {  
 DioNetworkLogger.instance.context = context; 
 DioNetworkLogger.instance.startNetworkLoggerScreen(); 
 },  

:zap:Push notification (Optional)

This is an optional feature. If you want to get local push notification when the network request is triggered or any response comes from the server.

Screenshot 1 Screenshot 1
  1. Initialize the notification.
void main() async{  
   ....
  WidgetsFlutterBinding.ensureInitialized();;  
  await DioNetworkLogger.instance.initLocalNotifications();  
  runApp(  
      ..... 
  );  
}
  1. For ios configure your AppDelegate
//other imports
import flutter_local_notifications
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {

    FlutterLocalNotificationsPlugin.setPluginRegistrantCallback { (registry) in
    GeneratedPluginRegistrant.register(with: registry)}
    GeneratedPluginRegistrant.register(with: self)
	if #available(iOS 10.0, *) {
       UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
    }
    return super.application(application,didFinishLaunchingWithOptions:launchOptions)
  }
}

NOTE: Used the flutter_local_notifications: ^17.2.2 plugin. If you find any issues, try to follow the documentation of flutter_local_notifications and dont forget to throw an issue in github.

Libraries

dio_logger