PageTitle class

Updates the application title dynamically based on the currently displayed PageTitle. Supports nested PageTitle widgets, using the title of the most recently built widget.

This widget listens to changes in the widget tree and updates the application's title accordingly. It uses a unique ID for each PageTitle instance to manage nested titles correctly. The title of the most recently built PageTitle widget is used as the application's title.

Example:

PageTitle(
  title: 'Home Page',
  child: Scaffold(
    appBar: AppBar(title: Text('Home')),
    body: Center(
      child: PageTitle(
        title: 'Product Details',
        child: Text('Product details'),
      ),
    ),
  ),
);

In this example, the application title will initially be "Home Page". When the inner PageTitle widget is built, the title will change to "Product Details". When the inner PageTitle widget is removed from the tree, the title will revert back to "Home Page".

Inheritance

Constructors

PageTitle({Key? key, required String title, required Widget child})
Creates a PageTitle widget.
const

Properties

child Widget
The child widget. This can be any widget, including other nested PageTitle widgets.
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
title String
The title to display in the application switcher. This title will be used as the application's title when this PageTitle widget is the most recently built one in the widget tree.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<PageTitle>
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

Static Methods

current(BuildContext context) String?
Retrieves the current title of the application. This returns the title of the most recently built PageTitle widget in the current context. Returns null if no PageTitle widget is found in the current context.