ActiveView<T extends ActiveController> class abstract

A stateful consumer bound to an existing typed controller.

Flutter owns State disposal; the application owns controller disposal. A view cancels its own subscription and must not dispose a shared controller. Use ActivitySelector when only a small derived value should rebuild.

Gallery walkthrough · browser route /#/views. These examples use the current checkout; published 1.x APIs can differ.

Bind a whole view

import 'dart:async';
import 'package:activity/activity.dart';
import 'package:flutter/material.dart';

class CounterController extends ActiveController {
  final count = ActiveInt(0);
  @override
  Iterable<ActiveType> get activities => [count];
}

void main() => runApp(const MaterialApp(home: CounterOwner()));

class CounterOwner extends StatefulWidget {
  const CounterOwner({super.key});
  @override
  State<CounterOwner> createState() => _CounterOwnerState();
}

class _CounterOwnerState extends State<CounterOwner> {
  final controller = CounterController();
  @override
  void dispose() {
    unawaited(controller.dispose());
    super.dispose();
  }

  @override
  Widget build(BuildContext context) =>
      Scaffold(body: CounterView(activeController: controller));
}

class CounterView extends ActiveView<CounterController> {
  const CounterView({super.key, required super.activeController});
  @override
  ActiveState<ActiveView<CounterController>, CounterController>
  createActivity() => _CounterViewState(activeController);
}

class _CounterViewState extends ActiveState<CounterView, CounterController> {
  _CounterViewState(super.activeController);
  @override
  Widget build(BuildContext context) => TextButton(
    onPressed: activeController.count.increment,
    child: Text('Count ${activeController.count.value}'),
  );
}

Share the same owner with a scope

import 'dart:async';
import 'package:activity/activity.dart';
import 'package:flutter/material.dart';

class CounterController extends ActiveController {
  final count = ActiveInt(0);
  @override
  Iterable<ActiveType> get activities => [count];
}

void main() => runApp(const MaterialApp(home: CounterOwner()));

class CounterOwner extends StatefulWidget {
  const CounterOwner({super.key});
  @override
  State<CounterOwner> createState() => _CounterOwnerState();
}

class _CounterOwnerState extends State<CounterOwner> {
  final controller = CounterController();
  @override
  void dispose() {
    unawaited(controller.dispose());
    super.dispose();
  }

  @override
  Widget build(BuildContext context) => Scaffold(
    body: Activity<CounterController>(
      controller,
      child: CounterView(activeController: controller),
    ),
  );
}

class CounterView extends ActiveView<CounterController> {
  const CounterView({super.key, required super.activeController});
  @override
  ActiveState<ActiveView<CounterController>, CounterController>
  createActivity() => _CounterViewState(activeController);
}

class _CounterViewState extends ActiveState<CounterView, CounterController> {
  _CounterViewState(super.activeController);
  @override
  Widget build(BuildContext context) => TextButton(
    onPressed: activeController.count.increment,
    child: Text('Count ${activeController.count.value}'),
  );
}
Inheritance

Constructors

ActiveView({Key? key, required T activeController, bool developerMode = false})
const

Properties

activeController → T
final
developerMode → bool
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

createActivity() → ActiveState<ActiveView<T>, T>
Return your strongly typed ActiveState instance.
createElement() → StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → ActiveState<ActiveView<T>, T>
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
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
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, int wrapWidth = 65}) → 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