如何解决Flutter 使文本字段与键盘一起上升
我在底部导航栏中有一个文本字段。我正在制作一个聊天屏幕,所以当用户点击文本字段时,键盘会向上移动,但文本字段会向下移动并且不会向上移动。我尝试了很多解决方案,但没有任何效果,我真的被卡住了。 颤振版
颤振 1.26.0-1.0.pre
return Scaffold(
resizetoAvoidBottomInset: false,backgroundColor: Palette.primary,appBar: MyAppBar(),body: MyBody(),bottomNavigationBar: TextField(
maxLength: 255,decoration: Inputdecoration(
hintText: " write here",focusedBorder: InputBorder.none,enabledBorder: InputBorder.none,errorBorder: InputBorder.none,disabledBorder: InputBorder.none,border: null,hintStyle: GoogleFonts.getFont('Tajawal',color: Colors.white,fontWeight: FontWeight.w500),counterText: "",),style: GoogleFonts.getFont('Tajawal',fontSize: 17,);
}
}
解决方法
您可以将文本字段包装在列表视图中
将反向命名参数设置为 true,然后调用 reversed
getter 并运行 tolist
函数
ListView(
reverse: true,children: <Widget>[
TextFormField(
decoration: InputDecoration(
labelText: 'I move!',),].reversed.toList(),
结果:
完整代码
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
debugShowCheckedModeBanner: false,title: ' Demo',theme: new ThemeData(
primaryColor: new Color(0xFFFF0000),home: new FormDemo(),);
}
}
class FormDemo extends StatefulWidget {
@override
_FormDemoState createState() => _FormDemoState();
}
class _FormDemoState extends State<FormDemo> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(''),body: Container(
padding: const EdgeInsets.all(20.0),child: new ListView(
reverse: true,);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。