I developed a app using flutter 1.0. The app works well on most android and ios phones. But I found there one android phone and one iphone can not open that app, just show the error message "type '_Smi' is not a subtype of type 'double'". Is there someone can tell me what's going on my app.
Error picture when open the flutter app:
It's hard to tell without the relevant piece of code, but in my case, this happened when trying to assign a double value from a Map. The solution was simply to call .toDouble on the value:
// myMap is a Map<String, dynamic>
double myDouble = myMap['mykey'].toDouble();
It used to work without the .toDouble(), but the _Smi error started happening one day.
I think running flutter clean
should solve this problem. I always run that when changing the phone.
_Smi stands for Small machine integers, according to Dart Cookbook
So basically you're getting an int and parsing it incorrectly.
这帮助我从另一个 api 读取 json。
double temp = weatherData['main']['temp'].toDouble();
dynamic
更改,而不是double
when you are using firestore (from google firebase) and you are having fields in a document that are stored as number
(only number available, so number is used for int, double, float, ...) - make sure that you use .toDouble()
before assigning the field value of a document to a double field in your model class in dart.
Example:
final collectionReference =
FirebaseFirestore.instance.collection("Products");
final products = await collectionReference.get();
List productsDocuments = products.docs
.map((doc) => doc.data())
.toList();
items = Items.fromList(productsDocuments);
List<Item> items;
factory Items.fromList(docsFirebase) => Items(
items: List<Item>.from(docsFirebase.map((docFirebase) => Item(
itemName: docFirebase['item_name'],
variantId: docFirebase['variant_id'],
imageUrl: docFirebase['image_url'],
barcode: docFirebase['barcode'],
defaultPrice: docFirebase['default_price'].toDouble(),
lowStock: docFirebase['low_stock'],
optimalStock: docFirebase['optimal_stock']))));
}
I had the same problem and settled on this.
Try to replace this:
double myDouble = myMap['mykey'].toDouble();
To this:
double myDouble = double.parse(myMap['mykey'].toString());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.