ไม่สามารถกำหนดประเภทอาร์กิวเมนต์ 'int' ให้กับสตริงพารามิเตอร์กระพือ
Aug 19 2020
ฉันกำลังทำงานกับ flutter และฉันสามารถแยกวิเคราะห์คำขอ api ของฉันโดยใช้ dio ได้อย่างสมบูรณ์แบบ แต่หลังจากแสดงรายการของฉันแทนที่จะบันทึกผลรวมทั้งหมดในฐานข้อมูลฉันต้องการแสดงผลรวมของผู้ใช้สองคอลัมน์จากฐานข้อมูล แต่ฉันพบประเภทอาร์กิวเมนต์ ' ไม่สามารถกำหนด int 'ให้กับข้อผิดพลาดสตริงพารามิเตอร์นี่คือรหัสของฉัน
? ListView.builder(
itemCount: filteredItems.length,
itemBuilder: (BuildContext context, int index) {
return GestureDetector(
onTap: () {
Navigator.of(context).pushNamed(PostDetail.routeName, arguments: filteredItems[index]);
},
child: Card(
elevation: 10,
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 10, horizontal: 8),
child: Column(
children: <Widget>[
Text(
filteredItems[index]['product_name'],
style: TextStyle(fontSize: 18),
),
Text(
// here i need to display two columans from database but error appers here
int.parse( filteredItems[index]['priceOne'])- int parse(filteredItems[index]['priceDisc']);
),
],
),
),
),
);
})
คำตอบ
1 Uni Aug 19 2020 at 18:32
ซึ่งจะไม่แสดงข้อความใด ๆ อย่างแน่นอนเนื่องจากText
วิดเจ็ตต้องการกString
. สิ่งที่คุณต้องทำคือแปลงint
เป็น a String
เพื่อแสดง นี่คือตัวอย่าง:
Text((int.parse(filteredItems[index]['priceOne'])- int.parse(filteredItems[index]['priceDisc'])).toString()),
1 Captivity Aug 19 2020 at 18:34
คุณไม่สามารถแสดงเป็นข้อความได้: Text( int.parse( filteredItems[index]['priceOne'])- int parse(filteredItems[index]['priceDisc']); )
คุณต้องเขียนตัวอย่างเช่น:
Row(
children: [
Text(
filteredItems[index]['priceOne'] + ' - '),
Text(filteredItems[index]['priceDisc'])
]
or:
Text((int.parse(filteredItems[index]['priceOne'])- int.parse(filteredItems[index]['priceDisc'])).toString()),