Dawid Szymczak
Dawid Szymczak

Reputation: 41

ListView in SlidingUpPanel scroll

In slidingUpPanel, I have a ListView widget. When I try to scroll, the ListView slidingUpPanel closes. How do I scroll the ListView without closing the slidingUpPanel?

SlidingUpPanel(
  controller: _panelController,
  maxHeight: _panelHeightOpen,
  minHeight: _panelHeightClosed,
  borderRadius: BorderRadius.only(
    topLeft: Radius.circular(50),
    topRight: Radius.circular(50),
  ),
  boxShadow: [
    BoxShadow(
      color: secondaryColor,
      spreadRadius: 1,
      blurRadius: 5,
      offset: Offset(0, -10), // changes position of shadow
    ),
  ],
  panelBuilder: (sc) => _summaryWidget(sc),
),

My _summaryWidget

ListView(
  shrinkWrap: true,
  physics: const NeverScrollableScrollPhysics(),
  children: [
    Photos(),
  ],
)

Upvotes: 3

Views: 1223

Answers (1)

Jim
Jim

Reputation: 7601

You need to put the sc in the ListView controller also:

@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: Text("SlidingUpPanelExample"),
    ),
    body: SlidingUpPanel(
      panelBuilder: (ScrollController sc) => _scrollingList(sc),
      body: Center(
        child: Text("This is the Widget behind the sliding panel"),
      ),
    ),
  );
}

Widget _scrollingList(ScrollController sc){
  return ListView.builder(
    controller: sc,
    itemCount: 50,
    itemBuilder: (BuildContext context, int i){
      return Container(
        padding: const EdgeInsets.all(12.0),
        child: Text("$i"),
      );
    },
  );
}

Upvotes: 1

Related Questions