expected_response 1.0.0+1

  • Readme
  • Changelog
  • Installing
  • 50

Expected Response Generator #

Create classes and generate code to make it easier to deal with http responses, make the behaviour of the response more verbose, generic, and dry.

Getting Started #

Installing #

Add the following to your pubspec

    expected_response: ^1.0.0

    build_runner: ^1.0.0
    expected_response_generator: ^1.0.0

run pub get

Using #

See our example to see more.

@ExpectedResponse(allowedCodes: [200, 401, 403, 500])
class Mocked extends HttpBase<bool> {

  bool base(bool base) {
    _buildResponse(this, base);
    return true;

  Future<ServerResponse> requestFunction(bool base) async => await request(this, base);

  void successResponse(ServerResponse response, bool base) {


  Future<ServerResponse> request(Mocked me, bool base) async {
    return ServerResponse(200, '');

When the function _buildResponse, the function that was generated, be evoke, it will request the server through the requestFunction, and behave for each response code allowed, and if is 200, will use the successResponse;

1.0.0 #

  • Create package
  • Create the annotations
    • ExpectedResponse
      • Responsable for indicate the class where the ecossystem will run, is the entry point of everything;
    • Response
      • Identify the behaviour expected for each response code returned from the http response
    • Request
      • Identify the function that must make the request
    • EntryFunction
      • Is the function that will evoke the generated function
  • Create ServerResponse, the abstract class that receives the http response
  • Created the UnrecognizedHttpResponse, the default behaviour for unknown responses
  • Created the HttpBase, the super class for every class annotated with @ExpectedResponse
  • Documented the annotations
  • Documented the helper classes
  • Create README


  • Change the description

Use this package as a library

1. Depend on it

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

  expected_response: ^1.0.0+1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or 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:expected_response/expected_response.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.9+1

Health suggestions

Format lib/expected_response.dart.

Run dartfmt to format lib/expected_response.dart.

Format lib/src/annotations/entry_function.dart.

Run dartfmt to format lib/src/annotations/entry_function.dart.

Format lib/src/annotations/expected_response.dart.

Run dartfmt to format lib/src/annotations/expected_response.dart.

Fix additional 5 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/annotations/request.dart (Run dartfmt to format lib/src/annotations/request.dart.)
  • lib/src/annotations/response.dart (Run dartfmt to format lib/src/annotations/response.dart.)
  • lib/src/exceptions/unrecognized_http_exception.dart (Run dartfmt to format lib/src/exceptions/unrecognized_http_exception.dart.)
  • lib/src/http_base.dart (Run dartfmt to format lib/src/http_base.dart.)
  • lib/src/server_response.dart (Run dartfmt to format lib/src/server_response.dart.)

Maintenance suggestions

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and expected_response.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
Dev dependencies
test ^1.0.0