Flutter Widget Demo with Code
Explanation
Text Widget
Text("This is a simple text widget", style: TextStyle(fontSize: 18))
- Displays a line of styled text.
Icon Widget
Icon(Icons.star, size: 40, color: Colors.amber)
- Displays a Material icon with color and size.
ElevatedButton Widget
ElevatedButton(
onPressed: () {},
child: Text("Click Me"),
)
- A button with elevation and click behavior.
TextField Widget
TextField(
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: "Enter some text",
),
)
- Input field for user text.
Checkbox Widget
Checkbox(
value: isChecked,
onChanged: (val) {
setState(() {
isChecked = val!;
});
},
)
- Toggles between true/false.
Switch Widget
Switch(
value: switchValue,
onChanged: (val) {
setState(() {
switchValue = val;
});
},
)
- A toggle switch for on/off.
Slider Widget
Slider(
value: sliderValue,
min: 0,
max: 100,
divisions: 10,
label: sliderValue.toInt().toString(),
onChanged: (value) {
setState(() {
sliderValue = value;
});
},
)
- A range slider with current value.
Row Widget
Row(
children: [
Container(color: Colors.red, width: 50, height: 50),
Container(color: Colors.green, width: 50, height: 50),
],
)
- Lays out widgets horizontally.
Column Widget
Column(
children: [
Text("Item 1"),
Text("Item 2"),
],
)
- Lays out widgets vertically.
ListView Widget
ListView.builder(
itemCount: 5,
itemBuilder: (context, index) => ListTile(
title: Text("List item \${index + 1}"),
),
)
- Scrollable list of items.
GestureDetector Widget
GestureDetector(
onTap: () {
print("Tapped!");
},
child: Container(
padding: EdgeInsets.all(16),
color: Colors.grey,
child: Text("Tap Me"),
),
)
- Detects tap and other gestures.
SnackBar Widget
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Hello")),
);
- Temporary message at the bottom.
AlertDialog Widget
showDialog(
context: context,
builder: (_) => AlertDialog(
title: Text("Notice"),
content: Text("This is a dialog"),
),
);
- Dialog box to show alerts or options.