The Placeholder widget in Flutter is a simple widget used to occupy space in a layout without displaying any content. It's often used as a temporary placeholder while designing a UI layout, allowing developers to visualize the arrangement of widgets without providing actual content. The Placeholder widget is typically replaced with other widgets during the development process.
Attributes:
color (Color):
- The color of the placeholder widget. It's optional and defaults to a gray color.
fallbackHeight (double):
- The fallback height of the placeholder widget. It's optional and defaults to 400.0.
fallbackWidth (double):
- The fallback width of the placeholder widget. It's optional and defaults to 400.0.
Example:
import 'package:flutter/material.dart';
class PlaceholderExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Placeholder Widget Example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Placeholder(
color: Colors.blueGrey,
fallbackHeight: 200,
fallbackWidth: 200,
),
SizedBox(height: 20),
Text(
'This is a Placeholder Widget',
style: TextStyle(fontSize: 18),
),
],
),
),
);
}
}
void main() {
runApp(MaterialApp(
home: PlaceholderExample(),
));
}
In this example:
A Placeholder widget is used inside a Column to demonstrate its usage.
The Placeholder widget has a specified color, fallbackHeight, and fallbackWidth, which will be used if the widget's size is not determined by the layout constraints.
Below the Placeholder widget, there is a Text widget providing context about the Placeholder. This text will be displayed below the placeholder in the UI.