isActive property Null safety

bool isActive
inherited

Whether the state is active or not.

Active state means the the state had data at least once.

By default the state starts with isActive=false, and after the first mutation with data the isActive becomes true, and remains in this state until the state is disposed.

Useful if you want to call onWaiting only one time during initialization.

Example refresh fetched list of products using RefreshIndicator:

class App extends StatelessWidget {
 @override
 Widget build(BuildContext context) {
   return RefreshIndicator(
     onRefresh: () => products.refresh(),
     child: OnReactive(
       () => products.onOrElse(
         // show a CircularProgressIndicator
         //for the first fetch of products
         onWaiting: !products.isActive ?
                      () => CircularProgressIndicator()
                      : null,
         orElse: (_) {
           return ListView.builder(
             itemCount: products.state.length,
             itemBuilder: (context, index) {
               return Text(products.state[index]);
             },
           );
         },
       ),
     ),
   );
 }
}

Implementation

bool get isActive {
  OnReactiveState.addToObs?.call(this);
  return _reactiveModelState._snapState.isActive;
}