0

So I have created a custom list view (list_item.dart) which is used to save data that comes from an api inside a card and display it to the user.Ehen I try to populate my listview with data I get the error "A RenderFlex overflowed by 1307 pixels on the right. inside a card widget".I have tried putting the card widget iside a flexible widget but it didnt work. please help.

error image

class CustomListItem extends StatelessWidget {
final String subtitle;
final String secondaryText;
final String body;
final int index;
final Widget image;
final void Function() onTap;

const CustomListItem({
required this.subtitle,
required this.secondaryText,
required this.body,
required this.index, required this.onTap,
required this.image,
});

@override
Widget build(BuildContext context) {
  return Padding(
    padding: const EdgeInsets.symmetric(vertical: 5.0),
      child: Card(
        child: Padding(
          padding: const EdgeInsets.all(20.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Row(
                children: <Widget>[
                  image,
                  Column(
                    children: <Widget>[
                      RichText(
                        text: TextSpan(
                          text: subtitle,
                          recognizer: TapGestureRecognizer()..onTap = onTap,
                          style: TextStyle(
                          fontWeight: FontWeight.bold,
                          ),
                        ),
                      ),
                      Text(secondaryText)
                    ],
                  ),
                ],
              ),
            Container(
              height: 1.0,
              width: MediaQuery.of(context).size.width,
              color: Colors.black,
            ),
            Row(
              children: <Widget>[Text(body)],
            ),
          ],
        ),
      ),
    ),
);
}
}
Kavishka Rajapakshe
  • 537
  • 1
  • 8
  • 23
  • Add your image and text widget inside Expanded or Flex Widget refer my answer [here](https://stackoverflow.com/a/68444861/13997210) – Ravindra S. Patil Aug 09 '21 at 09:12
  • Try add expanded widget in each widget like image,text , also Try using layout inspector in android studio,it will help to identify which widget shows error and how to fix it check video and documentation it helps lot https://flutter.dev/docs/development/tools/devtools/inspector@Kavishka Rajapakshe – Abhijith Aug 09 '21 at 09:20

1 Answers1

0

try to use Expanded to wrap your text widget, like:

        Row(
          children: <Widget>[Expanded(child: Text(body),),],
        ),
Jim
  • 6,928
  • 1
  • 7
  • 18