PassTrait<T> constructor

PassTrait<T>(
  1. T trait, {
  2. required Widget child,
})

The PassTrait Functionality allows you to pass data down your widget tree without struggles. Imagine having one unique value in your pack that special widgets below it regardless of their position or parent should know of. The PassTrait Widget injects your value in the Context, allowing you to access it everywhere.

PassTrait(
	10.0,
	child: ...
)

In some other Widgets generate function you can retrieve the value by using PassTrait.of now. The values are passed by type, so you can just get one value per type(of course custom classes are also valid):

  @override
  Widget generate(Context context) {
    var value = PassTrait.of<double>(context); // => 10.0
    return ...;
  }

Implementation

PassTrait(this.trait, {required this.child});