Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flutter add widgets on top and bottom to a listview

Tags:

flutter

Trying to add some widgets to before of a listview.... I searched and found to use expanded like:

  return Scaffold(
    appBar: AppBar(
      title: Text('Test Listview'),
    ),
    body: Container(
      padding: const EdgeInsets.all(10.0),
      child: Column(
        children: <Widget>[
          Text('header'),
          Expanded(
            child: ListView.builder(
              itemCount: providerApp.domains.length,
              itemBuilder: (BuildContext context, int index) {
                return Container( ......

But the issue here is that the Text('header') will be fixed, looking for some way where the the widget scrolls together with listview...

Thanks !!!

like image 936
aknd Avatar asked Oct 08 '19 00:10

aknd


People also ask

How do you change the widget position in flutter?

Here's how you do it: Step 1: Wrap the Stack's child widget inside the Position widget. Step 2: Inside the Position widget, add the top , right , bottom , left property and give it a value. For example, setting top:15 and right:0 will position a widget on the top right of your screen with 15 px space from the top.


1 Answers

You can achieve this by using listview inside list view, below is sample code please check

enter image description here

 body: ListView(
    children: <Widget>[
      Container(
        height: 40,
        color: Colors.deepOrange,
        child: Center(
          child: Text(
            'Header',
            style: TextStyle(color: Colors.white, fontSize: 16),
          ),
        ),
      ),
      ListView.builder(
        physics: ScrollPhysics(),
        shrinkWrap: true,
        itemCount: 50,
        itemBuilder: (BuildContext context, int index) {
          return Container(
            color: Colors.lime,
            height: 60,
            child: Center(
              child: Text(
                'Child $index',
                style: TextStyle(color: Colors.black, fontSize: 16),
              ),
            ),
          );
        },
      ),
      Container(
        height: 40,
        color: Colors.deepOrange,
        child: Center(
          child: Text(
            'Footer',
            style: TextStyle(color: Colors.white, fontSize: 16),
          ),
        ),
      ),
    ],
  ),
like image 119
Kailash Chouhan Avatar answered Oct 08 '22 08:10

Kailash Chouhan