Unverified Commit 94f48c2c authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Make UserAccountsDrawerHeader accessible (#13851)

Fixes #13743 
Fixes #12379
Follow-up to #13745

Also adds an option to hide gestures introduced by `InkWell` and `InkResponse` from the semantics tree (see also `GestureDetector.excludeFromSemantics`).
parent f4040455
...@@ -100,17 +100,33 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin { ...@@ -100,17 +100,33 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin {
package: _kGalleryAssetsPackage, package: _kGalleryAssetsPackage,
), ),
), ),
otherAccountsPictures: const <Widget>[ otherAccountsPictures: <Widget>[
const CircleAvatar( new GestureDetector(
backgroundImage: const AssetImage( onTap: () {
_kAsset1, _onOtherAccountsTap(context);
package: _kGalleryAssetsPackage, },
child: new Semantics(
label: 'Switch to Account B',
child: const CircleAvatar(
backgroundImage: const AssetImage(
_kAsset1,
package: _kGalleryAssetsPackage,
),
),
), ),
), ),
const CircleAvatar( new GestureDetector(
backgroundImage: const AssetImage( onTap: () {
_kAsset2, _onOtherAccountsTap(context);
package: _kGalleryAssetsPackage, },
child: new Semantics(
label: 'Switch to Account C',
child: const CircleAvatar(
backgroundImage: const AssetImage(
_kAsset2,
package: _kGalleryAssetsPackage,
),
),
), ),
), ),
], ],
...@@ -213,4 +229,21 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin { ...@@ -213,4 +229,21 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin {
), ),
); );
} }
void _onOtherAccountsTap(BuildContext context) {
showDialog<Null>(
context: context,
child: new AlertDialog(
title: const Text('Account switching not implemented.'),
actions: <Widget>[
new FlatButton(
child: const Text('OK'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
),
);
}
} }
...@@ -96,6 +96,7 @@ class InkResponse extends StatefulWidget { ...@@ -96,6 +96,7 @@ class InkResponse extends StatefulWidget {
this.highlightColor, this.highlightColor,
this.splashColor, this.splashColor,
this.enableFeedback: true, this.enableFeedback: true,
this.excludeFromSemantics: false,
}) : assert(enableFeedback != null), super(key: key); }) : assert(enableFeedback != null), super(key: key);
/// The widget below this widget in the tree. /// The widget below this widget in the tree.
...@@ -194,6 +195,15 @@ class InkResponse extends StatefulWidget { ...@@ -194,6 +195,15 @@ class InkResponse extends StatefulWidget {
/// * [Feedback] for providing platform-specific feedback to certain actions. /// * [Feedback] for providing platform-specific feedback to certain actions.
final bool enableFeedback; final bool enableFeedback;
/// Whether to exclude the gestures introduced by this widget from the
/// semantics tree.
///
/// For example, a long-press gesture for showing a tooltip is usually
/// excluded because the tooltip itself is included in the semantics
/// tree directly and so having a gesture to show it would result in
/// duplication of information.
final bool excludeFromSemantics;
/// The rectangle to use for the highlight effect and for clipping /// The rectangle to use for the highlight effect and for clipping
/// the splash effects if [containedInkWell] is true. /// the splash effects if [containedInkWell] is true.
/// ///
...@@ -379,7 +389,8 @@ class _InkResponseState<T extends InkResponse> extends State<T> with AutomaticKe ...@@ -379,7 +389,8 @@ class _InkResponseState<T extends InkResponse> extends State<T> with AutomaticKe
onDoubleTap: widget.onDoubleTap != null ? _handleDoubleTap : null, onDoubleTap: widget.onDoubleTap != null ? _handleDoubleTap : null,
onLongPress: widget.onLongPress != null ? () => _handleLongPress(context) : null, onLongPress: widget.onLongPress != null ? () => _handleLongPress(context) : null,
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
child: widget.child child: widget.child,
excludeFromSemantics: widget.excludeFromSemantics,
); );
} }
...@@ -427,6 +438,7 @@ class InkWell extends InkResponse { ...@@ -427,6 +438,7 @@ class InkWell extends InkResponse {
Color splashColor, Color splashColor,
BorderRadius borderRadius, BorderRadius borderRadius,
bool enableFeedback: true, bool enableFeedback: true,
bool excludeFromSemantics: false,
}) : super( }) : super(
key: key, key: key,
child: child, child: child,
...@@ -440,5 +452,6 @@ class InkWell extends InkResponse { ...@@ -440,5 +452,6 @@ class InkWell extends InkResponse {
splashColor: splashColor, splashColor: splashColor,
borderRadius: borderRadius, borderRadius: borderRadius,
enableFeedback: enableFeedback, enableFeedback: enableFeedback,
excludeFromSemantics: excludeFromSemantics,
); );
} }
...@@ -7,6 +7,7 @@ import 'package:flutter/rendering.dart'; ...@@ -7,6 +7,7 @@ import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import '../rendering/mock_canvas.dart'; import '../rendering/mock_canvas.dart';
import '../widgets/semantics_tester.dart';
import 'feedback_tester.dart'; import 'feedback_tester.dart';
void main() { void main() {
...@@ -156,4 +157,33 @@ void main() { ...@@ -156,4 +157,33 @@ void main() {
await runTest(true); await runTest(true);
await runTest(false); await runTest(false);
}); });
testWidgets('excludeFromSemantics', (WidgetTester tester) async {
final SemanticsTester semantics = new SemanticsTester(tester);
await tester.pumpWidget(new Directionality(
textDirection: TextDirection.ltr,
child: new Material(
child: new InkWell(
onTap: () { },
child: const Text('Button'),
),
),
));
expect(semantics, includesNodeWith(label: 'Button', actions: <SemanticsAction>[SemanticsAction.tap]));
await tester.pumpWidget(new Directionality(
textDirection: TextDirection.ltr,
child: new Material(
child: new InkWell(
onTap: () { },
child: const Text('Button'),
excludeFromSemantics: true,
),
),
));
expect(semantics, isNot(includesNodeWith(label: 'Button', actions: <SemanticsAction>[SemanticsAction.tap])));
semantics.dispose();
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment