Move examples to ListenableBuilder
(#130671)
Updates examples to use the new `ListenableBuilder` if there's no animation. This is slightly more idiomatic.
This commit is contained in:
parent
085d6c9700
commit
e8231cea4c
@ -74,8 +74,8 @@ class _MyKeyExampleState extends State<MyKeyExample> {
|
|||||||
child: Focus(
|
child: Focus(
|
||||||
focusNode: _focusNode,
|
focusNode: _focusNode,
|
||||||
onKey: _handleKeyEvent,
|
onKey: _handleKeyEvent,
|
||||||
child: AnimatedBuilder(
|
child: ListenableBuilder(
|
||||||
animation: _focusNode,
|
listenable: _focusNode,
|
||||||
builder: (BuildContext context, Widget? child) {
|
builder: (BuildContext context, Widget? child) {
|
||||||
if (!_focusNode.hasFocus) {
|
if (!_focusNode.hasFocus) {
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
|
@ -74,8 +74,8 @@ class _MyPhysicalKeyExampleState extends State<MyPhysicalKeyExample> {
|
|||||||
child: Focus(
|
child: Focus(
|
||||||
focusNode: _focusNode,
|
focusNode: _focusNode,
|
||||||
onKey: _handleKeyEvent,
|
onKey: _handleKeyEvent,
|
||||||
child: AnimatedBuilder(
|
child: ListenableBuilder(
|
||||||
animation: _focusNode,
|
listenable: _focusNode,
|
||||||
builder: (BuildContext context, Widget? child) {
|
builder: (BuildContext context, Widget? child) {
|
||||||
if (!_focusNode.hasFocus) {
|
if (!_focusNode.hasFocus) {
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
|
@ -91,8 +91,8 @@ class _SaveButtonState extends State<SaveButton> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return AnimatedBuilder(
|
return ListenableBuilder(
|
||||||
animation: widget.valueNotifier,
|
listenable: widget.valueNotifier,
|
||||||
builder: (BuildContext context, Widget? child) {
|
builder: (BuildContext context, Widget? child) {
|
||||||
return TextButton.icon(
|
return TextButton.icon(
|
||||||
icon: const Icon(Icons.save),
|
icon: const Icon(Icons.save),
|
||||||
@ -146,8 +146,8 @@ class _ActionsExampleState extends State<ActionsExample> {
|
|||||||
Actions.invoke(context, ModifyIntent(++count));
|
Actions.invoke(context, ModifyIntent(++count));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
AnimatedBuilder(
|
ListenableBuilder(
|
||||||
animation: model.data,
|
listenable: model.data,
|
||||||
builder: (BuildContext context, Widget? child) {
|
builder: (BuildContext context, Widget? child) {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
@ -100,8 +100,8 @@ class _ShortcutsExampleState extends State<ShortcutsExample> {
|
|||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
const Text('Add to the counter by pressing the up arrow key'),
|
const Text('Add to the counter by pressing the up arrow key'),
|
||||||
const Text('Subtract from the counter by pressing the down arrow key'),
|
const Text('Subtract from the counter by pressing the down arrow key'),
|
||||||
AnimatedBuilder(
|
ListenableBuilder(
|
||||||
animation: model,
|
listenable: model,
|
||||||
builder: (BuildContext context, Widget? child) {
|
builder: (BuildContext context, Widget? child) {
|
||||||
return Text('count: ${model.count}');
|
return Text('count: ${model.count}');
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user