Shakib Uz-Zaman
Shakib Uz-Zaman

Reputation: 621

Listview not showing inside a Row in Flutter

I am trying to show a listview after some texts in a column. The text shows properly inside the first Row until I add a listview inside the next row. Everything disappears after adding the ListView.

Here is the Code:

class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
  appBar: AppBar(

    title: Text(widget.title),
  ),
  body: Padding(
    padding: const EdgeInsets.all(16.0),
    child: Column(
      children: <Widget>[
        Row(
          children: <Widget>[
            Text(
              "Prayer Time",
              style: TextStyle(fontSize: 20, fontWeight: 
 FontWeight.normal),
            ),
          ],
        ),
        Row(
          children: <Widget>[myList()],
        ),
      ],
    ),
  ),
  floatingActionButton: FloatingActionButton(
    tooltip: 'Add Alarm',
    child: Icon(Icons.add),
    backgroundColor: const Color(0xff0A74C5),
  ), 
  );
}

Expanded myList() {
return Expanded(
    child: ListView.builder(
      itemBuilder: (context, position) {
        return Card(
          child: Text(androidVersionNames[position]),
        );
      },
      itemCount: androidVersionNames.length,
    )
  );
 }
}

Upvotes: 2

Views: 3745

Answers (2)

Pedro Massango
Pedro Massango

Reputation: 5015

Your ListView should have a fixed Size. Try to wrap the ListView inside a Container.

I run your code and fixed it. Replace your myList() with this code bellow:

Expanded myList() {
    return Expanded(
        child: Container(
          width: double.infinity,
          height: 200,
          child: ListView.builder(
            itemBuilder: (context, position) {
              return Card(
                child: Text(androidVersionNames[position]),
              );
            },
            itemCount: androidVersionNames.length,
          ),
        )
    );
  }

Upvotes: 0

BIS Tech
BIS Tech

Reputation: 19444

change like this:

  Expanded(
              child: Row(
                children: <Widget>[myList()],
              ),
            ),

Upvotes: 4

Related Questions