Home > Software design >  How can I create a ListView correctly?
How can I create a ListView correctly?

Time:06-13

I'm not able to create a Listview in Flutter because of when I create a Listview of widgets the screen stays empty, it's something like that View Details

I have also tried to use a Stateless widget returning a list view but didn't worked.

Thanks you so much :)

CodePudding user response:

The following is an example of how to use a ListView. Note that I created a MaterialApp since ListView is a Material Widget. You can replace ListViewExample with your own Widget containing a ListView.

void main() {
  runApp(MyApp());
}
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'ListView Example',
      home: ListViewExample(),
    );
  }
}

class ListViewExample extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ListView(
      padding: const EdgeInsets.all(8),
      children: <Widget>[
        Text('Text Widget 1'),
        Text('Text Widget 2'),
        Text('Text Widget 3'),
      ],
    );
  }
}

CodePudding user response:

ListView.builder(

              itemCount: 5
              itemBuilder: (context, index) {
                return Card(
                  child: Padding(
                      padding: const EdgeInsets.all(10),
                      child: Text("Some text $index")
                ),
                );
         }),

More about listview

  • Related