Placeholder Widget

This Tutorials is posted by niebin312 at 04-03-2019 05:13:30


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 {
_PlaceHolderState createState() => _PlaceHolderState();
}
class _PlaceHolderState extends State<PlaceHolderPage> {
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.

Whole code in GitHub,star to support.


Tags:



0 Comments
Login to comment.
Recent Comments

Be the first to Comment. You can ask a Query or Share your toughts or Just say thanks.



Recent Articles


How to deploy flutter web site on GitHub using peanut

Posted by nikhilchaudhary12155 on 13 Oct 2019 Article


AnimatedPositioned Widget Example in Flutter

Posted by seven.srikanth on 10 Oct 2019 Article


Flutter Open-Source and directory lists

Posted by nishantkotatech on 09 Oct 2019 Article


Flutter Travelling Couple Leading Page - Flutter Web Series 3

Posted by nikhilchaudhary12155 on 05 Oct 2019 Article



© 2018 - Fluttercentral | Email to me - Seven.srikanth@gmail.com