【发布时间】:2019-12-03 12:14:37
【问题描述】:
所以,在我使用 Image.asset(widget.product_detail_picture) 调用图像之前,我的应用程序运行良好。 这是错误:
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY
╞═══════════════════════════════════════════════════════════
The following assertion was thrown building ProductDetails(dirty, state:
ProductDetailsState#db131):
type 'int' is not a subtype of type 'String'
Either the assertion indicates an error in the framework itself, or we should
provide substantially more information in this error message to help you
determine and fix the underlying cause.
这是我的产品详情页面代码:
import 'package:flutter/material.dart';
final product_detail_name;
final product_detail_picture;
final product_detail_old_price;
final product_detail_new_price;
ProductDetails({
this.product_detail_name,
this.product_detail_picture,
this.product_detail_old_price,
this.product_detail_new_price,
});
@override
_ProductDetailsState createState() => _ProductDetailsState();
}
class _ProductDetailsState extends State<ProductDetails> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
backgroundColor: Colors.red,
title: Text('HunkyBees'),
actions: <Widget>[
new IconButton(
icon: Icon(
Icons.search,
color: Colors.white,
),
onPressed: () {}),
new IconButton(
icon: Icon(
Icons.shopping_cart,
color: Colors.white,
),
onPressed: () {})
],
),
body: new ListView(
children: <Widget>[
new Container(
height: 300.0,
child: GridTile(
child: Container(
color: Colors.white,
child: Image.asset(widget.product_detail_picture),
)),
),
],
),
);
}
}
这是我的产品页面,从中调用产品图片
import '../pages/product_details.dart';
class Products extends StatefulWidget {
@override
_ProductsState createState() => _ProductsState();
}
class _ProductsState extends State<Products> {
var product_list = [
{
"name": "Men Real Dress",
"picture": "images/products/blazer1.jpeg",
"old_price": 120,
"price": 85,
},
{
"name": "Red Dress",
"picture": "images/products/dress1.jpeg",
"old_price": 190,
"price": 80,
},
{
"name": "Women Dress",
"picture": "images/products/dress2.jpeg",
"old_price": 100,
"price": 59,
},
{
"name": "Women Hills",
"picture": "images/products/hills1.jpeg",
"old_price": 140,
"price": 90,
},
];
@override
Widget build(BuildContext context) {
return GridView.builder(
itemCount: product_list.length,
gridDelegate:
new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
itemBuilder: (BuildContext context, int index) {
return Single_prod(
prod_name: product_list[index]['name'],
prod_picture: product_list[index]['picture'],
prod_old_price: product_list[index]['old_price'],
prod_price: product_list[index]['price'],
);
});
}
}
class Single_prod extends StatelessWidget {
final prod_name;
final prod_picture;
final prod_old_price;
final prod_price;
Single_prod(
{this.prod_name,
this.prod_picture,
this.prod_old_price,
this.prod_price});
@override
Widget build(BuildContext context) {
return Card(
child: Hero(
tag: prod_name,
child: Material(
child: InkWell(
onTap: () => Navigator.of(context).push(
new MaterialPageRoute(
//Passing Product Details Inside Navigation Co
builder: (context) => new ProductDetails(
product_detail_name: prod_name,
product_detail_picture: prod_old_price,
product_detail_new_price: prod_price,
product_detail_old_price: prod_old_price,
),
),
),
child: GridTile(
footer: Container(
color: Colors.white70,
child: ListTile(
leading: Text(
prod_name,
style: TextStyle(fontWeight: FontWeight.bold),
),
title: Text(
"\$$prod_price",
style: TextStyle(
color: Colors.red, fontWeight: FontWeight.w800),
),
subtitle: Text(
"\$$prod_old_price",
style: TextStyle(
color: Colors.black54,
fontWeight: FontWeight.w800,
decoration: TextDecoration.lineThrough),
),
),
),
child: Image.asset(
prod_picture,
fit: BoxFit.cover,
)),
),
),
),
);
}
}
没有添加就可以正常工作:
child: Image.asset(widget.product_detail_picture), 到 product_details 页面
无需我调用图像,它就可以正常工作。
【问题讨论】:
-
能否请您在调用 ProductDetails 的位置添加代码
-
我已将产品页面代码添加到原帖
标签: android flutter flutter-layout flutter-dependencies