alice 0.0.24

  • Readme
  • Changelog
  • Example
  • Installing
  • 94

Alice #

pub package pub package pub package

Alice is an HTTP Inspector tool for Flutter which helps debugging http requests. It catches and stores http requests and responses, which can be viewed via simple UI. It is inspired from Chuck ( https://github.com/jgilfelt/chuck ).

Suported Dart http client plugins:

  • Dio
  • HttpClient from dart:io package
  • Http from http/http package
  • Chopper

Features:
✔️ Detailed logs for each HTTP calls (HTTP Request, HTTP Response)
✔️ Inspector UI for viewing HTTP calls
✔️ Save HTTP calls to file
✔️ Statistics
✔️ Notification on HTTP call
✔️ Support for top used HTTP clients in Dart
✔️ Error handling
✔️ Shake to open inspector

Install #

  1. Add this to your pubspec.yaml file:
dependencies:
  alice: ^0.0.23
  1. Install it
$ flutter packages get
  1. Import it
import 'package:alice/alice.dart';

Usage #

Alice configuration #

Create Alice instance:

Alice alice = Alice(showNotification: true);

Alice default behaviour is to show notification with http requests. You can disable it in Alice constructor.

Add navigator key to your application:

MaterialApp( navigatorKey: alice.getNavigatorKey(), home: ...)

You need to add this navigator key in order to show inspector UI. You can use also your navigator key in Alice:

Alice alice = Alice(showNotification: true, navigatorKey: yourNavigatorKeyHere);

You can set showInspectorOnShake in Alice constructor to open inspector by shaking your device (default disabled):

Alice alice = Alice(showNotification: true, showInspectorOnShake: true, navigatorKey: yourNavigatorKeyHere);

If you want to use dark mode just add darkTheme flag:

Alice alice = Alice(..., darkTheme: true);

HTTP Client configuration #

If you're using Dio, you just need to add interceptor.

Dio dio = Dio();
dio.interceptors.add(alice.getDioInterceptor());

If you're using HttpClient from dart:io package:

httpClient
	.getUrl(Uri.parse("https://jsonplaceholder.typicode.com/posts"))
	.then((request) async {
		alice.onHttpClientRequest(request);
		var httpResponse = await request.close();
		var responseBody = await httpResponse.transform(utf8.decoder).join();
		alice.onHttpClientResponse(httpResponse, request, body: responseBody);
 });

If you're using http from http/http package:

http.get('https://jsonplaceholder.typicode.com/posts').then((response) {
    alice.onHttpResponse(response);
});

If you're using Chopper. you need to add interceptor:

chopper = ChopperClient(
    interceptors: alice.getChopperInterceptor(),
);

To show inspector manually:

alice.showInspector();

Saving calls #

Alice supports saving logs to your mobile device storage. In order to make save feature works, you need to add in your Android application manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Extensions #

You can use extensions to shorten your http and http client code. This is optional, but may improve your codebase. Example:

  1. Import:
import 'package:alice/core/alice_http_client_extensions.dart';
import 'package:alice/core/alice_http_extensions.dart';
  1. Use extensions:
http
    .post('https://jsonplaceholder.typicode.com/posts', body: body)
    .interceptWithAlice(alice, body: body);
httpClient
    .postUrl(Uri.parse("https://jsonplaceholder.typicode.com/posts"))
    .interceptWithAlice(alice, body: body, headers: Map());

Example #

See complete example here: https://github.com/jhomlala/alice/blob/master/example/lib/main.dart

0.0.24 #

  • Updated dependencies
  • Prepare for 1.0.0 version of sensors and package_info. (dart_lsc)

0.0.23 #

  • Updated to dart 2.6.0
  • Added AliceHttpExtensions, AliceHttpClientExtensions

0.0.22 #

  • Updated dependencies
  • Refactored response page. If response is image or video, Alice will show it in response page. Large body outputs will be not shown by default. There is a "Show body" button to show large output.

0.0.21 #

  • Added Chopper support
  • Added AndroidX support

0.0.20 #

  • Updated dependencies

0.0.19 #

  • Updated dependencies

0.0.18 #

  • Added share option in call details. Share allows user to share curl of the request. (by: Praveenkumar Ramasamy https://github.com/pravinarr)

0.0.17 #

0.0.16 #

  • Fixed server text overflow

0.0.15 #

  • Updated dependencies

0.0.14 #

  • Fixed Dio API breaking change

0.0.13 #

  • Updated dependencies
  • Notification won't init when showNotification is off

0.0.12 #

  • Updated flutter local notification dependency version
  • Refactor

0.0.11 #

0.0.10 #

  • Added stats feature
  • Added save feature
  • Added secured/not secured connection indicator in call list item
  • Query parameters feature (Dio only)
  • Fix for Uint8List SDK breaking change
  • Updated dependencies
  • Refactored code

0.0.6 #

  • Fixed http/http package requests

0.0.5 #

  • Updated dependencies
  • Navigator key can be provided now from application (instead of using Alice's navigator key)

0.0.4 #

  • Updated Kotlin version

0.0.3 #

  • Removed gif from package

0.0.2 #

  • Bug fixes

0.0.1 #

  • Initial release

example/lib/main.dart

import 'dart:convert';
import 'dart:io';
import 'package:alice/alice.dart';
import 'package:alice_example/posts_service.dart';
import 'package:chopper/chopper.dart';
import 'package:http/http.dart' as http;
import 'package:alice/core/alice_http_client_extensions.dart';
import 'package:alice/core/alice_http_extensions.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  Alice alice;
  Dio dio;
  HttpClient httpClient;
  ChopperClient chopper;
  PostsService postsService;

  @override
  void initState() {
    alice = Alice(
        showNotification: true, showInspectorOnShake: true, darkTheme: true);
    dio = Dio();
    dio.interceptors.add(alice.getDioInterceptor());
    httpClient = HttpClient();
    chopper = ChopperClient(
      interceptors: alice.getChopperInterceptor(),
    );
    postsService = PostsService.create(chopper);

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorKey: alice.getNavigatorKey(),
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Alice HTTP Inspector example'),
        ),
        body: Center(
            child:
                Column(mainAxisAlignment: MainAxisAlignment.center, children: [
          RaisedButton(
            child: Text("Run HTTP Requests"),
            onPressed: _runHttpRequests,
          ),
          RaisedButton(
            child: Text("Run HTTP Insepctor"),
            onPressed: _runHttpInspector,
          )
        ])),
      ),
    );
  }

  void _runChopperHttpRequests() async {
    Map<String, dynamic> body = {"title": "foo", "body": "bar", "userId": "1"};
    postsService.getPost("1");
    postsService.postPost(body);
    postsService.putPost("1", body);
    postsService.putPost("1231923", body);
    postsService.putPost("1", null);
    postsService.postPost(null);
    postsService.getPost("123456");
  }

  void _runHttpRequests() async {
    _runChopperHttpRequests();
    Map<String, dynamic> body = {"title": "foo", "body": "bar", "userId": "1"};

    http
        .post('https://jsonplaceholder.typicode.com/posts', body: body)
        .interceptWithAlice(alice, body: body);

    http
        .get('https://jsonplaceholder.typicode.com/posts')
        .interceptWithAlice(alice);

    http
        .put('https://jsonplaceholder.typicode.com/posts/1', body: body)
        .interceptWithAlice(alice, body: body);

    http
        .patch('https://jsonplaceholder.typicode.com/posts/1', body: body)
        .interceptWithAlice(alice, body: body);

    http
        .delete('https://jsonplaceholder.typicode.com/posts/1')
        .interceptWithAlice(alice, body: body);

    http
        .get('https://jsonplaceholder.typicode.com/test/test')
        .interceptWithAlice(alice);

    http
        .post('https://jsonplaceholder.typicode.com/posts', body: body)
        .then((response) {
      alice.onHttpResponse(response, body: body);
    });

    http.get('https://jsonplaceholder.typicode.com/posts').then((response) {
      alice.onHttpResponse(response);
    });

    http
        .put('https://jsonplaceholder.typicode.com/posts/1', body: body)
        .then((response) {
      alice.onHttpResponse(response, body: body);
    });

    http
        .patch('https://jsonplaceholder.typicode.com/posts/1', body: body)
        .then((response) {
      alice.onHttpResponse(response, body: body);
    });

    http
        .delete('https://jsonplaceholder.typicode.com/posts/1')
        .then((response) {
      alice.onHttpResponse(response);
    });

    http.get('https://jsonplaceholder.typicode.com/test/test').then((response) {
      alice.onHttpResponse(response);
    });

    httpClient
        .getUrl(Uri.parse("https://jsonplaceholder.typicode.com/posts"))
        .interceptWithAlice(alice);

    httpClient
        .postUrl(Uri.parse("https://jsonplaceholder.typicode.com/posts"))
        .interceptWithAlice(alice, body: body, headers: Map());

    httpClient
        .putUrl(Uri.parse("https://jsonplaceholder.typicode.com/posts/1"))
        .interceptWithAlice(alice, body: body);

    httpClient
        .getUrl(Uri.parse("https://jsonplaceholder.typicode.com/test/test/"))
        .interceptWithAlice(alice);

    httpClient
        .postUrl(Uri.parse("https://jsonplaceholder.typicode.com/posts"))
        .then((request) async {
      alice.onHttpClientRequest(request, body: body);
      request.write(body);
      var httpResponse = await request.close();
      var responseBody = await utf8.decoder.bind(httpResponse).join();
      alice.onHttpClientResponse(httpResponse, request, body: responseBody);
    });

    httpClient
        .putUrl(Uri.parse("https://jsonplaceholder.typicode.com/posts/1"))
        .then((request) async {
      alice.onHttpClientRequest(request, body: body);
      request.write(body);
      var httpResponse = await request.close();
      var responseBody = await utf8.decoder.bind(httpResponse).join();
      alice.onHttpClientResponse(httpResponse, request, body: responseBody);
    });

    httpClient
        .patchUrl(Uri.parse("https://jsonplaceholder.typicode.com/posts/1"))
        .then((request) async {
      alice.onHttpClientRequest(request, body: body);
      request.write(body);
      var httpResponse = await request.close();
      var responseBody = await utf8.decoder.bind(httpResponse).join();
      alice.onHttpClientResponse(httpResponse, request, body: responseBody);
    });

    httpClient
        .deleteUrl(Uri.parse("https://jsonplaceholder.typicode.com/posts/1"))
        .then((request) async {
      alice.onHttpClientRequest(request);
      var httpResponse = await request.close();
      var responseBody = await utf8.decoder.bind(httpResponse).join();
      alice.onHttpClientResponse(httpResponse, request, body: responseBody);
    });

    httpClient
        .getUrl(Uri.parse("https://jsonplaceholder.typicode.com/test/test/"))
        .then((request) async {
      alice.onHttpClientRequest(request);
      var httpResponse = await request.close();
      var responseBody = await utf8.decoder.bind(httpResponse).join();
      alice.onHttpClientResponse(httpResponse, request, body: responseBody);
    });

    /*dio.post("https://jsonplaceholder.typicode.com/posts", data: body);
    dio.get("https://jsonplaceholder.typicode.com/posts",
        queryParameters: {"test": 1});
    dio.put("https://jsonplaceholder.typicode.com/posts/1", data: body);
    dio.put("https://jsonplaceholder.typicode.com/posts/1", data: body);
    dio.delete("https://jsonplaceholder.typicode.com/posts/1");
    dio.get("http://jsonplaceholder.typicode.com/test/test");

    dio.get("https://jsonplaceholder.typicode.com/photos");
    dio.get(
        "https://icons.iconarchive.com/icons/paomedia/small-n-flat/256/sign-info-icon.png");
    dio.get(
        "https://images.unsplash.com/photo-1542736705-53f0131d1e98?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80");
    dio.get(
        "https://findicons.com/files/icons/1322/world_of_aqua_5/128/bluetooth.png");
    dio.get(
        "https://upload.wikimedia.org/wikipedia/commons/4/4e/Pleiades_large.jpg");
    dio.get("http://techslides.com/demos/sample-videos/small.mp4");*/
  }

  void _runHttpInspector() {
    alice.showInspector();
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  alice: ^0.0.24

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:alice/alice.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
91
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
94
Learn more about scoring.

We analyzed this package on Apr 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.7
  • Flutter: 1.12.13+hotfix.9

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
chewie ^0.9.8+1 0.9.10
chopper ^3.0.1+1 3.0.2
dio ^3.0.8 3.0.9
flutter 0.0.0
flutter_local_notifications ^1.1.5+1 1.4.0
http ^0.12.0+4 0.12.0+4
open_file ^3.0.1 3.0.1
package_info >=0.4.0+13 <2.0.0 0.4.0+16
path_provider ^1.6.0 1.6.5
permission_handler ^5.0.0+hotfix.3 5.0.0+hotfix.3
rxdart ^0.23.1 0.23.1 0.24.0-dev.1
shake ^0.1.0 0.1.0
share ^0.6.3+5 0.6.3+6
video_player ^0.10.6 0.10.8+1
Transitive dependencies
async 2.4.1
charcode 1.1.3
collection 1.14.11 1.14.12
ffi 0.1.3
flutter_local_notifications_platform_interface 1.0.1
flutter_web_plugins 0.0.0
http_parser 3.1.4
logging 0.11.4
meta 1.1.8
open_iconic_flutter 0.3.0
path 1.6.4
path_provider_macos 0.0.4
path_provider_platform_interface 1.0.1
pedantic 1.9.0
permission_handler_platform_interface 2.0.0
platform 2.2.1
plugin_platform_interface 1.0.2
sensors 0.4.1+10
sky_engine 0.0.99
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
video_player_platform_interface 1.0.5
video_player_web 0.1.2+1
wakelock 0.1.4+1