network_console 0.0.4 copy "network_console: ^0.0.4" to clipboard
network_console: ^0.0.4 copied to clipboard

A comprehensive network consoling kit for Dio and Http with unified logging and a built-in on-device UI viewer.

example/lib/main.dart

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:network_console/network_console.dart';

void main() {
  runApp(const MaterialApp(home: MyApp()));
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("Network Inspector Example")),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            // --- SCENARIO A: Using Dio ---
            ElevatedButton(
              onPressed: () async {
                final dio = Dio();
                dio.interceptors.add(NetworkConsoleDio()); // Add interceptor

                try {
                  await dio.get('https://jsonplaceholder.typicode.com/todos/1');
                  print('Dio Request Completed');
                } catch (e) {
                  print(e);
                }
              },
              child: const Text("Make Dio Request"),
            ),
            const SizedBox(height: 20),

            // --- SCENARIO B: Using Http ---
            ElevatedButton(
              onPressed: () async {
                final client = NetworkConsoleHttp(); // Use wrapper client

                try {
                  await client.get(Uri.parse(
                      'https://jsonplaceholder.typicode.com/todos/2'));
                  print('Http Request Completed');
                } finally {
                  client.close();
                }
              },
              child: const Text("Make Http Request"),
            ),
            const SizedBox(height: 40),

            // --- SCENARIO C: Viewing Logs (UI) ---
            ElevatedButton.icon(
              icon: const Icon(Icons.history),
              label: const Text("Open Inspector UI"),
              style: ElevatedButton.styleFrom(
                backgroundColor: Colors.blue[100],
                foregroundColor: Colors.blue[900],
              ),
              onPressed: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (context) => const NetworkConsoleLogs(),
                  ),
                );
              },
            ),
          ],
        ),
      ),
    );
  }
}
1
likes
160
points
174
downloads

Publisher

unverified uploader

Weekly Downloads

A comprehensive network consoling kit for Dio and Http with unified logging and a built-in on-device UI viewer.

Homepage

Topics

#network #debugging #logging #dio #http

Documentation

API reference

License

MIT (license)

Dependencies

dio, flutter, http, intl, uuid

More

Packages that depend on network_console