- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
为什么会报错Another exception was thrown: FormatException: Invalid number (at character 1)
在一切恢复正常之前,我的屏幕上会出现几微秒。有时它甚至不会发生。下面是我的 StreamBuilder 函数:
_delivered() {
print('In the delivered function:${resId},${customerId}, ');
return StreamBuilder<QuerySnapshot>(
stream: Firestore.instance
.collection('restaurants')
.document(resId)
.collection('customers')
.document(customer)
.collection('orders')
.where('deliveryTime', isGreaterThan: '')
.snapshots(),
builder: (context, snapshot) {
print('Does snapshop have data? ${snapshot.hasData}');
if (!snapshot.hasData) return Container();
List deliveredListFromServer = snapshot.data.documents;
return Expanded(
child: ListView(
shrinkWrap: true,
children: deliveredListFromServer.map((item) {
print('document id: ${item.documentID}');
return InkWell(
child: SizedBox(
height: 50,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(
width: 80,
child: Text(
item['orderBy']['username'],
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontWeight: FontWeight.bold),
),
),
SizedBox(
width: 5,
),
Expanded(
child: ListView(
scrollDirection: Axis.horizontal,
children: item['order'].map<Widget>((item) {
return SizedBox(
width: 80,
child: Align(
alignment: Alignment.centerLeft,
child: Text(
'${item['qty']} ${item['drinkName']}',
overflow: TextOverflow.ellipsis,
),
),
);
}).toList(),
), //
),
SizedBox(
width: 5,
),
SizedBox(
width: 60,
child: Text(DateFormat('h:mm a').format(
DateTime.fromMillisecondsSinceEpoch(
int.parse(item['deliveryTime'])))),
)
],
),
),
onTap: () {
_deliveredDetail(item);
},
);
}).toList(),
),
);
});
}
I/flutter (11506): In the delivered function:XufIsxA8a24lLhO6gTr1,zMrQmcoQwci9bVVRo6tx,
I/flutter (11506): Does snapshop have data? true
I/flutter (11506): document id: 1579534059562
I/flutter (11506): document id: 1579595374166
I/flutter (11506): Another exception was thrown: FormatException: Invalid number (at character 1)
I/flutter (11506): Does snapshop have data? true
I/flutter (11506): document id: 1579534059562
document id: 1579595374166
从数据库。只有
document id: 1579534059562
有一个 deliveryTime 设置。数据库有 6 条记录,只有一条记录设置了 deliveryTime。其他都是空的
""
字符串。
I/flutter (11506): In the delivered function:XufIsxA8a24lLhO6gTr1,zMrQmcoQwci9bVVRo6tx,
I/flutter (11506): Does snapshop have data? false
I/flutter (11506): Does snapshop have data? true
I/flutter (11506): document id: 1579534059562
streamBuilder
正在向列表传递不正确的数据(以及可能的错误来源)。为什么查询有时会返回错误的结果?!
最佳答案
它再次发生,现在我知道为什么了。在代码中,它实际上是在这一行 int.parse(item['deliveryTime'])
中的问题因为在 parse()
方法 如果输入字符串不是有效的整数形式,程序将抛出 FormatException:
所以为了处理这个案子,
int.tryParse(item['deliveryTime']) ?? defaultValue;
你也可以使用 Dart try-catch 块:
try {
var n = int.parse(item['deliveryTime']);
print(n);
} on FormatException {
print('Format error!');
}
// Format error!
int类
parse()
方法也给了我们处理
FormatException
的方法带有 onError 参数的情况。
var num4 = int.parse(item['deliveryTime'], onError: (source) => -1);
// -1
抛出异常时,
onError
将使用 source 作为输入字符串调用。现在我们可以返回一个整数值或空值……在上面的例子中,函数返回
-1
每当
source
在错误的整数文字中。
关于flutter - 抛出了另一个异常 : FormatException: Invalid number (at character 1),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59853750/
int i; System.out.print("Please enter a string: "); String string_1 = input.nextLine(); System.out
我想要一个正则表达式来检查 a password must be eight characters including one uppercase letter, one special charac
在此先感谢您的帮助。 在命令行输入“example”时,Python 返回“example”。我在网上找不到任何东西来解释这一点。所有引用资料都在 print 命令的上下文中谈到字符串,我得到了所有关
我有 CSV 格式的数据,这些数据在字符编码方面被严重打乱,可能在不同的软件应用程序(LibreOffice Calc、Microsoft、Excel、Google Refine、自定义 PHP/My
我正在为 Latex 使用 Sublime Text,所以我需要使用特定的编码。但是,在某些情况下,当我粘贴从不同程序(大多数情况下为单词/浏览器)复制的文本时,我收到以下消息: "Not all c
在 flutter 中,我使用了一个php文件,该文件从数据库查询返回json响应,但是当我尝试解码json时,出现此错误: E/flutter ( 8294): [ERROR:flutter/lib
我在 Flutter 项目中遇到异常。错误如下所示: Exception has occurred. FormatException (FormatException: Unexpected char
这个问题已经有答案了: Why doesn't my compare work between char and int in Java? (4 个回答) 已关闭 3 年前。 我试图在我的代码中找出
我在 Flutter 项目中遇到异常。错误如下所示: Exception has occurred. FormatException (FormatException: Unexpected char
我是 python 新手,需要一些帮助。我应该编写一个脚本,从键盘读取单词,直到输入单词 999。对于除 999 之外的每个单词,报告该单词是否有效。如果单词的第一个字符等于最后一个字符,则该单词有效
我正在实现自己的词法分析器,并且刚刚了解了 C# 如何处理字 rune 字:https://msdn.microsoft.com/en-us/library/aa691087(v=vs.71).asp
我有这个字符串: var test = "toto@test.com"; 我想用空值替换“@”字符后的所有字符。我想得到这个字符串: var test = "toto" 最佳答案 试试这个: test
我将数据库从 sqlite 更改为 postgresql 以用于我网站的生产,但出现此错误。当我在本地使用 sqlite 时,它没有出现这个错误。使用 Django。 ProgrammingErr
我正在为我的实验表制作凯撒密码,并使其能够加密 3 代入(凯撒密码),这是练习的重点。但是有一件事困扰着我。首先,如果我输入 3 以外的字符,则有一个尾随字符。例如,输入“恶意软件”,然后输入 2 作
遵循 this question 中的逻辑,以下代码应该有效: #include int main(){ printf("%c", '\0101'); return 0; } 然而,
我在处理一段代码时遇到错误: Too many characters in character literal error 使用 C# 和 switch 语句遍历字符串缓冲区并读取标记,但在这一行中出
给定一个元素,其值为: Distrib = SU & Prem <> 0 我要转<或 >进入 <或 >因为下游应用程序需要
从表面上看,他们似乎都在做同样的事情。但似乎是后者as(,"character")更强大。 作为示例,请考虑以下内容: library(rvest) temp % html_node("div p")
我刚开始使用python,所以很可能只是在做一些愚蠢的事情。我正在从表中读取数据,需要将它们放入txt文件的列中。我无法说服我的代码创建新行。 这是我的代码- file = open("test_m.
在尝试刷新我的项目的 Fortran 90 知识时,我在使用内部文件时遇到了一些奇怪的情况。考虑示例代码: ! ---- internal_file_confusion.f90 ---- progra
我是一名优秀的程序员,十分优秀!