responder 0.1.0+hotfix.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

Responder #

Stateful builders that accept null returns and avoid rebuild. Useful for listening to streams or providers for things other than builds. Like pushing routes, showing a dialog, etc

Prologue #

It all began when we wanted to show a snackbar in response to a Stream event. We were greeted with red screens of death. Apparently we can not show snackbars when widgets are building, but we did not want to build/rebuild the widget tree. We just wanted to show the snackbar.

Method #

We took the code from StreamBuilder and modified the subscription to call setState only when something changes. We also cached the subtree so if builder returns null, we do nothing and inhibit the build. This resulted in a working as expected StreamResponder widget.

We use provider package a lot and wanted to use the same things with StreamProvider, we have not yet been able to acheive the same results with Responder widget.

Responder -- Not Very Useful at the moment #

For the Responder class, we use it just like a Builder widget, if we return null from the WidgetBuilder, the Responder widget handles it properly.

Follow: (responder_example)[./responder_example] for a simple project

body: Responder(
        builder: (context) {
          if (i % 10 == 0) {
            return null;
          } else
            return WidgetBody(number: i);
        },
      ),

StreamResponder -- Working as Expected, Use with Caution #

It all began when we wanted to show a snackbar in response to a Stream event. We were greeted with red screens of death. Apparently we can not show snackbars when widgets are building, but we did not want to build/rebuild the widget tree. We just wanted to show the snackbar.

Follow: (stream_responder_example)[./stream_responder_example] for a simple project.

return Scaffold(
      body: StreamResponder(
        initialData: 1,
        stream: numberStream.numbers,
        builder: (BuildContext context, AsyncSnapshot snapshot) {
          if (snapshot.data % 12 == 0) {
            numberStream.cancel();
            Navigator.push(
              context,
              MaterialPageRoute(
                builder: (context) => Scaffold(
                  body: Center(
                    child: Text(snapshot.data.toString()),
                  ),
                ),
              ),
            );
            return null;
          }
          return Center(child: Text(snapshot.data.toString()));
        },
      ),
      floatingActionButton: FloatingActionButton(onPressed: () {
        numberStream.init();
      }),
    );
  • Use it like you would a StreamBuilder, we have designed the api as close as possible
  • You can return a Widget like a normal StreamBuilder and everything will work as expected
  • You can return null from the builder, or a Widget doing so will inhibit the build, so you can call things related to context
  • NOTE Be careful not to call context based things and return a Widget at the same time. We still can not get over the platform rules.

[0.1.0+hotfix.1] - 29th April, 2020 #

  • fixes link in documentation

[0.1.0] - 29th April, 2020 #

  • adds detailed documentation and examples

[0.0.6] - 29th April, 2020 #

  • fixes to responder
  • adds API documentation
  • adds responder example
  • changes to responder scope

[0.0.5] - 28th April, 2020 #

  • adds responder on testing

[0.0.4] - 28th April, 2020 #

  • adds stream responder
  • adds stream responder example

[0.0.3] - 28th April, 2020 #

  • Updates the description

[0.0.2] - 28th April, 2020 #

  • Adds license
  • Adds repository

[0.0.1] - 28th April, 2020 #

  • Created the package

example/README.md

Examples #

Examples for using the Respoder package within your flutter application.

Responder #

For the Responder class, we use it just like a Builder widget, if we return null from the WidgetBuilder, the Responder widget handles it properly.

Follow: responder_example for a simple project

body: Responder(
        builder: (context) {
          if (i % 10 == 0) {
            return null;
          } else
            return WidgetBody(number: i);
        },
      ),

StreamResponder #

It all began when we wanted to show a snackbar in response to a Stream event. We were greeted with red screens of death. Apparently we can not show snackbars when widgets are building, but we did not want to build/rebuild the widget tree. We just wanted to show the snackbar.

Follow: stream_responder_example for a simple project.

return Scaffold(
      body: StreamResponder(
        initialData: 1,
        stream: numberStream.numbers,
        builder: (BuildContext context, AsyncSnapshot snapshot) {
          if (snapshot.data % 12 == 0) {
            numberStream.cancel();
            Navigator.push(
              context,
              MaterialPageRoute(
                builder: (context) => Scaffold(
                  body: Center(
                    child: Text(snapshot.data.toString()),
                  ),
                ),
              ),
            );
            return null;
          }
          return Center(child: Text(snapshot.data.toString()));
        },
      ),
      floatingActionButton: FloatingActionButton(onPressed: () {
        numberStream.init();
      }),
    );
  • Use it like you would a StreamBuilder, we have designed the api as close as possible
  • You can return a Widget like a normal StreamBuilder and everything will work as expected
  • You can return null from the builder, or a Widget doing so will inhibit the build, so you can call things related to context
  • NOTE Be careful not to call context based things and return a Widget at the same time. We still can not get over the platform rules.

Use this package as a library

1. Depend on it

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


dependencies:
  responder: ^0.1.0+hotfix.1

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:responder/responder.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

Because:

  • responder that is a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test