network_console 0.0.4
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(),
),
);
},
),
],
),
),
);
}
}