Filter by Widgets


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.


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

Error: The name 'RangeSlider' is defined in the libraries 'package:flutter/src/material/range_slider.dart' and 'package:flutter_range_slider/src/flutter_range_slider.dart'.

Check out this article on Error: The name 'RangeSlider' is defined in the libraries 'package:flutter/src/material/range_slider.dart' and 'package:flutter_range_slider/src/flutter_range_slider.dart'.

Read full post

How to create a persistent bottom sheet in Flutter?

Check out this article on How to create a persistent bottom sheet in Flutter?

Read full post

How to draw a Decorative Horizontal line in Flutter?

Check out this article on How to draw a Decorative Horizontal line in Flutter?

Read full post

How to fetch an Image from Internet in Flutter

Check out this article on How to fetch an Image from Internet in Flutter

Read full post

ListView with Images from the Internet

Check out this article on ListView with Images from the Internet

Read full post

How to show Tooltip in Flutter?

Check out this article on How to show Tooltip in Flutter?

Read full post

How to create BottomNavigationBar in flutter?

Check out this article on How to create BottomNavigationBar in flutter?

Read full post

How to add actions to Appbar?

Check out this article on How to add actions to Appbar?

Read full post

How to open dart devtools in VS code?

Check out this article on How to open dart devtools in VS code?

Read full post

Accessibility features in flutter

Check out this article on Accessibility features in flutter

Read full post

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

Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License , and code samples are licensed under the BSD License.