skip to Main Content

i’m using "SubCategoryTiles" widget all over the app. initially i was using same Group Icon but now i want to use different-different category_Icon wherever i use this widget. So i want to know how to do it. See the code and also the image with error i’m getting.

class SubCategoryTiles extends StatelessWidget {
  const SubCategoryTiles({
    required this.titleText,
    required this.onTapHandler,
    required this.category_Icon,
  });

  final Widget titleText;
  final VoidCallback onTapHandler;
  final IconData category_Icon;
  @override
  Widget build(BuildContext context) {
    return ListTile(
      leading: const CircleAvatar(
        backgroundColor: Colors.white,
        child: category_Icon,
        
        // Icon(
        //   Icons.group,
        //   color: Colors.deepOrange,
        // ),
      ),
      title: titleText,
      trailing: const Icon(Icons.arrow_right),
      onTap: onTapHandler,
    );
  }
}

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    The should be like this:

    class SubCategoryTiles extends StatelessWidget {
      const SubCategoryTiles({
        required this.titleText,
        required this.onTapHandler,
        required this.category_Icon,
      });
    
      final Widget titleText;
      final VoidCallback onTapHandler;
      final IconData category_Icon;
      @override
      Widget build(BuildContext context) {
        return ListTile(
          leading: CircleAvatar(
            backgroundColor: Colors.white,
            child: Icon(
              category_Icon,
              color: Colors.deepOrange,
            ),
    
            // Icon(
            //   Icons.group,
            //   color: Colors.deepOrange,
            // ),
          ),
          title: titleText,
          trailing: const Icon(Icons.arrow_right),
          onTap: onTapHandler,
        );
      }
    }
    

    // This is how it should be added when you require it.

    category_Icon: Icons.add_box,


  2. Wrap your category_Icon in a Icon widget

    child: Icon(category_Icon),
    

    IconData is not a widget, but an Icon is.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search