gpt4 book ai didi

flutter - 如何在 Flutter 的文本输入字段中配置自动大写行为?

转载 作者:IT老高 更新时间:2023-10-28 12:36:44 44 4
gpt4 key购买 nike

我正在 Windows 上试验 Flutter 开发。我有一个带有 InputField 的简单测试应用程序。我希望第一个键盘条目是大写字母,但目前看不到实现这一目标的方法(例如,按下 shift 启动键盘)。有什么想法吗?

代码(有点简化)是:

import 'package:flutter/material.dart';

void main() {
runApp(new MaterialApp(
theme: new ThemeData.dark(),
home: new MainScreen()
));
}

class MainScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
leading: new IconButton(
icon: new Icon(Icons.menu),
tooltip: 'Navigation menu',
onPressed: null,
),
title: new Text('Test'),
),
body: new NewTest(),
);
}
}

/// Widget
class NewTest extends StatefulWidget {
@override
_NewTestInputState createState() => new _NewTestInputState();
}
/// State
class _NewTestInputState extends State<NewTest> {
InputValue _currentInput;

void _handleInputChange(InputValue input) {
if (input != _currentInput){
setState(() {
_currentInput = input;
});
}
}

void _handleInputSubmitted(InputValue input) {
setState(() {
_currentInput = const InputValue();
});
}

@override
Widget build(BuildContext context) {
InputField _widget = new InputField(
value: _currentInput,
hintText: 'Enter text',
keyboardType: TextInputType.text,
autofocus: true,
onChanged: _handleInputChange,
onSubmitted: _handleInputSubmitted,
style: new TextStyle(fontSize: 20.0),
);
Container _container = new Container(
child: _widget,
decoration: new BoxDecoration(
border: new Border.all(
color: Colors.green[300],
width: 2.0,
),
),
padding: new EdgeInsets.all(16.0),
);
return _container;
}
}

最佳答案

Flutter 有一个用于文本字段的 textCapitalization 属性。将此属性设置为 TextCapitalization.sentences 或任何可用值,例如 .characters 或 .words 像这样:

TextField(
keyboardType: TextInputType.text,
**textCapitalization: TextCapitalization.sentences,**
style: TextStyle(
fontSize: 30.0,
color: Colors.black,
fontWeight: FontWeight.bold
),
)

关于flutter - 如何在 Flutter 的文本输入字段中配置自动大写行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42747394/

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