我正在处理颤振桌面项目,我想检索一些双值,但是当将某个字段作为空字段进行处理并尝试检索数据时,我得到了一个错误,以填充我所有的TextField。如何将这些TextField检查为空字段并检索空值。
错误:-由手势═══════════════════════════════════════════捕获的════════异常在处理手势时引发了以下FormatException:
当抛出异常时,这是堆栈#0 double.parse (dart:core-_HomePageState.build/double_patch.dart:111:28) #1 _HomePageState.build。包裹:城市洗衣/页/主页_页面。省道:992 #2 State.setState包:flutter/…/widgets/Frawork.DAT:1088 #3 _HomePageState.build。包装:城市洗衣/页/主页_页面。省道:975 #4 _InkResponseState._handleTap包:flutter/…/材料/油墨_井口.飞镖:989 #5 GestureRecognizer.invokeCallback包:颤振/…/手势/识别器.…:193 #6 TapGestureRecognizer.handleTapUp包:flutter/…/手势/tap.dart:608 #7 BaseTapGestureRecognizer._checkUp包:颤振/…/手势/tap.dart:296 #8 BaseTapGestureRecognizer.handlePrimaryPointer包:颤振/…/手势/tap.dart:230 #9 PrimaryPointerGestureRecognizer.handleEvent包:颤振/…/手势/识别器.:558 #10 PointerRouter._dispatch包:颤振/…/手势/指针_router.dart:94 #11 PointerRouter._dispatchEventToRoutes。包装:颤振/…/手势/指针_router.dart:139 #12 (dart:collection-patch/compact_hash.dart:400:8) #13 PointerRouter._dispatchEventToRoutes包:flutter/…/手势/指针_router.DAT:137号#14 PointerRouter.route包:flutter/…/手势/指针_router.dart:123 #15 GestureBinding.handleEvent包:flutter/…/手势/binding.dart:440 #16 GestureBinding.dispatchEvent包:颤振/…/手势/binding.dart:420 #17 RendererBinding.dispatchEvent包:颤振/…/渲染/绑定。省:278
代码:-
final price1 = TextEditingController();
final price2 = TextEditingController();
final price3 = TextEditingController();
final deliveryCharge = TextEditingController();
double? p1;
double? p2;
double? p3;
double? delivery;
double total = 0.0;
void priceTotal() {
double p1 = double.parse(price1.text);
double p2 = double.parse(price2.text);
double p3 = double.parse(price3.text);
double delivery = double.parse(deliveryCharge.text);
print(total.toString());
setState(() {
total = (p1 + p2 + p3 + delivery);
});
}TextField :-
Padding(
padding: const EdgeInsets.only(
top: 10.0, left: 10.0),
child: SizedBox(
width: 200.0,
child: TextField(
controller: price3,
decoration: const InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(10.0)),
),
prefixIcon: Padding(
padding: EdgeInsets.all(8.0),
child: FaIcon(
FontAwesomeIcons.rupeeSign,
size: 20.0,
),
),
hintText: 'Price',
),
),
),
),OnPress :-
onPressed: () {
setState(() {
delivery = double.parse(deliveryCharge.text);
p1 = double.parse(price1.text);
p2 = double.parse(price2.text);
p3 = double.parse(price3.text);
priceTotal();
});
},

发布于 2021-09-29 05:31:20
如果数据为null,则可以将其替换为零。让我们试一试。
delivery = double.parse(deliveryCharge.text??"0");
p1 = double.parse(price1.text??"0");
p2 = double.parse(price2.text??"0");
p3 = double.parse(price3.text??"0");https://stackoverflow.com/questions/69370838
复制相似问题