-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Fixes accessibility/tappability of the FAB in the FadeScaleTransition example #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
125a707
Fix accessibility of FadeScaleTransition example using FAB
shihaohong f12c8d1
Fix formatting
shihaohong 0a074b7
Update changelog
shihaohong bec09a6
Start FAB off as hidden instead of open
shihaohong e3c5763
Address code review feedback
shihaohong 5587e22
_controller.value -> _controller.status
shihaohong 7f17be5
Turn isAnimationRunningForwardsOrComplete bool to getter
shihaohong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,16 +16,20 @@ class _FadeScaleTransitionDemoState extends State<FadeScaleTransitionDemo> | |
| with SingleTickerProviderStateMixin { | ||
| AnimationController _controller; | ||
|
|
||
| bool _showFab = true; | ||
|
|
||
| @override | ||
| void initState() { | ||
| _controller = AnimationController( | ||
| value: 1.0, | ||
| value: 0.0, | ||
| duration: const Duration(milliseconds: 150), | ||
| reverseDuration: const Duration(milliseconds: 75), | ||
| vsync: this, | ||
| ); | ||
| )..addStatusListener((AnimationStatus status) { | ||
| setState(() { | ||
| // setState needs to be called to trigger a rebuild because | ||
| // the 'HIDE FAB'/'SHOW FAB' button needs to be updated based | ||
| // the latest value of [_controller.value]. | ||
| }); | ||
| }); | ||
| super.initState(); | ||
| } | ||
|
|
||
|
|
@@ -35,12 +39,23 @@ class _FadeScaleTransitionDemoState extends State<FadeScaleTransitionDemo> | |
| super.dispose(); | ||
| } | ||
|
|
||
| bool isAnimationRunningForwardsOrComplete() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this could be private (and maybe just a getter). |
||
| switch (_controller.status) { | ||
| case AnimationStatus.forward: | ||
| case AnimationStatus.completed: | ||
| return true; | ||
| case AnimationStatus.reverse: | ||
| case AnimationStatus.dismissed: | ||
| return false; | ||
| } | ||
| assert(false); | ||
| return null; | ||
| } | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return Scaffold( | ||
| appBar: AppBar( | ||
| title: const Text('Fade'), | ||
| ), | ||
| appBar: AppBar(title: const Text('Fade')), | ||
| floatingActionButton: AnimatedBuilder( | ||
| animation: _controller, | ||
| builder: (BuildContext context, Widget child) { | ||
|
|
@@ -49,9 +64,12 @@ class _FadeScaleTransitionDemoState extends State<FadeScaleTransitionDemo> | |
| child: child, | ||
| ); | ||
| }, | ||
| child: FloatingActionButton( | ||
| child: const Icon(Icons.add), | ||
| onPressed: () {}, | ||
| child: Visibility( | ||
| visible: _controller.status != AnimationStatus.dismissed, | ||
| child: FloatingActionButton( | ||
| child: const Icon(Icons.add), | ||
| onPressed: () {}, | ||
| ), | ||
| ), | ||
| ), | ||
| bottomNavigationBar: Column( | ||
|
|
@@ -80,21 +98,15 @@ class _FadeScaleTransitionDemoState extends State<FadeScaleTransitionDemo> | |
| const SizedBox(width: 10), | ||
| RaisedButton( | ||
| onPressed: () { | ||
| if (_showFab) { | ||
| setState(() { | ||
| _showFab = false; | ||
| }); | ||
| if (isAnimationRunningForwardsOrComplete()) { | ||
| _controller.reverse(); | ||
| } else { | ||
| setState(() { | ||
| _showFab = true; | ||
| }); | ||
| _controller.forward(); | ||
| } | ||
| }, | ||
| color: Theme.of(context).colorScheme.primary, | ||
| textColor: Theme.of(context).colorScheme.onPrimary, | ||
| child: _showFab | ||
| child: isAnimationRunningForwardsOrComplete() | ||
| ? const Text('HIDE FAB') | ||
| : const Text('SHOW FAB'), | ||
| ), | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_controller.value -> _controller.status?