gpt4 book ai didi

dart - 键盘上方的 flutter/Dart 滚动文本字段

转载 作者:行者123 更新时间:2023-12-04 21:57:55 25 4
gpt4 key购买 nike

我正在使用文本字段,如何使它在输入电子邮件和密码时向上滚动一点?

这是代码的预览

https://pastebin.com/4EngQDV5

blank

最佳答案

首先,您粘贴的代码不完整,所以我猜您将这些文本字段放在列中。您有两个选择:
1) 在您的 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
],
),
);
}
}

只需复制并粘贴代码,看看它是否是您想要的。
希望这有帮助。

关于dart - 键盘上方的 flutter/Dart 滚动文本字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55839982/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com