Widget not returning view. isAttrAssignedToProduct in this method I'm trying to find the assigned attribute in the table if the product exists in the table then return true and the image will be inflated in listview item on the base of true or false. My database returning true or false on condition but the view is not visible.

 Widget isAttrAssigned(int index){
        isAttrAssignedToProduct(index).then((onValue){
          if(onValue){
            debugPrint('Assigned value ${onValue}');
            return Container(
              width: 20.0,
              height: 20.0,
              decoration: BoxDecoration(
              color: Colors.yellow),
              child: Image.asset('assets/images/right.png'),
            );
          }else{
            debugPrint('Assigned  value ${onValue}');
            return Container(
              width: 20.0,
              height: 20.0,
              decoration: BoxDecoration(
                  color: Colors.yellow),
              child: Image.asset('assets/images/wrong.png'),
            );
          }
        }  ); }

My Query working fine

 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;
    }
  }

My List Tile

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
        ),

Related posts

Recent Viewed