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 one side border to container widget flutter

How to add one side border to container widget flutter?

September 17, 2022March 16, 2024

In this tutorial we will learn to add add one side border to container widget flutter. Border is used to create border around the widget or container and using the border we can style it in different way like adding the width of border, color of border and one side…

Read More
Dart Create routing in flutter

How to create routing in flutter and pass parameters to routes ?

January 24, 2022October 4, 2022

Flutter has multiple ways to create navigation and routing. In our last article i demonstrate How to navigate between one page to another in flutter and in this article i will show you to create a router where we can define all routes using flutter named routes. Fluter named routes…

Read More
Dart How to Subscribe for Flutter NavigatorRouter Events

How to Subscribe for Flutter Navigator/Router Events ?

April 29, 2022September 11, 2022

Navigator is used to navigate between the pages and sometimes we want to subscribe for flutter Navigator/Router Events to update the widget state or to perform the specific task during the push and pop of page. Flutter provider RouteObserver mixin to subscribe the events of navigator by which we can…

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

  • 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

  • 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
  • Exploring the Future of Web Development: Insights from Milana Cap
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version