// Copyright 2021 The Flutter team. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. import 'package:flutter/widgets.dart'; import 'animations.dart'; class BarTransition extends StatefulWidget { const BarTransition({ super.key, required this.animation, required this.backgroundColor, required this.child, }); final Animation animation; final Color backgroundColor; final Widget child; @override State createState() => _BarTransition(); } class _BarTransition extends State { late final Animation offsetAnimation; late final Animation heightAnimation; @override void initState() { super.initState(); offsetAnimation = Tween( begin: const Offset(0, 1), end: Offset.zero, ).animate(OffsetAnimation(widget.animation)); heightAnimation = Tween( begin: 0, end: 1, ).animate(SizeAnimation(widget.animation)); } @override Widget build(BuildContext context) { return ClipRect( child: DecoratedBox( decoration: BoxDecoration(color: widget.backgroundColor), child: Align( alignment: Alignment.topLeft, heightFactor: heightAnimation.value, child: FractionalTranslation( translation: offsetAnimation.value, child: widget.child, ), ), ), ); } }