BaseToolbar class
Internal: CNToolbarAction from cupertino_native package Used only for iOS platform channel communication Public API should use BaseToolbarAction instead BaseToolbar - Cross-platform toolbar with native iOS support
Uses CNToolbar (Cupertino Native) for iOS - provides true native iOS appearance with built-in liquid glass effects and native rendering. Uses Material AppBar-style toolbar for Android and other platforms.
*** use cupertino = { forceUseMaterial: true } force use Material toolbar on iOS *** use material = { forceUseCupertino: true } force use CNToolbar on Android
Features:
- Native iOS toolbar via CNToolbar (cupertino_native package)
- Material Design toolbar for Android
- Flexible leading, middle, and trailing actions
- Search functionality with expandable search field
- Built-in liquid glass effects on iOS (no manual wrapper needed)
- Automatic platform-specific conversion of actions
Example:
BaseToolbar(
leading: [
BaseToolbarAction(
icon: CNSymbol('chevron.left'),
onPressed: () => Navigator.pop(context),
),
],
middle: [
BaseToolbarAction(
icon: CNSymbol('pencil', size: 40),
onPressed: () => print('Edit'),
),
],
trailing: [
BaseToolbarAction(
icon: CNSymbol('gear'),
onPressed: () => print('Settings'),
),
],
)
For search functionality, use the factory constructor:
BaseToolbar.search(
leading: [
BaseToolbarAction(icon: CNSymbol('star.fill'), onPressed: () {}),
],
trailing: [
BaseToolbarAction(icon: CNSymbol('ellipsis.circle'), onPressed: () {}),
],
searchConfig: CNSearchConfig(
placeholder: 'Search',
onSearchTextChanged: (text) => print(text),
resultsBuilder: (context, text) => SearchResults(text),
),
contextIcon: CNSymbol('apps.iphone'),
)
Forcing Rebuild/Refresh
Since BaseToolbar is a StatelessWidget, it rebuilds when its parent rebuilds. To force a rebuild when the toolbar's state changes, use one of these methods:
Method 1: Change the Key (Recommended)
class MyWidget extends StatefulWidget {
@override
State<MyWidget> createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> {
int _refreshKey = 0;
List<BaseToolbarAction> _actions = [...];
void updateActions() {
setState(() {
_actions = [...]; // Update actions
_refreshKey++; // Increment key to force rebuild
});
}
@override
Widget build(BuildContext context) {
return BaseToolbar(
key: ValueKey(_refreshKey), // Or use BaseToolbar.refreshKey()
trailing: _actions,
// ...
);
}
}
Method 2: Use UniqueKey for Each Rebuild
BaseToolbar(
key: UniqueKey(), // Creates new key on every build
// ...
)
Method 3: Use the Static Helper
BaseToolbar(
key: BaseToolbar.refreshKey(), // Generates unique key
// ...
)
Updated: 2024.10.25 - Refactored to use BaseToolbarAction in public API Updated: 2024.10.30 - Added refresh documentation and helper methods
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- BaseStatelessWidget
- BaseToolbar
- Implementers
Constructors
-
BaseToolbar({Key? key, List<
BaseToolbarAction> ? leading, List<BaseToolbarAction> ? middle, List<BaseToolbarAction> ? trailing, String? title, Color? tint, bool transparent = false, double? height, double? pillHeight, BaseToolbarAlignment middleAlignment = BaseToolbarAlignment.center, Color? backgroundColor, CNSearchConfig? searchConfig, CNSymbol? contextIcon, BaseParam? baseParam}) -
const
-
BaseToolbar.search({Key? key, List<
BaseToolbarAction> ? leading, List<BaseToolbarAction> ? trailing, required CNSearchConfig searchConfig, CNSymbol? contextIcon, Color? tint, bool transparent = false, double? height, double? pillHeight, Color? backgroundColor, BaseParam? baseParam}) -
Factory constructor for search-enabled toolbar
const
Properties
- backgroundColor → Color?
-
Background color (Material only)
final
- baseParam → BaseParam?
-
Personalization parameters, gets platform parameters first, then mode parameters
finalinherited
- contextIcon → CNSymbol?
-
Context icon for search toolbar
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- height → double?
-
Custom toolbar height
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
-
leading
→ List<
BaseToolbarAction> ? -
Leading toolbar actions (typically back button, share)
final
-
middle
→ List<
BaseToolbarAction> ? -
Middle toolbar actions (main actions)
final
- middleAlignment → BaseToolbarAlignment
-
Alignment for middle section
final
- pillHeight → double?
-
Custom pill button height (iOS only)
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- searchConfig → CNSearchConfig?
-
Search configuration for search-enabled toolbar
final
- tint → Color?
-
Tint color for icons and text
final
- title → String?
-
Optional title text
final
-
trailing
→ List<
BaseToolbarAction> ? -
Trailing toolbar actions (typically settings, more)
final
- transparent → bool
-
Whether the toolbar should be transparent with blur effect
final
Methods
-
beforeBuild(
BuildContext context) → void -
Called before build
inherited
-
beforeBuildByCupertino(
BuildContext context) → void -
Called before buildByCupertino
inherited
-
beforeBuildByCupertinoNative(
BuildContext context) → void -
Called before buildByCupertinoNative (native iOS implementation)
inherited
-
beforeBuildByMaterial(
BuildContext context) → void -
Called before buildByMaterial
inherited
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
inherited
-
buildByCupertino(
BuildContext context) → Widget - build on cupertino mode (Flutter implementation)
-
buildByCupertinoNative(
BuildContext context) → Widget - build on cupertino mode with native iOS components (cupertino_native package) This is called when baseParam.nativeIOS = true Default implementation falls back to buildByCupertino()
-
buildByMaterial(
BuildContext context) → Widget - build on material mode
-
commonBuild(
BuildContext context, BaseParam? baseParam) → dynamic -
inherited
-
createElement(
) → StatelessElement -
Creates a StatelessElement to manage this widget's location in the tree.
inherited
-
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
-
getBuildMode(
BaseParam? baseParam) → WidgetBuildMode -
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
-
valueOf(
String key, dynamic value) → dynamic -
inherited
-
valueOfBaseParam(
BaseParam? baseParam, String key, dynamic value) → dynamic -
No reflection available in Dart
First get value from platform, then from mode, finally from value itself
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
refreshKey(
) → Key - Creates a unique key for forcing widget rebuild