@@ -267,11 +267,15 @@ class MaterialBanner extends StatefulWidget {
267
267
268
268
class _MaterialBannerState extends State <MaterialBanner > {
269
269
bool _wasVisible = false ;
270
+ CurvedAnimation ? _heightAnimation;
271
+ CurvedAnimation ? _slideOutCurvedAnimation;
270
272
271
273
@override
272
274
void initState () {
273
275
super .initState ();
274
276
widget.animation? .addStatusListener (_onAnimationStatusChanged);
277
+ _setCurvedAnimations ();
278
+
275
279
}
276
280
277
281
@override
@@ -280,12 +284,31 @@ class _MaterialBannerState extends State<MaterialBanner> {
280
284
if (widget.animation != oldWidget.animation) {
281
285
oldWidget.animation? .removeStatusListener (_onAnimationStatusChanged);
282
286
widget.animation? .addStatusListener (_onAnimationStatusChanged);
287
+ _setCurvedAnimations ();
283
288
}
284
289
}
285
290
291
+ void _setCurvedAnimations () {
292
+ _heightAnimation? .dispose ();
293
+ _slideOutCurvedAnimation? .dispose ();
294
+ if (widget.animation != null ) {
295
+ _heightAnimation = CurvedAnimation (parent: widget.animation! , curve: _materialBannerHeightCurve);
296
+ _slideOutCurvedAnimation = CurvedAnimation (
297
+ parent: widget.animation! ,
298
+ curve: const Threshold (0.0 ),
299
+ );
300
+ } else {
301
+ _heightAnimation = null ;
302
+ _slideOutCurvedAnimation = null ;
303
+ }
304
+
305
+ }
306
+
286
307
@override
287
308
void dispose () {
288
309
widget.animation? .removeStatusListener (_onAnimationStatusChanged);
310
+ _heightAnimation? .dispose ();
311
+ _slideOutCurvedAnimation? .dispose ();
289
312
super .dispose ();
290
313
}
291
314
@@ -408,14 +431,10 @@ class _MaterialBannerState extends State<MaterialBanner> {
408
431
child: materialBanner,
409
432
);
410
433
411
- final CurvedAnimation heightAnimation = CurvedAnimation (parent: widget.animation! , curve: _materialBannerHeightCurve);
412
434
final Animation <Offset > slideOutAnimation = Tween <Offset >(
413
435
begin: const Offset (0.0 , - 1.0 ),
414
436
end: Offset .zero,
415
- ).animate (CurvedAnimation (
416
- parent: widget.animation! ,
417
- curve: const Threshold (0.0 ),
418
- ));
437
+ ).animate (_slideOutCurvedAnimation! );
419
438
420
439
materialBanner = Semantics (
421
440
container: true ,
@@ -436,11 +455,11 @@ class _MaterialBannerState extends State<MaterialBanner> {
436
455
materialBannerTransition = materialBanner;
437
456
} else {
438
457
materialBannerTransition = AnimatedBuilder (
439
- animation: heightAnimation ,
458
+ animation: _heightAnimation ! ,
440
459
builder: (BuildContext context, Widget ? child) {
441
460
return Align (
442
461
alignment: AlignmentDirectional .bottomStart,
443
- heightFactor: heightAnimation .value,
462
+ heightFactor: _heightAnimation ! .value,
444
463
child: child,
445
464
);
446
465
},
0 commit comments