【发布时间】:2019-04-15 13:13:19
【问题描述】:
小部件不返回视图。 isAttrAssignedToProduct 在此方法中,如果产品存在于表中,则我试图在表中查找分配的属性,然后返回 true,并且图像将根据 true 或 false 在 listview 项目中膨胀。我的数据库在条件下返回真或假,但视图不可见。
Widget isAttrAssigned(int index){
Future result = isAttrAssignedToProduct(index);
return FutureBuilder(
future: result,
builder: (BuildContext context, AsyncSnapshot snapshot) {
result.then((v){
debugPrint('FUTURE VALE ${v}');
attr(v);
});
},);
Widget attr(bool v){
return v==true?Container(
width: 20.0,
height: 20.0,
decoration: BoxDecoration(
color: Colors.yellow),
child: Image.asset('assets/images/right.png'),
):Text('df');
}
我的查询工作正常
Future<bool> isAttrAssignedToProduct(int index) async {
List<Map<String, dynamic>> assd=new List<Map<String, dynamic>>();
try{
assd= await dbHelper.queryReadGroupAssignedAttribute(productList[index][DatabaseHelper.columnpid]);
if(assd.length>0){
// debugPrint('ASSIGNED ATTR PRESENT ${assd.length}');
return true;
}else{
return false;
}
}catch(e){
//debugPrint('ASSIGNED ATTR EXCEPTION ${e}');
return false;
}
}
我的列表磁贴
ListTile(
contentPadding: EdgeInsets.only(left: height*0.03,right: height*0.03 ),
onTap: (){
Navigator.push(context,
MaterialPageRoute(builder: (context) => ProductDetails(pid: productList[index]["pid"],),
settings: RouteSettings(name: '/productdetail')),).then((value){
setState(() {
length=value;
});
debugPrint('CEHCK BACK FROM DAETAIL $length');
});
},
title: Text(
'${title}',
style: TextStyle(fontFamily: 'semibold',color: MyColors.colorPrimaryDark,fontSize: 18.0)),
subtitle: Text(
'Price \$${price}',
style: TextStyle(color: Colors.grey,fontSize: 14.0,fontFamily: 'semibold')),
trailing:isAttrAssigned( index), //here i'm trying to inflate image
),
【问题讨论】: