nirikshak 0.1.1 nirikshak: ^0.1.1 copied to clipboard
Nirikshak is a lightweight Dio HTTP Inspector tool for Flutter which helps debugging http requests. It's a fork of popular package alice.
import 'dart:io';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:nirikshak/nirikshak.dart';
import 'package:path_provider/path_provider.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
const Brightness brightness = Brightness.dark;
const Color colorSchemeSeed = Colors.blue;
return MaterialApp(
theme: ThemeData(
brightness: brightness,
colorSchemeSeed: colorSchemeSeed,
),
debugShowCheckedModeBanner: false,
home: const HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
late Nirikshak _nirikshak;
late Dio _dio;
@override
void initState() {
super.initState();
_nirikshak = Nirikshak();
_dio = Dio(BaseOptions(followRedirects: false))
..interceptors.add(
_nirikshak.getDioInterceptor(),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Nirikshak HTTP Inspector - Example'),
),
body: Container(
padding: const EdgeInsets.all(16),
child: ListView(
children: [
const SizedBox(height: 8),
_getTextWidget(
'Welcome to example of Nirikshak - Dio HTTP Inspector.'
' Click the button below to generate sample data',
),
ElevatedButton(
onPressed: _runDioRequests,
child: const Text('Run Dio HTTP Requests'),
),
_getTextWidget(
'After clicking on the button above, your request will automatically '
'logged in the Nirikshak. Click the button below to show inspector.',
),
const SizedBox(height: 10),
ElevatedButton(
onPressed: () => _nirikshak.showNirikshak(context),
child: const Text("Show Nirikshak - HTTP Inspector"),
),
],
),
),
);
}
Widget _getTextWidget(String text) {
return Text(
text,
style: const TextStyle(fontSize: 14),
textAlign: TextAlign.center,
);
}
void _runDioRequests() async {
Map<String, dynamic> body = <String, dynamic>{
"title": "foo",
"body": "bar",
"userId": "1"
};
_dio.get<void>(
"https://httpbin.org/redirect-to?url=https%3A%2F%2Fhttpbin.org");
_dio.delete<void>("https://httpbin.org/status/500");
_dio.delete<void>("https://httpbin.org/status/400");
_dio.delete<void>("https://httpbin.org/status/300");
_dio.delete<void>("https://httpbin.org/status/200");
_dio.delete<void>("https://httpbin.org/status/100");
_dio.post<void>("https://jsonplaceholder.typicode.com/posts", data: body);
_dio.get<void>("https://jsonplaceholder.typicode.com/posts",
queryParameters: <String, dynamic>{"test": 1});
_dio.put<void>("https://jsonplaceholder.typicode.com/posts/1", data: body);
_dio.put<void>("https://jsonplaceholder.typicode.com/posts/1", data: body);
_dio.delete<void>("https://jsonplaceholder.typicode.com/posts/1");
_dio.get<void>("http://jsonplaceholder.typicode.com/test/test");
_dio.get<void>("https://jsonplaceholder.typicode.com/photos");
_dio.get<void>(
"https://icons.iconarchive.com/icons/paomedia/small-n-flat/256/sign-info-icon.png");
_dio.get<void>(
"https://images.unsplash.com/photo-1542736705-53f0131d1e98?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80");
_dio.get<void>(
"https://findicons.com/files/icons/1322/world_of_aqua_5/128/bluetooth.png");
_dio.get<void>(
"https://upload.wikimedia.org/wikipedia/commons/4/4e/Pleiades_large.jpg");
_dio.get<void>("http://techslides.com/demos/sample-videos/small.mp4");
_dio.get<void>("https://www.cse.wustl.edu/~jain/cis677-97/ftp/e_3dlc2.pdf");
final directory = await getApplicationDocumentsDirectory();
File file = File("${directory.path}/test.txt");
file.create();
file.writeAsStringSync("123456789");
String fileName = file.path.split('/').last;
FormData formData = FormData.fromMap(<String, dynamic>{
"file": await MultipartFile.fromFile(file.path, filename: fileName),
});
_dio.post<void>("https://jsonplaceholder.typicode.com/photos",
data: formData);
_dio.get<void>("http://dummy.restapiexample.com/api/v1/employees");
}
}