【发布时间】:2020-03-31 06:38:18
【问题描述】:
我正在创建自定义搜索页面。当这个页面打开时,汉堡菜单被隐藏并且搜索文本字段立即改变大小。如何让它顺利进行?
现在我做这个代码
class DefaultAppBar extends StatefulWidget implements PreferredSizeWidget {
@override
Size get preferredSize => Size.fromHeight(56.0);
@override
_DefaultAppBarState createState() => _DefaultAppBarState ();
}
class _DefaultAppBarState extends State<DefaultAppBar> with TickerProviderStateMixin {
AnimationController _controller;
double textWidth = 300.0;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
var future = new Future.delayed(const Duration(milliseconds: 100), ()=>setState(() {
textWidth = 400.00;
}));
return Stack(
children: [
Scaffold(
appBar:AppBar(
centerTitle: true,
automaticallyImplyLeading: false,
// ...
title:AnimatedContainer (
duration: Duration (milliseconds: 500),
width: loginWidth,
// color: Colors.red,
child: TextField(
autofocus: true,
// ...
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
prefixIcon: Icon(Icons.arrow_back,color: Colors.grey),
hintText: 'Search something ...',
border: OutlineInputBorder(borderRadius: BorderRadius.circular(10), borderSide: BorderSide.none),
contentPadding: EdgeInsets.zero,
// border: InputBorder.none,
// hintText: "My Custom Search Label", // KEY PROP
hintStyle: TextStyle(color: Colors.red), // KEY PROP
),
),
),
),
)
]
);
}
}
得到这个结果
工作,但不是很顺利以及如何自动计算 textWidth 的开始和结束以及如何制作像这样的动画https://photos.app.goo.gl/mWpdsouLi4csptKb7
【问题讨论】:
-
解释更多!!!
标签: flutter mobile flutter-animation