attributable 0.1.2

  • Installing
  • Versions
  • 41


Allows you to easily define getters/setters for attributes on your class and invoke callbacks when those attributes change.


A simple example may look like this:

import 'package:attributable';

class Button extends Object with Attributable {

  final List attribute_names = ['caption', 'color', 'enabled'];

  final Map attribute_callbacks = {
    'default' : (attr_name, self) => print("Attribute $attr_name now has a new value: ${self.attributes[attr_name]}"), 
    'caption' : (attr_name, self) => print("Caption is now '${self.caption}'"), 
    'enabled' : (attr_name, self) => print("Enabled is now set to '${self.enabled}'") 

  // Don't forget noSuchMethod() definition here (see below) or it won't work!


The default callback is invoked if no other callback for the given attribute is defined. Obviously, you may omit it, so nothing happens when your attribute changes.

So now we can create instances of our class and set attributes on them:

main() {

  var button = new Button();

  button.caption = "New caption"; // => Caption is now 'New caption' 
  button.enabled = true;          // => Enabled is now set to 'true' 
  button.color   = 'green';       // => Attribute color now has a new value: green


There's also a method which allows updating many attributes all at once:

button.updateAttributes({ 'caption': 'New caption', 'color': 'green'});

Needless to say, callbacks will also be invoked for the attributes listed. The updateAttributes() is slightly more powerful, see documenation to learn more.

IMPORTANT: at this point, in order for this to work, it is not enough to simply mix this abstract class into your class, you also have to define noSuchMethod() callback manually in your class, so that it looks something like the following:

noSuchMethod(Invocation i) {  
  try {
    return prvt_noSuchGetterOrSetter(i);
  } on NoSuchAttributeException {

The Invocation object gets passed into the prvt_noSuchGetterOrSetter(i) which then checks if any attribute with such a name are defined on the class. If not, then we return control to your class and it gets to call its original noSuchMethod() method, which, most likely, will generate an exception. Of course, if your class has its own noSuchMethod() functionality, you'd have take it into account and construct the method accordingly.

See /example/button.dart for an example (you can run it from the terminal).

1. Depend on it

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

  attributable: "^0.1.2"

2. Install it

You can install packages from the command line:

with pub:

$ pub get

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

3. Import it

Now in your Dart code, you can use:

import 'package:attributable/attributable.dart';
Version Uploaded Documentation Archive
0.1.2 Mar 27, 2017 Go to the documentation of attributable 0.1.2 Download attributable 0.1.2 archive
0.1.1 Oct 9, 2016 Go to the documentation of attributable 0.1.1 Download attributable 0.1.1 archive
0.1.0 May 20, 2016 Go to the documentation of attributable 0.1.0 Download attributable 0.1.0 archive


This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • tool failures on Feb 3, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1


Describes how popular the package is relative to other packages. [more]
17 / 100
Code health derived from static analysis. [more]
59 / 100
Reflects how tidy and up-to-date the package is. [more]
76 / 100
Overall score:
Weighted score of the above. [more]


Detected platforms: web, other

Primary library: package:attributable/attributable.dart with components: mirrors.


  • Fix lib/attributable.dart.

    Strong-mode analysis of lib/attributable.dart failed with the following error:

    line: 85 col: 17
    'Exception' isn't a function.

  • Maintain

    Changelog entries help clients to follow the progress in your code.

  • Fix issues reported by dartanalyzer.

    dartanalyzer reported 1 error(s) and 0 warning(s).

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Maintain an example.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use attributable.dart.


Package Constraint Resolved Available
Dev dependencies
test >=0.12.0