我在将TextField
放置在AppBar
上遇到了问题,以便用户可以输入内容,类似于使用搜索栏。我需要获取用户输入并对其执行某些操作,因此这不是我的应用程序内部的搜索。这就是为什么使用TextField
是有意义的。
现在,我已成功将TextField
放置在我的AppBar
左侧。问题是TextField
是一个正方形,不占据足够的空间,因此您无法看到自己正在编写的内容。
链接指向它的外观:
以下是代码实现:
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Myseum',
theme: new ThemeData(
primarySwatch: Colors.blue,
fontFamily: 'Raleway',
),
home: Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text(
"Myseum",
style: TextStyle(
fontFamily: 'Raleway',
fontStyle: FontStyle.italic,
fontSize: 25,
),
),
leading: prefix0.TextBox(), // TextBox is the widget I made.
backgroundColor: Colors.black,
),
现在小部件是TextBox()
class TextBox extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
alignment: Alignment.centerLeft,
color: Colors.white,
child: TextField(
decoration:
InputDecoration(border: InputBorder.none, hintText: 'Search'),
),
);
}
}
title
组件中。 - diegoveloper