简体   繁体   中英

How to continious scroll bottomModelSheet after child ListView completes the scroll in flutter?

I have the showModalBottomSheet widget which I am calling when the user clicks on a button and it has listView as a child widget.

with this, I am able to scroll through the bottom model sheet,

But how to continuously scroll the bottom model sheet down after the listview has completed scrolling down?

Currently, the bottom model sheet does not go down just the ListView indicates the completion of scroll.

在此处输入图片说明

instead of scroll complete feedback, I want to scroll down the BottomModelSheet when ListView done scrolling. Is there any way to achieve this with `showModalBottomSheet'?

  class _ExampleState extends State<Example> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          children: <Widget>[
            RaisedButton(
              child: Text('Press Me'),
              onPressed: () async => await showModalBottomSheet(
                  // isScrollControlled: true,
                  context: context,
                  builder: (ctx) => ListViewWidget()),
            ),
          ],
        ),
      ),
    );
  }
}

class ListViewWidget extends StatefulWidget {
  @override
  _ListViewWidgetState createState() => _ListViewWidgetState();
}

class _ListViewWidgetState extends State<ListViewWidget> {
  ScrollController _scrollController;
  ScrollPhysics _scrollPhysics;

  void _scrollListener() async {
    if (_scrollController.position.pixels ==
        _scrollController.position.minScrollExtent) {
      setState(() {
        _scrollPhysics = NeverScrollableScrollPhysics();
      });
    }
  }

  @override
  void initState() {
    _scrollController = ScrollController()..addListener(_scrollListener);
    _scrollPhysics = AlwaysScrollableScrollPhysics();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      shrinkWrap: true,
      itemCount: kStates.length,
      controller: _scrollController,
      physics: _scrollPhysics,
      itemBuilder: (_, index) => GestureDetector(
        child: Text(
          kStates[index],
          style: TextStyle(
            color: Colors.black,
          ),
        ),
      ),
    );
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM