我正在尝试使用NumberFromatter,TextInputFormatter但是当我尝试使用它时,它完全搞砸了!这是我的TextInputFormatter实现代码:
class NumericTextFormatter extends TextInputFormatter {
TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) {
if(newValue.text.length > 0) {
int num = int.parse(newValue.text.replaceAll(',', ''));
final f = new NumberFormat("#,###");
return newValue.copyWith(text: f.format(num));
} else {
return newValue.copyWith(text: '');
}
}
}
Run Code Online (Sandbox Code Playgroud)
因此,当我将此格式化程序添加到 aTextField并尝试键入 1 到 9 时,我希望看到的内容类似于:123,456,789
但这是显示在TextField:
1
12
123
1,234
12,354 <- this is where it starts
123,564
1,235,674
12,356,874 <- and it happends again
Run Code Online (Sandbox Code Playgroud)
添加一个 , 字符后,光标似乎会移动。那么有人可以帮我解决这个问题吗?
当我尝试开发 Flutter应用程序(不是包等)时,在src文件夹内的子文件夹中创建所有应用程序文件和文件夹有什么好处lib吗?
所以我在 Flutter 的项目管理应用程序中有一个 listview.builder 。这个列表视图充满了任务(它们可以是:新的、开始的、完成的)。我从 API 获取这些数据,并希望“新”的数据出现在顶部,开始的数据出现在中间,“已完成”的数据出现在底部!-这是现在的样子 这是我的Class,请注意我从 API/JSON 获取状态
class ProjectTask {
final int id;
final String description;
final String state;
final List assigned_users;
final List subtasks;
ProjectTask(this.id,
this.description,
this.state,
this.assigned_users,
this.subtasks);
}
Run Code Online (Sandbox Code Playgroud)
列表视图
else return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int index) {
if(snapshot.data[index].state == "done") {
return Slidable(
//SLIDABLE STUFF
delegate: SlidableStrechDelegate(),
actionExtentRatio: 0.25,
actions: <Widget>[
//ACTION ONE
IconSlideAction(
caption: ("Information"),
foregroundColor: Colors.white,
color: Colors.black38,
icon: Icons.info,
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (context)=>projectTask(snapshot.data[index]))); …Run Code Online (Sandbox Code Playgroud) 我需要DatabaseReference在 firebase 中迭代一个节点。但是连图书馆里没有那个forEach功能!DataSnapshotfirebase_database
我还尝试使用库中的DataSnapshot对象firebase(其中包含 forEach 函数),但出现错误:
[dart] The argument type '(DataSnapshot) ? List<dynamic>' can't be assigned to the parameter type '(DataSnapshot) ? FutureOr<dynamic>'.
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
getAccountsList() {
return firebaseDbService.getAccounts().once().then((DataSnapshot snapshot) {
var list = [];
snapshot.forEach((DataSnapshot account) => list.add({
'id': snapshot.key,
'name': snapshot.child('name').val(),
}));
return list;
});
}
Run Code Online (Sandbox Code Playgroud)