Skip to content
Readerstacks logo Readerstacks
  • Home
  • Softwares
  • Angular
  • Php
  • Laravel
  • Flutter
Readerstacks logo
Readerstacks
How to create a scroll view in flutter

How to create a scroll view in flutter ?

Aman Jain, January 8, 2022November 5, 2023

Flutter provides multiple way to scroll the view and one of the most efficient way is ListView.builder. Using the ListView class we can configure multiple options. Using these widgets we can create horizontal as well vertical scroll.

  1. ListView
  2. GridView
  3. CustomScrollView
  4. DraggableScrollableSheet
  5. NestedScrollView
  6. PageView
  7. SingleChildScrollView

Here are the few scroll widgets list which are most used in flutter.

In this article we will learn to show the scroll using Listview and a brief example of other Scroll widgets.

  1. ListView – Listview shows items in linear way and it can handle large list data because it renders only the Kist which is on screen.
  2. GridView – GridView is also same as list which but it works as row. We can accommodate multiple widget in single row and can configure how many widget will be in a row.
  3. CustomScrollView – Custom Scroll view is useful when we want some animation in scroll.
  4. DraggableScrollableSheet – Draggable Scroll view is euseful when we want to drag the scroll as well
  5. NestedScrollView – Sometime it requires in our application multiple scroll view inside another scroll view thus NestedScrollView Come into the action.
  6. PageView – Pageview is useful to create slider and tiktok like scroll view.
  7. SingleChildScrollView – SingleChildScrollView when we do not want multiple children it only accepts a single child.

So in this article i will cover ListView scrollview step by step

Step 1 : Create flutter project

Very first step is to create the fluter application using command line tool or in Android studio.

flutter create example_app

This will create a new project with name my_app then go in to the folder.

Step 2 : Create a widgets for long list

Now, Create a widget to scroll the content.

File : lib/LongListContentWidget.dart

import 'package:flutter/material.dart';

class LongListContentWidget extends StatelessWidget {

  final List<String> list = <String>['1', '2', '3','4','5'];
  LongListContentWidget({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(

      title: 'Flutter Demo',
      theme: ThemeData(

        primarySwatch: Colors.blue,
      ),
      home: Scaffold(

          appBar: AppBar(title: const Text("Readerstack")),
          body:   ListView.builder(
                padding: const EdgeInsets.all(8),
                itemCount: list.length,
                itemBuilder:  (BuildContext context, int index) {
                    return Container(
                      height: 200,
                      margin: EdgeInsets.all(5),
                      decoration: BoxDecoration(
                          border: Border.all(color: Colors.red)
                      ),
                      child: Center(child: Text(list[index])),
                    );
                },

              ),
            ),
    );
  }
}

Here as you can see we have used ListView.builder to build the scroll view for best performance of the app.

Step 3 : Add Page to main file

Add you new pages to main.dart and start navigating.

import 'package:flutter/material.dart';
import 'package:example_app/LongListContentWidget.dart';

void main() => runApp(LongListContentWidget());

Step 4: Run the project

Simply run the project using command line or in android studio to check the implementation.

flutter run lib/main.dart

Live Preview

Related

Dart Flutter Flutterscroll

Post navigation

Previous post
Next post

Related Posts

Dart How to add rounded border radius to image in flutter

How to add rounded border radius to image in flutter ?

September 19, 2022March 16, 2024

In this article we will learn to add rounded border radius to image in flutter. In flutter rounded corner border can be added using borderRadius but to add the rounded border to image is not same because by adding the border radius to container it won’t apply to child image….

Read More
Dart flutter refresh page on back

How to refresh a page or widget on navigation pop/back in flutter ?

April 28, 2022November 5, 2023

Sometime in out application we want to refresh a page or widget on navigation pop/back in flutter because we want to update the state of our page so users can see the latest update based on their actions. So In this article I will show you to flutter refresh page…

Read More
Dart Display Asset Image in Flutter

How to show local(asset) image in flutter application?

January 2, 2022January 15, 2022

In this tutorial we will learn to show assets image in flutter. In flutter there is two types of images we can show one is asset image and other one is network image. To use the images in flutter we have Image class which supports both local and remote images….

Read More

Aman Jain
Aman Jain

With years of hands-on experience in the realm of web and mobile development, they have honed their skills in various technologies, including Laravel, PHP CodeIgniter, mobile app development, web app development, Flutter, React, JavaScript, Angular, Devops and so much more. Their proficiency extends to building robust REST APIs, AWS Code scaling, and optimization, ensuring that your applications run seamlessly on the cloud.

Categories

  • Angular
  • CSS
  • Dart
  • Devops
  • Flutter
  • HTML
  • Javascript
  • jQuery
  • Laravel
  • Laravel 10
  • Laravel 11
  • Laravel 9
  • Mysql
  • Php
  • Softwares
  • Ubuntu
  • Uncategorized

Archives

  • June 2025
  • May 2025
  • April 2025
  • October 2024
  • July 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • July 2023
  • March 2023
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Recent Posts

  • Installing a LAMP Stack on Ubuntu: A Comprehensive Guide
  • Understanding High Vulnerabilities: A Deep Dive into Recent Security Concerns
  • Understanding High Vulnerabilities in Software: A Week of Insights
  • Blocking Spam Requests with LaraGuard IP: A Comprehensive Guide
  • Enhancing API Development with Laravel API Kit
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version