@@ -52,62 +52,75 @@ class _ShaderAnimationViewState extends State<ShaderAnimationView> with SingleTi
5252
5353 @override
5454 Widget build (BuildContext context) {
55- return ColoredBox (
56- color: widget.shaderInfo.backgroundColor ?? Colors .transparent,
57- child: Padding (
58- padding: widget.shaderInfo.padding ?? EdgeInsets .zero,
59- child: LayoutBuilder (
60- builder: (context, size) {
61- return AnimatedBuilder (
62- animation: _controller,
63- builder: (context, child) {
64- return ShaderBuilder (
65- assetKey: widget.shaderInfo.assetKey,
66- (context, shader, _) {
67- final duration = widget.shaderInfo.builder.animationDuration;
68- double timeValue;
55+ Widget child = Padding (
56+ padding: widget.shaderInfo.padding ?? EdgeInsets .zero,
57+ child: LayoutBuilder (
58+ builder: (context, size) {
59+ return AnimatedBuilder (
60+ animation: _controller,
61+ builder: (context, child) {
62+ return ShaderBuilder (
63+ assetKey: widget.shaderInfo.assetKey,
64+ (context, shader, _) {
65+ final duration = widget.shaderInfo.builder.animationDuration;
66+ double timeValue;
6967
70- if (duration != null ) {
71- // Bounded animation - use animated value between 0-1
72- final animation = TweenSequence <double >([
73- TweenSequenceItem (
74- tween: Tween <double >(
75- begin: 0.0 ,
76- end: 1.0 ,
77- ).chain (CurveTween (curve: Curves .easeInOut)),
78- weight: 50.0 ,
79- ),
80- TweenSequenceItem (
81- tween: Tween <double >(
82- begin: 1.0 ,
83- end: 0.0 ,
84- ).chain (CurveTween (curve: Curves .easeInOut)),
85- weight: 50.0 ,
86- ),
87- ]).animate (_controller);
88- timeValue = animation.value;
89- } else {
90- // Unbounded animation - use controller value as continuous time
91- // Scale the 0-1 controller value to actual time in seconds
92- timeValue = _controller.value * _controller.duration! .inSeconds;
93- }
68+ if (duration != null ) {
69+ // Bounded animation - use animated value between 0-1
70+ final animation = TweenSequence <double >([
71+ TweenSequenceItem (
72+ tween: Tween <double >(
73+ begin: 0.0 ,
74+ end: 1.0 ,
75+ ).chain (CurveTween (curve: Curves .easeInOut)),
76+ weight: 50.0 ,
77+ ),
78+ TweenSequenceItem (
79+ tween: Tween <double >(
80+ begin: 1.0 ,
81+ end: 0.0 ,
82+ ).chain (CurveTween (curve: Curves .easeInOut)),
83+ weight: 50.0 ,
84+ ),
85+ ]).animate (_controller);
86+ timeValue = animation.value;
87+ } else {
88+ // Unbounded animation - use controller value as continuous time
89+ // Scale the 0-1 controller value to actual time in seconds
90+ timeValue = _controller.value * _controller.duration! .inSeconds;
91+ }
9492
95- widget.shaderInfo.builder.setUniforms (shader, size.biggest, timeValue);
93+ widget.shaderInfo.builder.setUniforms (shader, size.biggest, timeValue);
9694
97- return widget.shaderInfo.builder.buildShader (
98- widget.shaderInfo.metadata,
99- shader,
100- size.biggest,
101- timeValue,
102- widget.shaderInfo.builder.childBuilder (context),
103- );
104- },
105- );
106- },
107- );
108- },
109- ),
95+ return widget.shaderInfo.builder.buildShader (
96+ widget.shaderInfo.metadata,
97+ shader,
98+ size.biggest,
99+ timeValue,
100+ widget.shaderInfo.builder.childBuilder (context),
101+ );
102+ },
103+ );
104+ },
105+ );
106+ },
110107 ),
111108 );
109+
110+ if (widget.shaderInfo.aspectRatio != null ) {
111+ child = AspectRatio (
112+ aspectRatio: widget.shaderInfo.aspectRatio! ,
113+ child: child,
114+ );
115+ }
116+
117+ if (widget.shaderInfo.backgroundColor != null ) {
118+ child = ColoredBox (
119+ color: widget.shaderInfo.backgroundColor! ,
120+ child: Center (child: child),
121+ );
122+ }
123+
124+ return child;
112125 }
113126}
0 commit comments