我正在尝试将 Textformfield 的第一个字母大写,为此我使用
textCapitalization: TextCapitalization.words,
Run Code Online (Sandbox Code Playgroud)
但它不适用于Textformfield,并且适用于textfield
请帮助如何做到这一点。
我查看 TextFormField,这里的字段不是我需要的:
onChanged(在按下每个键后调用,我需要当用户已经完成并退出 TextFormField 焦点时)onEditingComplete(在用户按下完成键或类似键后调用,但用户可以退出 TextFormField 焦点而不点击这些按钮)onSave(在调用后调用form.save()。但我需要在用户完成编辑后执行此操作,以让用户知道该应用程序会“自动更正”用户输入的内容)validator(也曾呼吁过form.validate(),就在之前form.save()。不是我需要的)我需要当用户退出焦点(关闭键盘或点击另一个文本字段)时,我进行处理,让用户看到他们的输入正在被调整和处理为“正确的”。我怎样才能捕捉到这样的事件?
我们有一个 flutter 中的 Web 项目,有时空格按钮在文本表单字段中不起作用。刷新页面后,或向服务器发出请求后,它会再次工作。这种情况给我们的用户带来了不稳定的环境,并因此产生了大量的投诉。对于这个“有时无法使用空格按钮”问题,是否有任何官方文档或 flutter 的解决方案。我们注意到,当出现此问题时,字体与应有的不同,就像未加载一样。它不是特定于浏览器的,因为问题发生在
我需要更改文本表单字段内光标的位置。我设法将光标的高度减小 1,但光标的位置仍然位于顶部。我无法将其移动到底部。
我想实现这个目标:
但我实现的是:
Flutter 有没有办法做到这一点?
我的代码示例
TextFormField(
style: TextStyle(
color: Theme.of(context).textTheme.bodySmall?.color,
fontSize: 14,
),
minLines: 1,
maxLines: 1,
maxLength: 300,
cursorColor: Theme.of(context).hintColor,
textAlignVertical: TextAlignVertical.center,
cursorHeight: 1,
cursorWidth: 15,
);
Run Code Online (Sandbox Code Playgroud) 是否可以显示TextField如下图所示的提示?

我有以下文本字段
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Playground',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const Scaffold(
backgroundColor: Colors.green,
body: Align(
alignment: Alignment.bottomCenter,
child: ResponsiveInput(),
),
);
}
}
class ResponsiveInput extends StatelessWidget {
const ResponsiveInput({Key? key}) : …Run Code Online (Sandbox Code Playgroud) 如何删除颤振中 TextFormField 中前缀图标后的空格?我已经尝试过 isCollapsed = true、isDense = true。我已经设置了 contentPadding:EdgeInsets.all(0)。然而,使用 prefix 而不是 prefixIcon 解决了我的问题,但还有另一个问题。前缀仅出现在焦点上。如何解决我的问题?我希望前缀(或 prefixIcon)在开头始终可见。并且 TextFormField 的文本必须类似于前缀的 continue 。
我似乎无法找到一种方法来小部件测试 TextFormField 是否将 obliqueText 设置为 true 或 false。
我知道 TextFormField 是 TextField 的包装器,而 obliqueText 是 TextField 的属性,但无法想出在我的测试中访问 obliqueText 的方法。
因此,当我尝试访问 obscureText 时,我收到消息: The getter 'obscureText' isn't Defined for the type 'TextFormField'
有人知道如何测试 TextFormField 的 obliqueText 属性吗?
testWidgets(
'show and hide password fields',
(
WidgetTester tester,
) async {
await tester.pumpWidget(
materialWrapper(
child: emailSignUpScreen,
),
);
final Finder passwordTextFormField = find.byKey(
const Key(
'passwordTextFormField',
),
);
final TextFormField input =
tester.widget<TextFormField>(passwordTextFormField);
expect(input.obscureText, true);
},
);
Run Code Online (Sandbox Code Playgroud) 我在TextField中添加了验证器,但验证器在提交数据时不起作用。保存按钮保存空值数据。
import 'package:cloud_firestore/cloud_firestore.dart';
import '../../screens/orders/order_success.dart';
import '../../services/global_methods.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
class PlaceOrder extends StatefulWidget {
static const routeName = '/place-order';
const PlaceOrder({Key? key}) : super(key: key);
@override
State<PlaceOrder> createState() => _PlaceOrderState();
}
class _PlaceOrderState extends State<PlaceOrder> {
final _formKey = GlobalKey<FormState>();
String? _name;
int? _phoneNumber;
String? _fullAddress;
String? _area;
String? _city;
String? _addressType;
final TextEditingController _addressController = TextEditingController();
String? _addressValue;
String? _deliverySlotValue;
final FirebaseAuth _auth = FirebaseAuth.instance;
late bool _isLoading = false;
final GlobalMethods _globalMethods = GlobalMethods();
final …Run Code Online (Sandbox Code Playgroud) 与前缀和后缀图标相比,文本表单字段中的提示文本有点升高(感觉好像与两个图标相比是向上的)。
我还附上了用于此 TextFormfield 的代码:
TextFormField(
style:
w400.size12.copyWith(color: BrandColor.foodsearchViewTextColor),
cursorColor: BrandColor.foodsearchViewTextColor,
decoration: InputDecoration(
prefixIcon: Padding(
padding: const EdgeInsets.only(right: 18.0),
child: IconButton(
icon: SvgPicture.asset(
SvgAssets.food_search_icon,
color: BrandColor.foodsearchViewTextColor,
),
onPressed: null,
),
),
suffixIcon: Padding(
padding: const EdgeInsets.only(right: 14.0),
child: IconButton(
icon: SvgPicture.asset(
SvgAssets.food_searchview_suffix,
color: BrandColor.foodsearchViewTextColor,
),
onPressed: null,
),
),
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
focusedErrorBorder: InputBorder.none,
border: InputBorder.none,
hintText: foodSearchText,
hintStyle: w400.size12.copyWith(
color: BrandColor.foodsearchViewTextColor, fontSize: 13)),
),
Run Code Online (Sandbox Code Playgroud)
我也尝试用中心小部件包装文本表单字段,但它没有解决问题。如果有人可以提供帮助,我将非常感激
android-edittext flutter flutter-layout textformfield flutter-textformfield
我有一个包含多个TextFormField 的表单。我希望用户能够使用选项卡移至下一个字段或使用 Shift+Tab 返回。页面如下所示:
当我专注于“合同号”字段并按 Tab 键时,它不会转到组合字段,而是转到使用 NavigationRail 创建的侧面导航中编写的发票。再次按下选项卡时,它会移动到“付款”。在第三个选项卡上,它移至“合成文本字段”。
有什么办法可以修复这种情况发生的顺序吗?