Skip to main content

Flutter Development (Day -07):



  • All source code : Click Here
  • Today we are going to talk more about lists and its types.
  • Lists are very important in any field like if we want to return large amount of data we can't assing every single value to a String variable and display it is a tedious task to do , but Flutter makes it easy for us just wrap the list in a ListView widget then it is ready.

    Types of Lists.

    1. Horizontal List
    2. Vertical List
    3. Grid List

Horizontal List:

  • Same as returning the ListView in previous tutorials just add a property scrollDirection:Axis.horizontal.

Vertical List:

  • We already discussed in our previous tutorials.

Grid List:



  • Sometimes you might want to display your items as a grid rather than a normal list of items that come one after the next. For this task, use the GridView widget.


Ex.

import 'Package:flutter/material.dart';
import 'package:random_color/random_color.dart';

class WorkingWithLists extends StatefulWidget {
  @override
  _WorkingWithListsState createState() => _WorkingWithListsState();
}

class _WorkingWithListsState extends State<WorkingWithLists> {
  RandomColor randomColor = RandomColor();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Working with Lists"),
        centerTitle: true,
        backgroundColor: RandomColor().randomColor(),
      ),
      body: GridView(
        gridDelegate:
            SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
        scrollDirection: Axis.vertical,
        children: <Widget>[
          _showGrid(),
          _showGrid(),
          _showGrid(),
          _showGrid(),
          _showGrid(),
          _showGrid(),
          _showGrid(),
          _showGrid(),
          _showGrid(),
          _showGrid(),
          _showGrid(),
          _showGrid(),
          _showGrid(),
          _showGrid(),
          _showGrid(),
          _showGrid(),
          _showGrid(),
          _showGrid(),
          _showGrid(),
          _showGrid(),
          _showGrid(),
          _showGrid(),
          _showGrid(),
          _showGrid(),
        ],
      ),
    );
  }

  Widget _showGrid() {
    return Container(
      margin: const EdgeInsets.all(2.0),
      color: RandomColor().randomColor(),
      child: Center(
        child: Text(
          "Grid",
          style: TextStyle(
              color: Colors.white, fontSize: 30.0, fontWeight: FontWeight.bold),
        ),
      ),
    );
  }
}

  • Here I used some extra stuff like returning a function instead typing again and again same code.
  • Used random_color: ^1.0.3 package to generate random colors.
  • Grid view is also a type of Scrollable widget.It requires a crossAxisCount which is nothing but it returns two 2 columns change the number and scrollDirection and see the magic.
  • For more info on any other widgets visit here.



Follow me on:
 Twitter  Github   LinkedIn

Comments

Popular posts from this blog

Flutter Development (Day-00): This is the First Post from this Blog.This blog will tell you about Flutter.If you don't know about it then the upcoming posts will explain you everything.This is 30 day tutorial which explains about Flutter for absolute beginners. prerequsites:  If you are enthusiastic and Curious. All source code :  Click Here . If you are following this tutorial / blog please leave your opinion 👀 / say Hii ✋/ Your e-mail in the comment section that I can improve myself and it will gives boost for me to do more tutorials. If you have any doubts feel free to ask me in the comment section or email me ramubugudi4@gmail.com I can definetly give reply. Follow me on:   Twitter   Github     LinkedIn
Flutter Development (Day-16): All source code :  Click Here . Sorry for the last two days I haven't posted anything because I am ready to leave my hometown to attend my college.Is there anyone from AndhraPradesh or Tamilnadu .If yes please provide your city name in the comment section. In this post we are going to proceed the next level of our todo app.We are going add animations to our app,Code clean Up and some UI changes. We add the animation to our FloationgActionButton.You may ask why you haven't add animations to others as well? I tried it but it is looking weird. Adding animations to  FloationgActionButton is very much similar to our previous basic animation tutorial. From the next we are going to deal with some of the important widgets which we will be using in further tutorials. If you are following this tutorial / blog please leave your opinion 👀 / say Hii ✋/ Your e-mail in the comment section that I can improve myself and it will gives boost for me t...
Flutter Development (Day-02): This is the 3rd post from this blog.Today we are going to see some of the basic widgets in flutter and how ,where to use those widgets. In Flutter everything is a widget like view in Android.Text,Padding,Margin are also widgets in Flutter. All source code :  Click Here Scaffold: Implements the basic Material Design visual layout structure. This class provides APIs for showing drawers, snack bars, and bottom sheets. Appbar: A Material Design app bar. An app bar consists of a toolbar and potentially other widgets, such as a TabBar and a FlexibleSpaceBar. Container: A convenience widget that combines common positioning of the widgets. Row: Layout a list of child widgets in the horizontal direction. Column: Layout a list of child widgets in the vertical direction. Text: A run of text with a single style. Image: A widget that displays an image. Icon: A Material Design icon. Raised...