gits_inspector 0.1.2 gits_inspector: ^0.1.2 copied to clipboard
A simple in-app for GitsHttp inspector. Intercepts and persists all HTTP requests and responses inside your application, and provides a UI for inspecting their content.
import 'package:flutter/material.dart';
import 'package:gits_http/gits_http.dart';
import 'package:gits_inspector/gits_inspector.dart';
final inspector = GitsInspector(
notificationIcon: '@mipmap/ic_launcher',
saveInspectorToLocal: true,
showInspectorOnShake: true,
showNotification: true,
);
final http = GitsHttp(
gitsInspector: inspector,
);
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
super.initState();
inspector.setNavigatorState(Navigator.of(context));
}
bool isLoading = false;
String? error;
Response? response;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'Send HTTP call',
),
if (isLoading)
const CircularProgressIndicator()
else if (response != null || error != null)
Text(
error ?? response?.body ?? '',
style: Theme.of(context).textTheme.bodySmall,
),
const SizedBox(height: 8),
ElevatedButton(
onPressed: () async {
try {
final response = await http.get(
Uri.parse('https://jsonplaceholder.typicode.com/users/1'),
);
setState(() {
this.response = response;
error = null;
});
} on GitsException catch (e) {
setState(() {
error = e.toGitsFailure().toString();
});
} catch (e) {
setState(() {
error = e.toString();
});
}
},
child: const Text('Send HTTP'),
),
],
),
),
);
}
}