Fundamentals - Widgets
Method 1: Widget as a StatelessWidget class
class MyMenuBox extends StatelessWidget {
final IconData iconData;
final String label;
final VoidCallback onPressed;
final Color foregroundColor = Colors.white;
final Color backgroundColor = Colors.transparent;
const MyMenuBox({
super.key,
required this.iconData,
required this.label,
required this.onPressed,
});
@override
Widget build(BuildContext context) {
return TextButton.icon(
style: TextButton.styleFrom(
foregroundColor: foregroundColor, // Text color
backgroundColor: backgroundColor, // Background color
// padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 32.0),
//shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
//side: BorderSide(
// color: Colors.white.withOpacity(0.3),
//), // Light border for glossy look
elevation: 1,
),
onPressed: onPressed,
icon: Icon(iconData, size: 35, color: Colors.white),
label: Text(label, style: TextStyle(color: Colors.white)),
);
}
}Method 2: Method 1: Stateful Widget using StatelessWidget Class
Comparison
Case
Method 1
Method 2
Another Example
Summary
Last updated
Was this helpful?

