我想允许用户只添加数字“12345”和十进制数字(如“21321.12312”)和负数(如-23423.32432)。用户不应该能够添加多个“.” 比如“12..32”,并在第一个输入中添加“-”,比如-324.34,而不是324-4323。我使用了这个正则表达式r'^(-?\d+\.\d+)(\s*,\s*-?\d+\.\d+)+$',但无法输入任何内容。
文本字段代码:
TextFormField(
inputFormatters: [
FilteringTextInputFormatter.allow(
RegExp(r'^(-?\d+\.\d+)(\s*,\s*-?\d+\.\d+)+$')),
],
controller: budget,
keyboardType: TextInputType.number,
decoration: InputDecoration(
contentPadding:
EdgeInsets.only(right: 20, left: 20, top: 10, bottom: 10),
hintText: getTranslated(context, "budget_example"),
hintStyle: TextStyle(fontSize: 13, fontFamily: "tahoma"),
border: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: MyColors.secondary),
borderRadius: BorderRadius.circular(100),
),
),
),
Run Code Online (Sandbox Code Playgroud) 我听说它用于大型项目中的状态管理。使用 Bloc 模式很好。但是我在 GitHub 上知道的每个项目以及我看过的每个教程都在制作一个像 Bloc 登录页面这样的小项目。我不明白为什么建议在大型项目中使用 Bloc,因为要在页面上创建每个状态和事件,我们应该创建一个将事件更改为状态的新 Bloc 类。这似乎不是很好。你能介绍一些使用 Bloc 模式的大型 Flutter 项目吗?
我在更改广播列表图块图标颜色时遇到问题。我尝试使用 ListTileTheme 但没有成功。顺便说一句,我在对话框中使用 RadioListTile,但我认为这不会影响它。
代码。
ListTileTheme(
iconColor: AppColors.green,
textColor: AppColors.green,
child: SimpleDialog(
shape:
RoundedRectangleBorder(
borderRadius:
BorderRadius
.circular(10),
),
title: Text(
"Select Restaurant",
style: Theme.of(context)
.textTheme
.headline3,
textAlign:
TextAlign.center,
),
children: [
Divider(),
RadioListTile(
title: const Text(
'Name and Address'),
value: 1,
groupValue:
_isRadioSelected,
onChanged: (v) {
setState(() {
_isRadioSelected =
v;
});
},
),
],
),
);
Run Code Online (Sandbox Code Playgroud)