Всякий раз, когда я получаю данные с сервера MySQL и пробираю их из JSON, возникает ошибка и выбрасывает Formatexception специально на Price . Но всякий раз, когда я пытался изменить цену на инт. это работает правильно. Но так как я работаю с ценами, мы все знаем, что тип данных должен быть вдвое больше. < /p>
class Product {
final int mid;
final String icode;
final String name;
final String description;
final double price;
final int gid;
final String gname;
final String pic;
int quantity;
Product({
required this.mid,
required this.icode,
required this.name,
required this.description,
required this.price,
required this.gid,
required this.gname,
required this.pic,
required this.quantity,
});
factory Product.fromJson(Map json) {
return switch (json) {
{
'mid': int mid,
'icode': String icode,
'name': String name,
'description': String description,
'price': double price,
'gid': int gid,
'gname': String gname,
'pic': String pic,
'quantity': int quantity,
} =>
Product(
mid: mid,
icode: icode,
name: name,
description: description,
price: price,
gid: gid,
gname: gname,
pic: pic,
quantity: quantity,
),
_ => throw const FormatException('Failed to load Product.'),
};
}
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... le-flutter
Ошибка Formatexception При изменении данных DataType от int на удвоение (Flutter) ⇐ MySql
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как преобразовать список[int, int, int] в кортеж[int, int, int], а не в кортеж[int, ...]
Anonymous » » в форуме Python - 0 Ответы
- 288 Просмотры
-
Последнее сообщение Anonymous
-