ElevatedButton is a material design button that is typically used for important or primary actions in an application. It has a higher elevation compared to a FlatButton and is designed to stand out on the screen
There Are Some Common Attributes for ElevatedButton
primary | Background color of the button |
onPrimary | Text color when button is not pressed. |
elevation | Elevation (shadow) of the button |
side: BorderSide(color:) | Side Border |
fixedSize | Button Height Weight size |
Here's a simple example of using a ElevatedButton in Flutter:
File open lib->main.dart file −
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() {
runApp(
MyApp()
);
}
class MyApp extends StatefulWidget{
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
backgroundColor: Colors.blue,
title: Text('Button Example',
style:TextStyle(fontSize: 20,color: Colors.white)),
),
body: Center(
child:
Column(
children: [
SizedBox(height: 20,),
FloatingActionButton(
onPressed: () {
// Handle FloatingActionButton press
print('FloatingActionButton pressed!');
},
child: Icon(Icons.add), // Icon displayed on the button
backgroundColor: Colors.blue, // Background color of the button
),
SizedBox(height: 20,),
SizedBox(height: 20,),
Center(
child: ElevatedButton(
onPressed: () { },
child: Text("Click Me"),
style: ElevatedButton.styleFrom(
padding: EdgeInsets.all(10.0),
fixedSize: Size(300, 50),
textStyle: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
elevation: 15,
shadowColor: Colors.red,
side: BorderSide(color: Colors.lightBlueAccent, width: 1),
),
)
),
],
),
)
));
}
}
Open
Device Manager, run the emulator, and then run the application. Next,
check the working output and check the output you declared in your
code.
Output: