Flutter_Widget_Example_Code
Flutter_Widget_Example_Code
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Flutter Widgets UI"),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
showToast = !showToast;
});
},
child: Icon(Icons.add),
),
body: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Center(
child: Text(
message,
style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold),
),
),
SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ElevatedButton(
onPressed: () {
setState(() {
message = "Elevated Button Clicked!";
});
},
child: Text("Elevated"),
),
OutlinedButton(
onPressed: () {
setState(() {
message = "Outlined Button Clicked!";
});
},
child: Text("Outlined"),
),
TextButton(
onPressed: () {
setState(() {
message = "Text Button Clicked!";
});
},
child: Text("Text"),
),
IconButton(
onPressed: () {
setState(() {
message = "Icon Button Clicked!";
});
},
icon: Icon(Icons.thumb_up),
),
],
),
Container(
margin: EdgeInsets.symmetric(vertical: 16),
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.blue[50],
borderRadius: BorderRadius.circular(8),
),
child: TextField(
decoration: InputDecoration(
labelText: "Enter something",
border: OutlineInputBorder(),
),
onChanged: (value) {
setState(() {
message = value;
});
},
),
),
Card(
elevation: 4,
child: ListTile(
leading: Icon(Icons.person),
title: Text("List Tile Title"),
subtitle: Text("With Card and Icon"),
),
),
Image.network(
'https://via.placeholder.com/150',
height: 100,
),
GestureDetector(
onTap: () {
setState(() {
message = "Gesture Detected!";
});
},
child: Container(
margin: EdgeInsets.only(top: 10),
padding: EdgeInsets.all(12),
color: Colors.orange,
child: Text("Tap me"),
),
),
ExpansionTile(
title: Text("Tap to Expand (ExpansionTile)"),
children: [
ListTile(
title: Text("More Widgets Inside"),
subtitle: Text("This simulates Expanded usage."),
)
],
),
Builder(builder: (context) {
return ElevatedButton(
child: Text("Show Dialog"),
onPressed: () {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text("Dialog Box"),
content: Text("This is a dialog message."),
actions: [
TextButton(
child: Text("Close"),
onPressed: () => Navigator.pop(context),
)
],
),
);
},
);
}),
if (showToast)
Container(
margin: EdgeInsets.symmetric(vertical: 10),
padding: EdgeInsets.all(10),
color: Colors.green[200],
child: Text("This is a custom toast!"),
),
ProviderExample(),
],
),
),
),
);
}
}
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.only(top: 20),
padding: EdgeInsets.all(10),
color: Colors.purple[100],
child: Text("Provider Example: $data"),
);
}
}