Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
4119210e
Unverified
Commit
4119210e
authored
Sep 27, 2022
by
Jonah Williams
Committed by
GitHub
Sep 27, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[framework] use Visibility instead of Opacity (#112191)
parent
97b53bc9
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
80 additions
and
31 deletions
+80
-31
context_menu.dart
packages/flutter/lib/src/cupertino/context_menu.dart
+2
-2
bottom_navigation_bar.dart
packages/flutter/lib/src/material/bottom_navigation_bar.dart
+2
-3
navigation_rail.dart
packages/flutter/lib/src/material/navigation_rail.dart
+2
-3
basic.dart
packages/flutter/lib/src/widgets/basic.dart
+3
-1
sliver.dart
packages/flutter/lib/src/widgets/sliver.dart
+5
-0
visibility.dart
packages/flutter/lib/src/widgets/visibility.dart
+44
-0
bottom_navigation_bar_test.dart
...ges/flutter/test/material/bottom_navigation_bar_test.dart
+4
-4
bottom_navigation_bar_theme_test.dart
...utter/test/material/bottom_navigation_bar_theme_test.dart
+5
-5
navigation_rail_test.dart
packages/flutter/test/material/navigation_rail_test.dart
+5
-5
navigation_rail_theme_test.dart
...ges/flutter/test/material/navigation_rail_theme_test.dart
+8
-8
No files found.
packages/flutter/lib/src/cupertino/context_menu.dart
View file @
4119210e
...
...
@@ -378,9 +378,9 @@ class _CupertinoContextMenuState extends State<CupertinoContextMenu> with Ticker
onTap:
_onTap
,
child:
TickerMode
(
enabled:
!
_childHidden
,
child:
Opacity
(
child:
Visibility
.
maintain
(
key:
_childGlobalKey
,
opacity:
_childHidden
?
0.0
:
1.0
,
visible:
!
_childHidden
,
child:
widget
.
child
,
),
),
...
...
packages/flutter/lib/src/material/bottom_navigation_bar.dart
View file @
4119210e
...
...
@@ -728,9 +728,8 @@ class _Label extends StatelessWidget {
if
(!
showUnselectedLabels
&&
!
showSelectedLabels
)
{
// Never show any labels.
text
=
Opacity
(
alwaysIncludeSemantics:
true
,
opacity:
0.0
,
text
=
Visibility
.
maintain
(
visible:
false
,
child:
text
,
);
}
else
if
(!
showUnselectedLabels
)
{
...
...
packages/flutter/lib/src/material/navigation_rail.dart
View file @
4119210e
...
...
@@ -619,9 +619,8 @@ class _RailDestination extends StatelessWidget {
SizedBox
(
width:
0
,
height:
0
,
child:
Opacity
(
alwaysIncludeSemantics:
true
,
opacity:
0.0
,
child:
Visibility
.
maintain
(
visible:
false
,
child:
label
,
),
),
...
...
packages/flutter/lib/src/widgets/basic.dart
View file @
4119210e
...
...
@@ -289,7 +289,9 @@ class Directionality extends _UbiquitousInheritedWidget {
///
/// * [Visibility], which can hide a child more efficiently (albeit less
/// subtly, because it is either visible or hidden, rather than allowing
/// fractional opacity values).
/// fractional opacity values). Specifically, the [Visibility.maintain]
/// constructor is equivalent to using an opacity widget with values of
/// `0.0` or `1.0`.
/// * [ShaderMask], which can apply more elaborate effects to its child.
/// * [Transform], which applies an arbitrary transform to its child widget at
/// paint time.
...
...
packages/flutter/lib/src/widgets/sliver.dart
View file @
4119210e
...
...
@@ -1656,6 +1656,11 @@ class SliverMultiBoxAdaptorElement extends RenderObjectElement implements Render
/// RenderBox layout protocol.
/// * [AnimatedOpacity], which uses an animation internally to efficiently
/// animate [Opacity].
/// * [SliverVisibility], which can hide a child more efficiently (albeit less
/// subtly, because it is either visible or hidden, rather than allowing
/// fractional opacity values). Specifically, the [SliverVisibility.maintain]
/// constructor is equivalent to using a sliver opacity widget with values of
/// `0.0` or `1.0`.
class
SliverOpacity
extends
SingleChildRenderObjectWidget
{
/// Creates a sliver that makes its sliver child partially transparent.
///
...
...
packages/flutter/lib/src/widgets/visibility.dart
View file @
4119210e
...
...
@@ -85,6 +85,28 @@ class Visibility extends StatelessWidget {
'Cannot maintain interactivity if size is not maintained.'
,
);
/// Control whether the given [child] is [visible].
///
/// The [child] and [replacement] arguments must not be null.
///
/// This is equivalent to the default [Visibility] constructor with all
/// "maintain" fields set to true. This constructor should be used in place of
/// an [Opacity] widget that only takes on values of `0.0` or `1.0`, as it
/// avoids extra compositing when fully opaque.
const
Visibility
.
maintain
({
super
.
key
,
required
this
.
child
,
this
.
replacement
=
const
SizedBox
.
shrink
(),
this
.
visible
=
true
,
})
:
assert
(
child
!=
null
),
assert
(
replacement
!=
null
),
assert
(
visible
!=
null
),
maintainState
=
true
,
maintainAnimation
=
true
,
maintainSize
=
true
,
maintainSemantics
=
true
,
maintainInteractivity
=
true
;
/// The widget to show or hide, as controlled by [visible].
///
/// {@macro flutter.widgets.ProxyWidget.child}
...
...
@@ -332,6 +354,28 @@ class SliverVisibility extends StatelessWidget {
'Cannot maintain interactivity if size is not maintained.'
,
);
/// Control whether the given [sliver] is [visible].
///
/// The [sliver] and [replacementSliver] arguments must not be null.
///
/// This is equivalent to the default [SliverVisibility] constructor with all
/// "maintain" fields set to true. This constructor should be used in place of
/// a [SliverOpacity] widget that only takes on values of `0.0` or `1.0`, as it
/// avoids extra compositing when fully opaque.
const
SliverVisibility
.
maintain
({
super
.
key
,
required
this
.
sliver
,
this
.
replacementSliver
=
const
SliverToBoxAdapter
(),
this
.
visible
=
true
,
})
:
assert
(
sliver
!=
null
),
assert
(
replacementSliver
!=
null
),
assert
(
visible
!=
null
),
maintainState
=
true
,
maintainAnimation
=
true
,
maintainSize
=
true
,
maintainSemantics
=
true
,
maintainInteractivity
=
true
;
/// The sliver to show or hide, as controlled by [visible].
final
Widget
sliver
;
...
...
packages/flutter/test/material/bottom_navigation_bar_test.dart
View file @
4119210e
...
...
@@ -1971,8 +1971,8 @@ void main() {
await
tester
.
pumpWidget
(
widget
);
expect
(
find
.
text
(
'Red'
),
findsOneWidget
);
expect
(
find
.
text
(
'Green'
),
findsOneWidget
);
expect
(
tester
.
widget
<
Opacity
>(
find
.
byType
(
Opacity
).
first
).
opacity
,
0.0
);
expect
(
tester
.
widget
<
Opacity
>(
find
.
byType
(
Opacity
).
last
).
opacity
,
0.0
);
expect
(
tester
.
widget
<
Visibility
>(
find
.
byType
(
Visibility
).
first
).
visible
,
false
);
expect
(
tester
.
widget
<
Visibility
>(
find
.
byType
(
Visibility
).
last
).
visible
,
false
);
},
);
...
...
@@ -2009,8 +2009,8 @@ void main() {
);
expect
(
find
.
text
(
'Red'
),
findsOneWidget
);
expect
(
find
.
text
(
'Green'
),
findsOneWidget
);
expect
(
tester
.
widget
<
Opacity
>(
find
.
byType
(
Opacity
).
first
).
opacity
,
0.0
);
expect
(
tester
.
widget
<
Opacity
>(
find
.
byType
(
Opacity
).
last
).
opacity
,
0.0
);
expect
(
tester
.
widget
<
Visibility
>(
find
.
byType
(
Visibility
).
first
).
visible
,
false
);
expect
(
tester
.
widget
<
Visibility
>(
find
.
byType
(
Visibility
).
last
).
visible
,
false
);
},
);
...
...
packages/flutter/test/material/bottom_navigation_bar_theme_test.dart
View file @
4119210e
...
...
@@ -359,14 +359,14 @@ void main() {
);
final
Finder
find
Opac
ity
=
find
.
descendant
(
final
Finder
find
Visibil
ity
=
find
.
descendant
(
of:
find
.
byType
(
BottomNavigationBar
),
matching:
find
.
byType
(
Opac
ity
),
matching:
find
.
byType
(
Visibil
ity
),
);
expect
(
find
Opac
ity
,
findsNWidgets
(
2
));
expect
(
tester
.
widget
<
Opacity
>(
findOpacity
.
at
(
0
)).
opacity
,
0.0
);
expect
(
tester
.
widget
<
Opacity
>(
findOpacity
.
at
(
1
)).
opacity
,
0.0
);
expect
(
find
Visibil
ity
,
findsNWidgets
(
2
));
expect
(
tester
.
widget
<
Visibility
>(
findVisibility
.
at
(
0
)).
visible
,
false
);
expect
(
tester
.
widget
<
Visibility
>(
findVisibility
.
at
(
1
)).
visible
,
false
);
});
testWidgets
(
'BottomNavigationBarTheme can be used to hide selected labels'
,
(
WidgetTester
tester
)
async
{
...
...
packages/flutter/test/material/navigation_rail_test.dart
View file @
4119210e
...
...
@@ -4693,14 +4693,14 @@ Finder _opacityAboveLabel(String text) {
// Only valid when labelType != all.
double
?
_labelOpacity
(
WidgetTester
tester
,
String
text
)
{
// We search for both
Opac
ity and FadeTransition since in some
// We search for both
Visibil
ity and FadeTransition since in some
// cases opacity is animated, in other it's not.
final
Iterable
<
Opacity
>
opacityWidgets
=
tester
.
widgetList
<
Opac
ity
>(
find
.
ancestor
(
final
Iterable
<
Visibility
>
visibilityWidgets
=
tester
.
widgetList
<
Visibil
ity
>(
find
.
ancestor
(
of:
find
.
text
(
text
),
matching:
find
.
byType
(
Opac
ity
),
matching:
find
.
byType
(
Visibil
ity
),
));
if
(
opac
ityWidgets
.
isNotEmpty
)
{
return
opacityWidgets
.
single
.
opacity
;
if
(
visibil
ityWidgets
.
isNotEmpty
)
{
return
visibilityWidgets
.
single
.
visible
?
1.0
:
0.0
;
}
final
FadeTransition
fadeTransitionWidget
=
tester
.
widget
<
FadeTransition
>(
...
...
packages/flutter/test/material/navigation_rail_theme_test.dart
View file @
4119210e
...
...
@@ -363,27 +363,27 @@ Align _destinationsAlign(WidgetTester tester) {
}
NavigationRailLabelType
_labelType
(
WidgetTester
tester
)
{
if
(
_
opacityAboveLabel
(
'Abc'
).
evaluate
().
isNotEmpty
&&
_opac
ityAboveLabel
(
'Def'
).
evaluate
().
isNotEmpty
)
{
return
_label
Opacity
(
tester
,
'Abc'
)
==
1
?
NavigationRailLabelType
.
selected
:
NavigationRailLabelType
.
none
;
if
(
_
visibilityAboveLabel
(
'Abc'
).
evaluate
().
isNotEmpty
&&
_visibil
ityAboveLabel
(
'Def'
).
evaluate
().
isNotEmpty
)
{
return
_label
Visibility
(
tester
,
'Abc'
)
?
NavigationRailLabelType
.
selected
:
NavigationRailLabelType
.
none
;
}
else
{
return
NavigationRailLabelType
.
all
;
}
}
Finder
_
opac
ityAboveLabel
(
String
text
)
{
Finder
_
visibil
ityAboveLabel
(
String
text
)
{
return
find
.
ancestor
(
of:
find
.
text
(
text
),
matching:
find
.
byType
(
Opac
ity
),
matching:
find
.
byType
(
Visibil
ity
),
);
}
// Only valid when labelType != all.
double
_labelOpac
ity
(
WidgetTester
tester
,
String
text
)
{
final
Opacity
opacityWidget
=
tester
.
widget
<
Opac
ity
>(
bool
_labelVisibil
ity
(
WidgetTester
tester
,
String
text
)
{
final
Visibility
visibilityWidget
=
tester
.
widget
<
Visibil
ity
>(
find
.
ancestor
(
of:
find
.
text
(
text
),
matching:
find
.
byType
(
Opac
ity
),
matching:
find
.
byType
(
Visibil
ity
),
),
);
return
opacityWidget
.
opacity
;
return
visibilityWidget
.
visible
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment