Fix AnimatedCrossFade would focus on a hidden widget (#87618)
Moving the focus with the tab key on the external keyboard will move the focus to the widget that is hidden by AnimatedCrossFade.
This commit is contained in:
@@ -6,6 +6,7 @@ import 'package:flutter/rendering.dart';
|
||||
|
||||
import 'animated_size.dart';
|
||||
import 'basic.dart';
|
||||
import 'focus_scope.dart';
|
||||
import 'framework.dart';
|
||||
import 'ticker_provider.dart';
|
||||
import 'transitions.dart';
|
||||
@@ -343,9 +344,11 @@ class _AnimatedCrossFadeState extends State<AnimatedCrossFade> with TickerProvid
|
||||
enabled: _isTransitioning,
|
||||
child: ExcludeSemantics(
|
||||
excluding: true, // Always exclude the semantics of the widget that's fading out.
|
||||
child: FadeTransition(
|
||||
opacity: bottomAnimation,
|
||||
child: bottomChild,
|
||||
child: ExcludeFocus(
|
||||
child: FadeTransition(
|
||||
opacity: bottomAnimation,
|
||||
child: bottomChild,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -354,9 +357,12 @@ class _AnimatedCrossFadeState extends State<AnimatedCrossFade> with TickerProvid
|
||||
enabled: true, // Top widget always has its animations enabled.
|
||||
child: ExcludeSemantics(
|
||||
excluding: false, // Always publish semantics for the widget that's fading in.
|
||||
child: FadeTransition(
|
||||
opacity: topAnimation,
|
||||
child: topChild,
|
||||
child: ExcludeFocus(
|
||||
excluding: false,
|
||||
child: FadeTransition(
|
||||
opacity: topAnimation,
|
||||
child: topChild,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@@ -360,6 +361,30 @@ void main() {
|
||||
expect(find.text('BBB'), findsOneWidget);
|
||||
expect(find.text('AAA'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('AnimatedCrossFade test focus', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: AnimatedCrossFade(
|
||||
firstChild: TextButton(onPressed: () {}, child: const Text('AAA')),
|
||||
secondChild: TextButton(onPressed: () {}, child: const Text('BBB')),
|
||||
crossFadeState: CrossFadeState.showFirst,
|
||||
duration: const Duration(milliseconds: 50),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final FocusNode visibleNode = Focus.of(tester.element(find.text('AAA')), scopeOk: true);
|
||||
visibleNode.requestFocus();
|
||||
await tester.pump();
|
||||
expect(visibleNode.hasPrimaryFocus, isTrue);
|
||||
|
||||
final FocusNode hiddenNode = Focus.of(tester.element(find.text('BBB')), scopeOk: true);
|
||||
hiddenNode.requestFocus();
|
||||
await tester.pump();
|
||||
expect(hiddenNode.hasPrimaryFocus, isFalse);
|
||||
});
|
||||
}
|
||||
|
||||
class _TickerWatchingWidget extends StatefulWidget {
|
||||
|
||||
Reference in New Issue
Block a user