dart - 键盘上方的颤振/飞镖滚动文本字段
解决方案
好的,首先,您粘贴的代码不完整,所以我猜您将这些文本字段放在列中。您有两个选择:
1st)在您的 Scaffold 中,您可以将此属性设置为 false,例如resizeToAvoidBottomInset: false,
2o)您可以使用SingleChildScrollView,它会在键盘出现时向上移动您的文本字段,例如:
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
body: SingleChildScrollView(
child: MyLoginPage(title: 'Flutter Demo Home Page'),
),
),
);
}
}
class MyLoginPage extends StatefulWidget {
MyLoginPage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyLoginPageState createState() => _MyLoginPageState();
}
class _MyLoginPageState extends State<MyLoginPage> {
String _email;
String _password;
TextStyle style = TextStyle(fontSize: 25.0);
@override
Widget build(BuildContext context) {
final emailField = TextField(
obscureText: false,
style: style,
decoration: InputDecoration(
contentPadding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
prefixIcon: Icon(FontAwesomeIcons.solidEnvelope),
hintText: "Email",
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red[300], width: 32.0),
borderRadius: BorderRadius.circular(97.0))),
onChanged: (value) {
setState(() {
_email = value;
});
},
);
final passwordField = TextField(
obscureText: true,
style: style,
decoration: InputDecoration(
contentPadding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
prefixIcon: Icon(FontAwesomeIcons.key),
hintText: "Password",
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red[300], width: 32.0),
borderRadius: BorderRadius.circular(25.0))),
onChanged: (value) {
setState(() {
_password = value;
});
},
);
return Center(
child: Column(
children: <Widget>[
Container(
color: Colors.yellow[300],
height: 300.0,
),
emailField,
passwordField
],
),
);
}
}
只需复制并粘贴代码,看看它是否是您想要的。
希望这有帮助。
推荐阅读
- graphql - Shopify graphql 客户创建
- python - 无法使用 Python Pyautogui 以管理员身份打开 CMD
- javascript - React FilePond 预览 [ 文件海报 ] 不工作
- scala - 如何使用 SparkSQL 从数据框列中获取值?
- python - GPIO控制在while true:
- arrays - 创建具有固定数量元素但仍少于固定数量的随机生成数组
- html - CSS 自定义复选框
- html - 为什么 div 会越过图像?
- javascript - 以 PDF 格式下载 HTML 表格
- python - 如何从存在轻微背景的图像中提取文本?