How To Implement Flutter ListView Horizontal

flutter listview horizontal

Flutter listview horizontal implementation. In this post, I will be discussing and implementing Flutter listview horizontal using an easy and proper Flutter example code. Step by step explanation of what Flutter listview is, its usage in Flutter app and how to implement Flutter listview horizontal. So let’s not waste anymore of your time and start implementing Flutter listview horizontal.

What is Flutter Listview Horizontal?

Listview in Flutter is as the name suggests, it is a list of items, listview is used when you want to show a list of items like a rounded edged container or any other widget. By default it is vertical means the items are shown from top to bottom.

In this post, we will implement how to make Flutter listview horizontal means from left to right and vice versa. Let’s now implement Flutter listview horizontal using a proper Flutter example code.

Default Flutter Listview

Let’s see the default Flutter listview looks like. We have used a simple listview and have given it some Flutter containers widgets having different colors and shapes using the children constructor of the Flutter listview which takes a list of widgets. See the below code:

ListView(
        padding: EdgeInsets.only(top: 30),
        children: [
          Container(
            height: 100,
            width: 100,
            decoration:
                BoxDecoration(shape: BoxShape.circle, color: Colors.green),
          ),
          Column(
            children: [
              Container(
                margin: EdgeInsets.only(top: 30),
                height: 100,
                width: 100,
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(20),
                    color: Colors.blue),
              ),
            ],
          ),
          Column(
            children: [
              Container(
                margin: EdgeInsets.only(top: 30),
                height: 100,
                width: 100,
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(50),
                    color: Colors.purple),
              ),
            ],
          ),
          Column(
            children: [
              Container(
                margin: EdgeInsets.only(top: 30),
                height: 100,
                width: 100,
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(10),
                    color: Colors.black),
              ),
            ],
          )
        ],
      )
flutter listview default scroll direction
You can see in the above image that we have a Flutter listview and its direction is vertical, from top to bottom. Let’s now change it to Flutter listview horizontal.

Implementing Flutter Listview Horizontal

Let’s see how to implement Flutter listview horizontal. For that we have to use the scroll direction constructor of the Flutter listview. By default it is axis vertical, we have to change it to axis horizontal. See the below code:

scrollDirection: Axis.horizontal
flutter listview horizontal
You can see in the above image that the direction is now horizontal, left to right and vice versa.
So in this way you can change the direction and implement Flutter listview horizontal. If you still have any queries then do let me know in the comment section. I would love to answer them
Now as a treat, I have designed a beautiful custom Flutter listview design for you in which Flutter listview horizontal is also implemented. The complete source code is given in the next section.

Beautiful Flutter Listview Design Source Code

flutter listview horizontal

import 'package:flutter/material.dart';
void main() {
  runApp(MyApp());
}
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Homepage(),
    );
  }
}
class Homepage extends StatefulWidget {
  @override
  State<Homepage> createState() => _HomepageState();
}
class _HomepageState extends State<Homepage> {
  @override
  Widget build(BuildContext context) {
    return SafeArea(
        child: Scaffold(
      body: ListView(
        padding: EdgeInsets.only(top: 30),
        scrollDirection: Axis.horizontal,
        children: [
          Column(
            children: [
              Container(
                height: 100,
                width: 100,
                margin: EdgeInsets.all(20),
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(50),
                    color: Colors.green),
                child: Container(
                  height: 100,
                  width: 100,
                  margin: EdgeInsets.all(10),
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(50),
                      color: Colors.lightBlue),
                  child: Container(
                    height: 100,
                    width: 100,
                    margin: EdgeInsets.all(10),
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(50),
                        color: Colors.white),
                  ),
                ),
              ),
            ],
          ),
          Column(
            children: [
              Container(
                height: 100,
                width: 100,
                margin: EdgeInsets.all(20),
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(20),
                    color: Colors.green),
                child: Container(
                  height: 100,
                  width: 100,
                  margin: EdgeInsets.all(10),
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(20),
                      color: Colors.white),
                  child: Container(
                    height: 100,
                    width: 100,
                    margin: EdgeInsets.all(10),
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(20),
                        color: Colors.green),
                  ),
                ),
              ),
            ],
          ),
          Column(
            children: [
              Container(
                height: 100,
                width: 100,
                margin: EdgeInsets.all(20),
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(50),
                    color: Colors.blue),
                child: Container(
                  height: 100,
                  width: 100,
                  margin: EdgeInsets.all(10),
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(50),
                      color: Colors.purple),
                  child: Container(
                    height: 100,
                    width: 100,
                    margin: EdgeInsets.all(10),
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(50),
                        color: Colors.blue),
                  ),
                ),
              ),
            ],
          ),
          Column(
            children: [
              Container(
                height: 100,
                width: 100,
                margin: EdgeInsets.all(20),
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(50),
                    color: Colors.green),
                child: Container(
                  height: 100,
                  width: 100,
                  margin: EdgeInsets.all(10),
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(50),
                      color: Colors.lightBlue),
                  child: Container(
                    height: 100,
                    width: 100,
                    margin: EdgeInsets.all(10),
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(50),
                        color: Colors.white),
                  ),
                ),
              ),
            ],
          ),
        ],
      ),
    ));
  }
}

Conclusion

In conclusion, now you have an in depth practical understand of how to implement Flutter listview horizontal in Flutter app. I would love to hear your amazing thought regarding this post. I would also highly encourage you to visit my other posts on Flutter app development, Flutter animations, Flutter beautiful templates with source code, Flutter widgets and many more, links to some of these posts are listed below. Thanks for reading.

Leave a Comment

Your email address will not be published.