【发布时间】:2020-11-08 14:03:36
【问题描述】:
我想将文本表单域中的每 3 个字符串分开并显示在
我已经尝试过regex 我可以在终端中获取它,但我无法在 textformfield 中显示它,使它看起来像终端,enter image description here
在左侧,当我打印它时,我有我想要的东西,但在右侧,我有我的 textformfield
我想完全像终端一样显示它,但在 textformfield 中
这是我的代码
如果您需要更多信息,请告诉我
import 'package:flutter/material.dart';
class AddTransication extends StatefulWidget {
@override
_AddTransicationState createState() => _AddTransicationState();
}
class _AddTransicationState extends State<AddTransication> {
RegExp reg_ex = new RegExp(r'(\d{1,3})(?=(\d{3})+(?!\d))');
Function mathFunc = (Match match) => '${match[1]},';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Test Screen"),
actions: <Widget>[
FlatButton(
textColor: Colors.white,
onPressed: () {},
child: Text("Save"),
shape: CircleBorder(side: BorderSide(color: Colors.transparent)),
),
],
),
body: SafeArea(
child: Form(
child: Column(
children: [emailField(reg_ex, mathFunc)],
),
),
),
);
}
Widget emailField(reg_ex, mathFunc) {
return TextFormField(
onChanged: (str) {
String result = str.replaceAllMapped(reg_ex, mathFunc);
print(' $result');
},
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
labelText: 'Email Address',
hintText: 'you@example.com',
),
);
}
}
更新!
我还希望它返回一个有效的 int,就像我写 1000 时它应该返回 10,000,我已经用正则表达式做到了,但我想在那里显示它【问题讨论】: