mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Explain why Opacity could be slow (#24255)
This commit is contained in:
parent
5251306886
commit
d9ad220bbb
@ -156,12 +156,17 @@ class Directionality extends InheritedWidget {
|
||||
///
|
||||
/// ## Transparent image
|
||||
///
|
||||
/// If only a single [Image] needs to be composited with an opacity between 0.0
|
||||
/// and 1.0, it's much faster to directly use [Image].
|
||||
/// If only a single [Image] or [Color] needs to be composited with an opacity
|
||||
/// between 0.0 and 1.0, it's much faster to directly use them without [Opacity]
|
||||
/// widgets.
|
||||
///
|
||||
/// For example, `Container(color: Color.fromRGBO(255, 0, 0, 0.5))` is much
|
||||
/// faster than `Opacity(opacity: 0.5, child: Container(color: Colors.red))`.
|
||||
///
|
||||
/// {@tool sample}
|
||||
///
|
||||
/// This example draws an [Image] with 0.5 opacity:
|
||||
/// The following example draws an [Image] with 0.5 opacity without using
|
||||
/// [Opacity]:
|
||||
///
|
||||
/// ```dart
|
||||
/// Image.network(
|
||||
@ -170,8 +175,15 @@ class Directionality extends InheritedWidget {
|
||||
/// colorBlendMode: BlendMode.modulate
|
||||
/// )
|
||||
/// ```
|
||||
///
|
||||
/// {@end-tool}
|
||||
///
|
||||
/// Directly drawing an [Image] or [Color] with opacity is faster than using
|
||||
/// [Opacity] on top of them because [Opacity] could apply the opacity to a
|
||||
/// group of widgets and therefore a costly offscreen buffer will be used.
|
||||
/// Drawing content into the offscreen buffer may also trigger render target
|
||||
/// switches and such switching is particularly slow in older GPUs.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [Visibility], which can hide a child more efficiently (albeit less
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user