flutter_chuck_inspection 1.0.4
flutter_chuck_inspection: ^1.0.4 copied to clipboard
A powerful HTTP inspector for Flutter — monitor, debug, and analyze requests in real-time with a sleek dark UI and persistent notifications.
example/lib/main.dart
import 'package:http/http.dart' as http;
import 'package:flutter/material.dart';
import 'package:dio/dio.dart';
import 'package:flutter_chuck_inspection/flutter_chuck_inspection.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
MyApp({super.key});
@override
Widget build(BuildContext context) {
ChuckInspector().init(
navKey: navigatorKey,
enableNotifications: true,
notificationChannelId: 'chuck_inspector',
notificationChannelName: 'HTTP Inspector',
notificationChannelDescription: 'Shows HTTP request statistics',
);
return MaterialApp(
debugShowCheckedModeBanner: false,
navigatorKey: navigatorKey,
title: 'Chuck Inspector Demo',
theme: ThemeData.dark(),
home: DemoPage(),
);
}
}
class DemoPage extends StatefulWidget {
const DemoPage({super.key});
@override
_DemoPageState createState() => _DemoPageState();
}
class _DemoPageState extends State<DemoPage> {
final Dio dio = Dio();
@override
void initState() {
super.initState();
dio.interceptors.add(ChuckDioInterceptor());
}
Future<void> makeSuccessRequest() async {
try {
await dio.get('https://jsonplaceholder.typicode.com/posts/1');
} catch (e) {
debugPrint(e.toString());
}
}
Future<void> makeErrorRequest() async {
try {
await dio.get('https://jsonplaceholder.typicode.com/invalid-endpoint');
} catch (e) {
debugPrint(e.toString());
}
}
Future<void> fetchUsers() async {
const url = 'https://reqres.in/api/users?page=2';
final http.Client client = ChuckHttpClient(http.Client());
final response = await client.get(
Uri.parse(url),
headers: {
'Content-Type': 'application/json',
'x-api-key': 'reqres-free-v1',
},
);
debugPrint(response.body);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Chuck Inspector Demo')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: makeSuccessRequest,
child: Text('Make Success Request'),
),
SizedBox(height: 16),
ElevatedButton(
onPressed: makeErrorRequest,
style: ElevatedButton.styleFrom(backgroundColor: Colors.red),
child: Text('Make Error Request'),
),
SizedBox(height: 16),
ElevatedButton(
onPressed: fetchUsers,
style: ElevatedButton.styleFrom(backgroundColor: Colors.green),
child: Text('Make Request Http'),
),
SizedBox(height: 32),
ElevatedButton.icon(
onPressed: () => ChuckInspector().showInspector(),
icon: Icon(Icons.bug_report),
label: Text('Open Inspector'),
style: ElevatedButton.styleFrom(
backgroundColor: Color(0xFF6C5CE7),
padding: EdgeInsets.symmetric(horizontal: 32, vertical: 16),
),
),
],
),
),
);
}
}