-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[vector_graphics] Allow transition between placeholder and loaded image to have an animation #8195
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
auto-submit
merged 15 commits into
flutter:main
from
raju-muliyashiya:vector-graphics-transition-enhancement
Feb 5, 2025
Merged
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
91b9e6d
[vector_graphics] Allow transition between placeholder and loaded ima…
raju-muliyashiya 5fb0571
Merge remote-tracking branch 'origin/main' into vector-graphics-trans…
raju-muliyashiya d2c51f9
[vector_graphics] version pump
raju-muliyashiya 07a6931
[vector_graphics] removed un-used asset
raju-muliyashiya ad64be4
[vector_graphics] change log added
raju-muliyashiya 018b454
[vector_graphics] re-format code
raju-muliyashiya a88f20f
Merge branch 'main' into vector-graphics-transition-enhancement
raju-muliyashiya 4b11672
Merge branch 'main' into vector-graphics-transition-enhancement
raju-muliyashiya 3912d29
Merge branch 'flutter:main' into vector-graphics-transition-enhancement
raju-muliyashiya 56beb50
[vector_graphics] removed default Duration for animation
raju-muliyashiya 60b3300
Merge branch 'flutter:main' into vector-graphics-transition-enhancement
raju-muliyashiya 67cb047
[vector_graphics] removed default Duration for animation
raju-muliyashiya 65c0768
[vector_graphics] removed default Duration for animation
raju-muliyashiya 5489268
Merge remote-tracking branch 'origin/main' into vector-graphics-trans…
raju-muliyashiya 7bfb80f
[vector_graphics] removed default Duration for animation
raju-muliyashiya 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 |
|---|---|---|
|
|
@@ -61,6 +61,7 @@ VectorGraphic createCompatVectorGraphic({ | |
| String? semanticsLabel, | ||
| bool excludeFromSemantics = false, | ||
| Clip clipBehavior = Clip.hardEdge, | ||
| Duration transitionDuration = const Duration(milliseconds: 500), | ||
| WidgetBuilder? placeholderBuilder, | ||
| VectorGraphicsErrorWidget? errorBuilder, | ||
| ColorFilter? colorFilter, | ||
|
|
@@ -79,6 +80,7 @@ VectorGraphic createCompatVectorGraphic({ | |
| semanticsLabel: semanticsLabel, | ||
| excludeFromSemantics: excludeFromSemantics, | ||
| clipBehavior: clipBehavior, | ||
| transitionDuration: transitionDuration, | ||
| placeholderBuilder: placeholderBuilder, | ||
| errorBuilder: errorBuilder, | ||
| colorFilter: colorFilter, | ||
|
|
@@ -118,6 +120,7 @@ class VectorGraphic extends StatefulWidget { | |
| this.semanticsLabel, | ||
| this.excludeFromSemantics = false, | ||
| this.clipBehavior = Clip.hardEdge, | ||
| this.transitionDuration, | ||
| this.placeholderBuilder, | ||
| this.errorBuilder, | ||
| this.colorFilter, | ||
|
|
@@ -137,6 +140,7 @@ class VectorGraphic extends StatefulWidget { | |
| this.semanticsLabel, | ||
| this.excludeFromSemantics = false, | ||
| this.clipBehavior = Clip.hardEdge, | ||
| this.transitionDuration, | ||
| this.placeholderBuilder, | ||
| this.errorBuilder, | ||
| this.colorFilter, | ||
|
|
@@ -218,6 +222,9 @@ class VectorGraphic extends StatefulWidget { | |
| /// A callback that fires if some exception happens during data acquisition or decoding. | ||
| final VectorGraphicsErrorWidget? errorBuilder; | ||
|
|
||
| /// Set transition duration while switching from placeholder to url image | ||
| final Duration? transitionDuration; | ||
|
|
||
| /// If provided, a color filter to apply to the vector graphic when painting. | ||
| /// | ||
| /// For example, `ColorFilter.mode(Colors.red, BlendMode.srcIn)` to give the vector | ||
|
|
@@ -510,11 +517,24 @@ class _VectorGraphicWidgetState extends State<VectorGraphic> { | |
| _stackTrace ?? StackTrace.empty, | ||
| ); | ||
| } else { | ||
| child = widget.placeholderBuilder?.call(context) ?? | ||
| SizedBox( | ||
| width: widget.width, | ||
| height: widget.height, | ||
| ); | ||
| child = widget.placeholderBuilder != null | ||
|
||
| ? widget.transitionDuration != null | ||
| ? AnimatedSwitcher( | ||
| duration: widget.transitionDuration!, | ||
| child: widget.placeholderBuilder!.call(context), | ||
| transitionBuilder: | ||
| (Widget child, Animation<double> animation) { | ||
| return FadeTransition( | ||
| opacity: animation, | ||
| child: child, | ||
| ); | ||
| }, | ||
| ) | ||
| : widget.placeholderBuilder!.call(context) | ||
| : SizedBox( | ||
| width: widget.width, | ||
| height: widget.height, | ||
| ); | ||
| } | ||
|
|
||
| if (!widget.excludeFromSemantics) { | ||
|
|
||
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
Oops, something went wrong.
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.
This doesn't just allow the transition, it forces it on for all apps. should this be opt in if a transition duration is specififed?
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.
To clarify, by providing a default value here and having the value be non-nullable, you will make all vector graphics fade in over 0.5 seconds. You must change this to be nullable with a null default or I will not accept the change