1 / 12

How to Programmatically Scrolling to the End of a ListView in Flutter

In this article, you will learn how you can scroll Programmatically to the end of the ListView. You will learn to use the ListView widget in Flutter. Read the article to know more about the ListView widget.

John115
Download Presentation

How to Programmatically Scrolling to the End of a ListView in Flutter

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. How to Programmatically Scrolling to the End of a ListView in Flutter? A ListView is a scrollable collection of widgets organized linearly in Flutter. Additionally, it is the scrolling widget that is used the most. So, we will examine what the ListView widget in Flutter is in this article. The ListView Widget in Flutter fulfills the necessary tasks by placing the elements inside it in the correct order according to the developer’s requirements. Also check out the the availability of experts to hire Flutter app developers for your next project.

  2. ListViews Widgets come in the following four types: 1. ListView() 2. ListView.builder() 3. ListView.separated() 4. ListView.custom()

  3. You can learn more about the listview widget and its type with more details from here. In our code, we sometimes need to scroll the list view to the Top or bottom (programmatically). So, in this article, We will learn how to scroll down to the bottom of a ListView in Flutter. Also check out the as important topic How to Use Hexadecimal Color Strings in Flutter? To manage our ListView, we will want a ScrollController.

  4. ScrollController _scrollController = ScrollController(); To jump listview from Top to bottom, you can use the below snippet. onPressed: () async { SchedulerBinding.instance?.addPostFrameCallback((_) { _scrollController.animateTo( _scrollController.position.maxScrollExtent, duration: const Duration(milliseconds: 1), curve: Curves.fastOutSlowIn); }); },

  5. To jump listview from Bottom to Top, you can use the below snippet. onPressed: () async { SchedulerBinding.instance?.addPostFrameCallback((_) { _scrollController.animateTo( _scrollController.position.minScrollExtent, duration: const Duration(milliseconds: 1), curve: Curves.fastOutSlowIn); }); },

  6. classMyHomePageextendsStatefulWidget { constMyHomePage({Key? key}) : super(key: key); @override _MyHomePageStatecreateState() => _MyHomePageState(); } class _MyHomePageStateextends State { final ScrollController _scrollController = ScrollController(); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Coflutter'), ), body: Column( children: [ Row( Let’s see a complete example of a scrolling list view of both sides.

  7. mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ ElevatedButton( child: const Text('To Top'), onPressed: () async { SchedulerBinding.instance?.addPostFrameCallback((_) { _scrollController.animateTo( _scrollController.position.minScrollExtent, duration: const Duration(milliseconds: 1), curve: Curves.fastOutSlowIn); }); }, ),

  8. ElevatedButton( child: const Text('To Bottom'), onPressed: () async { SchedulerBinding.instance?.addPostFrameCallback((_) { _scrollController.animateTo( _scrollController.position.maxScrollExtent, duration: const Duration(milliseconds: 1), curve: Curves.fastOutSlowIn); }); }, ), ], ),

  9. Expanded( child: ListView.builder( controller: _scrollController, itemCount: 100, itemBuilder: (BuildContext context, int index) { return Card( child: ListTile( title: Text("Index : $index"), ), ); }, ), ), const Divider(), ], )); } }

  10. Output

  11. Conclusion We have learned an exciting ListView feature in this article that you may have seen on multiple websites and blogs. So now you can add the same functionality to your app. Hope you like this article. Source: https://bosctechlabs.com/programmatically-scrolling-to-end-of-listview/

More Related