我需要帮助来实现我的AppBar动画。
我的AppBar在双击时会隐藏,但是它没有动画效果,会立即隐藏。我希望能够添加动画效果。我尝试使用SlideTransition和AnimatedContainer小部件包装我的AppBar,但这两种方法都不起作用,因为报错提示我需要一个PreferredSize小部件。
如果有人能帮助我,我将非常高兴!
我已经查看了这个答案,但是回答这个问题的人也遇到了同样的问题。没有动画效果。 Show (slide in) or hide (slide out) flutter AppBar on screen tap
这里是我的AppBar的视频:https://streamable.com/it7ib
这里是我的AppBar的照片:
代码:
import 'package:flutter/material.dart';
class GeneratedCouponScreen extends StatefulWidget {
@override
_GeneratedCouponScreenState createState() => _GeneratedCouponScreenState();
}
class _GeneratedCouponScreenState extends State<GeneratedCouponScreen> {
bool showAppBar = true;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: showAppBar ? AppBar() : null ,
backgroundColor: Colors.white,
body: GestureDetector(
onDoubleTap: () {
if (showAppBar) {
setState(() {
showAppBar = false;
});
}
else {
setState(() {
showAppBar = true;
});
}
},
child: SafeArea(
child: Container(
padding: EdgeInsets.all(16.0),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('DATA WYDANIA:', style: TextStyle(color: Colors.black),),
Text('10/09/2019', style: TextStyle(color: Colors.black))
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('UNIKALNY KOD:', style: TextStyle(color: Colors.black)),
Text('e-86-tC-9', style: TextStyle(color: Colors.black))
],
)
],
),
Column(
children: [
SizedBox(height: 8.0),
Image.asset('assets/images/coupon_hamburger.png',)
],
)
],
)
),
)));
}
}
appBar: PreferredSize( preferredSize: Size.fromHeight(50.0), // 这里是所需的高度 child: AppBar( // ... ) ),
我认为在应用PreferredSize小部件后,您将能够使您的AppBar动画化。 - Mo Meshkani