In the world of mobile app development, Flutter has emerged as a powerful toolkit for building natively compiled applications. Among its extensive collection of widgets, the FilledButton stands out as a versatile component for creating interactive elements. In this blog post, we will be exploring FilledButton in Flutter, delving into its features, usage, and customization options to enhance your application’s user interface.
Understanding the Basics of FilledButton in Flutter
The FilledButton widget in Flutter is a material design button that provides a consistent look and feel across different platforms. It is used to trigger actions when pressed and comes with a variety of customization options to fit the design needs of your application. To get started with a basic FilledButton, you can use the following code snippet:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('Exploring FilledButton in Flutter')),
body: Center(
child: FilledButton(
onPressed: () {
print('FilledButton Pressed');
},
child: Text('Press Me'),
),
),
),
);
}
}
In this example, the FilledButton is placed at the center of the screen. It is configured with an onPressed callback that handles the button press event, printing a message to the console. The child property is used to define the button’s label, which in this case is a simple ‘Press Me’ text.
Customizing FilledButton for Enhanced UI
One of the strengths of the FilledButton in Flutter is its ability to be customized to meet specific UI requirements. You can modify properties such as color, shape, and elevation to create a button that aligns with your design vision. Here’s an example of a customized FilledButton:
FilledButton(
onPressed: () {
// Your action here
},
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.blue),
shape: MaterialStateProperty.all(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
side: BorderSide(color: Colors.blueAccent),
),
),
elevation: MaterialStateProperty.all(5),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.thumb_up, color: Colors.white),
SizedBox(width: 8),
Text('Like', style: TextStyle(color: Colors.white)),
],
),
)
In this code, the FilledButton is styled with a blue background color, rounded edges, and a border. It also includes an icon and text, making it more visually appealing. Such customizations can significantly enhance the user’s interaction experience with your application.
In conclusion, exploring FilledButton in Flutter reveals the widget’s flexibility and adaptability, making it a valuable tool for creating interactive and visually pleasing user interfaces. By understanding its core functionalities and customization options, developers can effortlessly integrate FilledButton into their Flutter applications to improve user engagement.