InheritedWrap<U extends InheritedWidget> class
Works with an InheritedWidget to allow for targeted and independent rebuilds throughout your app. A powerful ability, you merely 'link' a Widget to an InheritedWidget using .dependOnInheritedWidget(context) and then call that InheritedWidget using .notifyClients() to rebuild its dependencies.
/// Static API Example import 'package:state_set/state_set.dart';
/// Static API class APIImages extends StatelessWidget { /// const APIImages({Key? key}) : super(key: key);
static final InheritedWrap _branch = InheritedWrap<_ImageInherited>( builder: (child) => _ImageInherited(child: child), child: const HomePage(), );
/// Link a widget to an InheritedWidget static bool dependOnInheritedWidget(BuildContext? context) => _branch.dependOnInheritedWidget(context);
/// In harmony with Flutter's own API static void notifyClients() => _branch.notifyClients();
/// Supply a Widget builder static Widget setState({ Key? key, required Widget Function(BuildContext context) builder, }) => _SetState(key: key, builder: builder);
/// Determine if static bool inBuilder = false;
@override Widget build(BuildContext context) => _branch; }
/// The InheritedWidget assigned 'dependent' child widgets. class _ImageInherited extends InheritedWidget { /// const _ImageInherited({Key? key, required Widget child}) : super(key: key, child: child);
@override bool updateShouldNotify(covariant InheritedWidget oldWidget) => true; }
/// Used like the function, setState(), to 'spontaneously' call /// build() functions here and there in your app. Much like the Scoped /// Model's ScopedModelDescendant() class. /// This class object will only rebuild if the InheritedWidget notifies it /// as it is a dependency. class _SetState extends StatelessWidget { /// Supply a 'builder' passing in the App's 'data object' and latest BuildContext object. const _SetState({Key? key, required this.builder}) : super(key: key);
/// This is called with every rebuild of the App's inherited widget. final Widget Function(BuildContext context) builder;
/// Calls the required Function object: /// Function(BuildContext context) @override Widget build(BuildContext context) { /// Go up the widget tree and link to the App's inherited widget. context.dependOnInheritedWidgetOfExactType<_ImageInherited>();
APIImages.inBuilder = true;
final Widget widget = builder(context);
APIImages.inBuilder = false;
return widget;
} }
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- InheritedWrap
- Available Extensions
Constructors
- InheritedWrap({Key? key, required U builder(Widget child), required Widget child})
-
const
Properties
- builder → U Function(Widget child)
-
Supply a child Widget to the returning InheritedWidget's child parameter.
final
- child → Widget
-
The 'child' Widget eventually passed to the InheritedWidget.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< StatefulWidget> -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of
DiagnosticsNode
objects describing this node's children.inherited -
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
dependOnInheritedWidget(
BuildContext? context) → bool - Link a widget to a InheritedWidget of type U
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyClients(
) → bool - Notify any dependencies to be rebuilt.
-
setState(
VoidCallback fn) → void - Calls setState() function in the Widget's State object.
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited