Results for “BuildContext”
Full-text search across Boring Doc explanations, official documentation pages, the Flutter API index and every indexed version change.
Concepts
- State management3.47.7state
through many layers gets tedious. InheritedWidget lets any descendant find a value through BuildContext; dependents are rebuilt when the inherited widget is replaced with one whose updateShouldNotify
- Navigation and routing3.47.7navigation
need. After any await on navigation, check mounted (or context.mounted) before touching the BuildContext; the user may have left the screen meanwhile. The Navigator is a desk
- Widgets and the widget lifecycle3.47.7widgets
created on every build. StatelessWidget: build() depends only on its constructor arguments and BuildContext. StatefulWidget creates a State object that survives rebuilds and holds mutable data. State
Guides
- Animate a widget across screensdoc
import 'package:flutter/material.dart'; class MainScreen extends StatelessWidget { const MainScreen({super.key}); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Main Screen')), body: GestureDetector( onTap
- Staggered animationsdoc
How to write a staggered animation in Flutter. A staggered animation consists
- Retrieve the value of a text fielddoc
controller when the widget is disposed. myController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { // Fill this out in the next step. } } 3. Display the current value
- Layoutdoc
Learn about common layout widgets in Flutter. Learn how to build layouts
- Navigation and routingdoc
navigate to a new screen, access the Navigator through the route's BuildContext and call imperative methods such as push() or pop() : Because Navigator keeps a stack
API reference
- BuildContextclass
handle to the location of a widget in the widget tree. widgets.BuildContext BuildContext Build Context class widgets
- BuildContext.newconstructor
widgets.BuildContext.BuildContext.new BuildContext new Build Context.new constructor widgets
- DisposableBuildContextclass
Provides non-leaking access to a BuildContext. widgets.DisposableBuildContext DisposableBuildContext Disposable Build Context class widgets
- ContextActionclass
abstract Action subclass that adds an optional BuildContext to the isEnabled and invoke methods to be able to provide context to actions. widgets.ContextAction ContextAction Context Action class
- widgets.ElementVisitortypedef
Signature for the callback to BuildContext.visitChildElements. widgets.ElementVisitor ElementVisitor Element Visitor typedef widgets
- widgets.ConditionalElementVisitortypedef
Signature for the callback to BuildContext.visitAncestorElements. widgets.ConditionalElementVisitor ConditionalElementVisitor Conditional Element Visitor typedef widgets
- widgets.NavigatorFinderCallbacktypedef
callback that given a BuildContext finds a NavigatorState. widgets.NavigatorFinderCallback NavigatorFinderCallback Navigator Finder Callback typedef widgets
- widgets.createLocalImageConfigurationfunction
Creates an ImageConfiguration based on the given BuildContext (and optionally size). widgets.createLocalImageConfiguration createLocalImageConfiguration create Local Image Configuration function widgets
- DisposableBuildContext.newconstructor
Creates an object that provides access to a BuildContext without leaking a State. widgets.DisposableBuildContext.DisposableBuildContext.new DisposableBuildContext new Disposable Build Context.new constructor widgets
- material.PopupMenuPositionBuildertypedef
builder that creates a RelativeRect to position a popup menu. Both BuildContext and BoxConstraints are from the PopupRoute that displays this menu. material.PopupMenuPositionBuilder PopupMenuPositionBuilder Popup Menu Position
- widgets.ScrollableWidgetBuildertypedef
signature of a method that provides a BuildContext and ScrollController for building a widget that may overflow the draggable Axis of the containing area. widgets.ScrollableWidgetBuilder ScrollableWidgetBuilder Scrollable
- CupertinoDynamicColor.newconstructor
Creates an adaptive Color that changes its effective color based on the BuildContext given. The default effective color is color. cupertino.CupertinoDynamicColor.CupertinoDynamicColor.new CupertinoDynamicColor new Cupertino Dynamic Color.new constructor
- CupertinoDynamicColor.withBrightnessconstructor
Creates an adaptive Color that changes its effective color based on the given BuildContext's brightness (from MediaQueryData.platformBrightness or CupertinoThemeData.brightness). The default effective color is color. cupertino.CupertinoDynamicColor.CupertinoDynamicColor.withBrightness
- CupertinoDynamicColor.withBrightnessAndContrastconstructor
Creates an adaptive Color that changes its effective color based on the given BuildContext's brightness (from MediaQueryData.platformBrightness or CupertinoThemeData.brightness) and accessibility contrast setting (MediaQueryData.highContrast). The default
Version changes
- Added BuildContext parameter to TextEditingController.buildTextSpan2.0.0breaking
BuildContext` parameter was added to `TextEditingController.buildTextSpan`. With the `BuildContext` available, users can access `InheritedWidgets` inside `buildTextSpan` to retrieve state required to style the text, or otherwise
- Deprecate findChildIndexCallback in favor of findItemIndexCallback in ListView and SliverList separated constructors3.41.0deprecated
account for separators. return itemIndex == -1 ? null : itemIndex * 2; }, itemBuilder: (BuildContext context, int index) { return ListTile( key: ValueKey (items[index]), title: Text(items[index]), ); }, separatorBuilder: (BuildContext
- More Strict Assertions in the Navigator and the Hero Controller Scope1.20.0breaking
throw exceptions. ```dart import 'package:material_ui/material_ui.dart'; void main() { runApp( MaterialApp( builder: (BuildContext context, Widget child) { // Builds two parallel navigators. This throws // error because both of navigators
- Default multitouch scrolling3.19.0breaking
MyCustomScrollBehavior extends MaterialScrollBehavior { // Override behavior methods and getters like multitouchDragStrategy @override MultitouchDragStrategy getMultitouchDragStrategy(BuildContext context) => MultitouchDragStrategy.sumAllPointers; } // Set ScrollBehavior for an entire application. MaterialApp( scrollBehavior: MyCustomScrollBehavior(), // ... ); ``` ### Setting
- SnackBars managed by the ScaffoldMessenger2.0.0breaking
SnackBar`s would be shown by calling on the `Scaffold` within the current `BuildContext`. By calling `Scaffold.of(context).showSnackBar`, the current `Scaffold` would animate a `SnackBar` into
- Redesigned the Radio widget3.35.0breaking
them with `RadioGroup`. ### Case 1: trivial case Code before migration: ```dart Widget build(BuildContext context) { return Column( children: [ Radio ( value: 0, groupValue: _groupValue, onChanged: (int? value) { setState
- Default Scrollbars on Desktop2.2.0breaking
dart final ScrollController controller = ScrollController(); Scrollbar( controller: controller, child: ListView.builder( controller: controller, itemBuilder: (BuildContext context, int index) { return Text('Item $index'); } ) ); ``` Code after migration: ```dart final ScrollController
- Deprecated the window singleton3.10.0deprecated
static `window` property, application and library code that has access to a `BuildContext` should use `View.of` to look up the `FlutterView` the context is associated with. Some
- Deprecate OverlayPortal.targetsRootOverlay3.38.0deprecated
with `overlayLocation` instead. ### Case 1: trivial case Code before migration: ```dart Widget build(BuildContext context) { return OverlayPortal.targetsRootOverlay( controller: myController, overlayChildBuilder: _myBuilder, child: myChild, ); } ``` Code after migration: ```dart
- Actions API revision1.20.0breaking
TheAction.key)` instance. Code before migration: ```dart class MyWidget extends StatelessWidget { // ... @override Widget build(BuildContext context) { return Shortcuts( shortcuts: <LogicalKeySet, Intent> { LogicalKeySet(LogicalKeyboardKey.enter): Intent(ActivateAction.key), }, child: Actions( actions
- Trackpad gestures can trigger GestureRecognizer3.3.0breaking
Trackpad gestures on most platforms now send `PointerPanZoom` sequences and can trigger
- MouseTracker no longer attaches annotations1.17.0breaking
Removed `MouseTracker`'s methods `attachAnnotation`, `detachAnnotation`, and `isAnnotationAttached`. The `MouseTracker` class has
- Default PrimaryScrollController on Desktop3.3.0breaking
constraints) { return Row( children: [ SizedBox( height: constraints.maxHeight, width: constraints.maxWidth / 2, child: ListView.builder( itemBuilder: (BuildContext context, int index) { return Text
- Default drag scrolling devices2.5.0breaking
widget Code before migration: ```dart final ScrollController controller = ScrollController(); ListView.builder( controller: controller, itemBuilder: (BuildContext context, int index) { return Text('Item $inde
- TextField requires MaterialLocalizations1.20.0breaking
material_ui/material_ui.dart'; void main() => runApp(Foo()); class Foo extends StatelessWidget { @override Widget build(BuildContext context) { return MediaQuery( data: const MediaQueryData(), child: Directionality( textDirection: TextDirection.ltr, child: Material( child
- Removed ignoringSemantics3.13.0removed
semantics tree. class _IgnorePointerWithSemantics extends SingleChildRenderObjectWidget { const _IgnorePointerWithSemantics({ super.child, }); @override _RenderIgnorePointerWithSemantics createRenderObject(BuildContext context) { return _Rende
- CupertinoTabBar requires Localizations parent1.17.0breaking
cupertino_ui/cupertino_ui.dart'; void main() => runApp(Foo()); class Foo extends StatelessWidget { @override Widget build(BuildContext context) { return MediaQuery( data: const MediaQueryData(), child: CupertinoTabBar( items: const [ BottomNavigationBarItem( icon: Icon
- IconData class marked as final3.44.0breaking
final String? fontFamily; @override final String? fontPackage; @override final bool matchTextDirection; } Widget build(BuildContext context) { // Example usage of AppIcons: return Icon(AppIcons.arrowUpward); } ``` To maintain dot shorthand support
- Deprecate ExpansionTileController in favor of ExpansibleController3.32.0deprecated
migration: ```dart class _MyWidgetState extends State { final ExpansionTileController controller = ExpansionTileController(); @override Widget build(BuildContext context) { return ExpansionTile( controller: controller, ); } } ``` Code after migration: ```dart class _MyWidgetState extends State
- Deprecate SystemContextMenuController.show3.32.0deprecated
hood. No migration is needed: ```dart class _MyWidgetState extends State { @override Widget build(BuildContext context) { TextField( contextMenuBuilder: (BuildContext context, EditableTextState editableTextState) { return SystemContextMenu.editableText( editableTextState: editableTextState
- The new Form, FormField auto-validation API1.22.0breaking
changes. Code before migration: ```dart class MyWidget extends StatelessWidget { @override Widget build(BuildContext context) { return FormField( autovalidate: true, builder: (FormFieldState state) { return Container(); }, ); } } ``` Code after migration: ```dart
- Dialogs' Default BorderRadius1.20.0breaking
material_ui/material_ui.dart'; void main() => runApp(Foo()); class Foo extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( floatingActionButton: FloatingActionButton(onPressed: () { showDialog( context: context, builder: (BuildContext
- Rebuild optimization for OverlayEntries and Routes1.17.0breaking
migration: ```dart class FooState extends State { String buttonLabel = 'Click Me'; @override Widget build(BuildContext context) { return ElevatedButton( onPressed: () async { // Illegal state modification that should
- Eliminating nullOk Parameters2.0.0breaking
using static member functions that are typically called `of`, and take a `BuildContext`. In order to modify your code to use the new form of the APIs
- Migrate ShortcutActivator and ShortcutManager to KeyEvent system3.16.0breaking
For some time now (years), Flutter has had two key event systems
- Migrate RawKeyEvent/RawKeyboard system to KeyEvent/HardwareKeyboard system3.19.0breaking
For some time now (years), Flutter has had two key event systems
- Migrate to standalone material_ui and cupertino_ui packagesunreleasedbreaking
The Material and Cupertino design libraries are now available as standalone packages
- Accessibility traversal order of tooltip changed3.19.0breaking
tree in your test: ```dart Directionality( textDirection: TextDirection.ltr, child: Overlay( initialEntries: [ OverlayEntry( builder: (BuildContext context) { return ListView( children: [ const Text('before'), Tooltip( key: tooltipKey, showDuration: const Duration
- Replaced parameters for customizing context menus with a generic widget builder3.7.0breaking
Context menus, or text selection toolbars, are the menus that show up