requests_inspector 1.0.1+4 copy "requests_inspector: ^1.0.1+4" to clipboard
requests_inspector: ^1.0.1+4 copied to clipboard

outdated

A Flutter package for logging API requests and accessing it by Shaking your phone to get the RequestsInspector widget on your screen.

requests_inspector 🕵 #

A Flutter package for logging API requests and accessing it by Shaking your phone to get the RequestsInspector widget on your screen.

First, add it at the top of your MaterialApp with enabled: true. #

void main() {
  runApp(const RequestsInspector(
    enabled: true,
    child: MyApp(),
  ));
}

Note: Don't forget to enable it!

Then, on your API request add a new RequestDetails using RequestInspectorController filled with the API data. #

InspectorController().addNewRequest(
    RequestDetails(
        requestName: requestName,
        requestMethod: RequestMethod.GET,
        url: apiUrl,
        statusCode: responseStatusCode,
        responseBody: responseData,
        sentTime: DateTime.now(),
        ),
    );

Real example #

Future<List<Post>> fetchPosts() async {
  final dio = Dio();
  final response = await dio.get('https://jsonplaceholder.typicode.com/posts');

  final postsMap = response.data as List;
  final posts = postsMap.map((postMap) => Post.fromMap(postMap)).toList();

  InspectorController().addNewRequest(
    RequestDetails(
      requestName: 'Posts',
      requestMethod: RequestMethod.GET,
      url: 'https://jsonplaceholder.typicode.com/posts',
      statusCode: response.statusCode ?? 0,
      responseBody: response.data,
      sentTime: DateTime.now(),
    ),
  );

  return posts;
}

Finlay, Shake your phone to get the Inspector #

We are done 🎉️ 😁️

95
likes
0
pub points
91%
popularity

Publisher

verified publisherabdelazeem-kuratem.engineer

A Flutter package for logging API requests and accessing it by Shaking your phone to get the RequestsInspector widget on your screen.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

dio, flutter, provider, shake

More

Packages that depend on requests_inspector