我正在 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
),
)
https://stackoverflow.com/questions/42747394/
相关文章:
dart - Flutter - 通过滑动或按下 floatingActionButton 来展开
android - 可以在 Android Studio 中使用 Flutter 开发 IOS 吗?
dart - 如何更改手机屏幕上的 flutter 应用程序名称显示?
google-maps - Flutter:如何使用新的 Marker API 向 Google M
search - Flutter - 更改 SearchDelegate 的搜索提示文本
dart - 在 Flutter 中显示全屏图像 onTap
flutter - 如何在 flutter 中检索当前的类名?