From c02ad6fd41413a46b7c01480f00832389c9f1450 Mon Sep 17 00:00:00 2001 From: David Shuckerow Date: Fri, 6 Apr 2018 10:00:38 -0700 Subject: [PATCH] Make no-op buttons more accessible by showing a SnackBar when they're pressed (#16284) * Remove explicit child nodes * Remove semantics on no-op menu buttons * Add a dummy action to the overflow bar --- .../demo/material/bottom_app_bar_demo.dart | 42 +++++++------------ 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/examples/flutter_gallery/lib/demo/material/bottom_app_bar_demo.dart b/examples/flutter_gallery/lib/demo/material/bottom_app_bar_demo.dart index 035fab9ac4..812ab2b7fd 100644 --- a/examples/flutter_gallery/lib/demo/material/bottom_app_bar_demo.dart +++ b/examples/flutter_gallery/lib/demo/material/bottom_app_bar_demo.dart @@ -181,7 +181,6 @@ class _BottomAppBarDemoState extends State { new Semantics( label: 'Set Bottom App Bar color to ${colorToName[color]}', container: true, - explicitChildNodes: false, child: new Row(children: [ new Radio( value: color, @@ -311,34 +310,21 @@ class _DemoBottomAppBar extends StatelessWidget { ); } rowContents.addAll( [ - // Generally, an icon button does not need to be wrapped in a Semantics object. - // When the button has a null onPressed callback, it will be disabled by default. - // - // However, for the purposes of this demo, we don't want the button to appear disabled. - // To achieve this we use a no-op callback instead of a null callback. This allows - // the buttons to appear active, but perform no actions. - // - // To tell the accessibility service that the callback is a no-op, the Semantics widget - // wraps these buttons with `enabled: false`. - new Semantics( - label: 'Search', - container: true, - explicitChildNodes: false, - enabled: false, - child: new IconButton( - icon: const Icon(Icons.search), - onPressed: () {}, - ), + new IconButton( + icon: const Icon(Icons.search), + onPressed: () { + Scaffold.of(context).showSnackBar( + const SnackBar(content: const Text('This is a dummy search action.')), + ); + }, ), - new Semantics( - label: 'Show more', - container: true, - explicitChildNodes: false, - enabled: false, - child: new IconButton( - icon: const Icon(Icons.more_vert), - onPressed: () {}, - ), + new IconButton( + icon: const Icon(Icons.more_vert), + onPressed: () { + Scaffold.of(context).showSnackBar( + const SnackBar(content: const Text('This is a dummy menu action.')), + ); + }, ), ]); return new Row(