作者:zealyw | 来源:互联网 | 2022-12-21 14:22
我想制作一个粘贴在页面底部的小部件,然后将其固定在键盘的顶部(当它出现时).
请注意输入文本字段如何固定到下图中的键盘:
我该怎么做?我试过把它放进去bottomNavigationBar
,但这(显然)不起作用.有没有内置的方法来做到这一点?
1> Kevin Walter..:
这是你想要的事情的一个实例.我认为!只需复制/粘贴/运行
在这个例子中重要的是Expanded.一个非常好的小部件,可以扩展到尽可能多的空间.并在结果中尽可能地向下推动聊天框
(屏幕底部或键盘底部)
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('49715760 Stackoverflow'),
),
body: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
new Expanded(
child: new Material(
color: Colors.red,
child: new Text("Filled"),
),
),
new Container(
color: Colors.white,
padding: new EdgeInsets.all(10.0),
child: new TextField(
decoration: new InputDecoration(
hintText: 'Chat message',
),
),
),
],
),
);
}
}