Flutter Open
  • Flutter Widgets
  • Structure of code
  • Widgets 01 | Container
  • Widgets 02 | Text
  • Widgets 03 | Image
  • Widgets 04 | Row & Column
  • Widgets 05 | Icon
  • Widgets 06 | RaiseButton
  • Widgets 07 | AppBar
  • Widgets 08 | Scaffold
  • Widgets 09 | FlutterLogo
  • Widgets 10 | Placeholder
  • Widgets 11 | BottomNavigationBar
  • Widgets 12 | TabBarView&TabBar
  • Widgets 13 | DropdownButton
  • Widgets 14 | PopupMenuButton
  • Widgets 15 | Stack
  • Widgets 16 | Stepper
  • Widgets 17 | SimpleDialog
  • Widgets 18 | SnackBar
  • Animation
    • Animation 01 | Base Animation
    • Animation 02 | Flare Animation
  • Canvas
    • Canvas 01 | Custom Painting
    • Canvas 02 | Round Angle Polygon
    • Canvas 03 | Regular Polygon
    • Canvas 04 | Pie Chart With Round Angle
    • Canvas 05 | Gesture With Canvas
Powered by GitBook
On this page
  • Before Start
  • Simple Use
  • Constructor
  • color
  • strokeWidth
  • fallbackWidth & fallbackHeight
  • Conclusion

Was this helpful?

Widgets 10 | Placeholder

In this tutorial, you will learn how to use the Placeholder in the flutter.

Before Start

This widget is simple, but we also need a page to contain our page, so we should create a page first.

import "package:flutter/material.dart";
import 'package:flutter_widgets/const/_const.dart';

class PlaceHolderPage extends StatefulWidget {
  @override
  _PlaceHolderState createState() => _PlaceHolderState();
}

class _PlaceHolderState extends State<PlaceHolderPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(PageName.PLACE_HOLDER),
      ),
      body: SingleChildScrollView(
        child: Column(
          children: <Widget>[
            //our code here.
            SizedBox(height: 600)
          ],
        ),
      ),
    );
  }
}

It will show nothing, but with a title.

Simple Use

So what about the Placeholder, it is a widget to note there have some widget need to implement. So its intention is as its name, hold the place to notice people comply it again in the future. It is so simple. Let's look at the codes.

   Container(
              height: 100,
              child: Placeholder(),
            ),

It will show like this.

Constructor

As I often say, if you want to use a widget, you should look at its constructor first. As follows.

const Placeholder({
    Key key,
    this.color = const Color(0xFF455A64), // Blue Grey 700
    this.strokeWidth = 2.0,
    this.fallbackWidth = 400.0,
    this.fallbackHeight = 400.0,
  })

The parameter is so simple, we have learned the types before. Just look at its parameters one by one.

color

This parameter will set the color of the line in the Placeholder. Let's look at an example as below.

           SizedBox(height: 10),
            Container(
              height: 100,
              child: Placeholder(color: RED),
            ),

strokeWidth

This parameter will control the width of the line in the Placeholder. The Example is below.

            SizedBox(height: 20),
            Container(
              height: 100,
              child: Placeholder(
                color: GREEN,
                strokeWidth: 20,
              ),
            ),

It will show like this.

fallbackWidth & fallbackHeight

These two parameters control the width, height of the Placeholder. If you want to set Placeholder with width =100, height = 100 and just set the fallbackWidth=100,fallbackHeight = 100, it may be not fit your requirement. So you should use with the Container. Let's look at the code as follows.

         SizedBox(height: 20),
            Placeholder(
              color: RED,
              strokeWidth: 4,
              fallbackWidth: 100,
              fallbackHeight: 100,
            ),
            SizedBox(height: 20),
            Container(
              constraints: BoxConstraints.expand(height: 100, width: 100),
              child: Placeholder(
                color: BLUE_DEEP,
                strokeWidth: 4,
                fallbackWidth: 10,
                fallbackHeight: 100,
              ),
            ),

It will show as follows, the second fit your requirements, but the first one doesn't. You should care about that.

Conclusion

We have learned the simple widget, but I also suggest you code them by yourself.Only code enough, you can easy to use them.

Thanks for your reading!

The end.

Facebook Page

Twitter

GitHub

Medium

PreviousWidgets 09 | FlutterLogoNextWidgets 11 | BottomNavigationBar

Last updated 6 years ago

Was this helpful?

Whole code in ,star to support.

GitHub
Flutter Open
NieBin
NieBin
FlutterOpen