Flutter Set onPressed onClick on Elevated Button Example

Hello friends, As you all know I’m trying to cover Elevated Button widget in flutter with small small examples. In today’s example tutorial we would learn about How in Flutter Set onPressed onClick on Elevated Button. Elevated button is a good alternative option after deprecation of Raised button in flutter. So let’s get started 🙂 .

Contents in this project Flutter Set onPressed onClick on Elevated Button in Android iOS Example :-

1. Open your flutter project’s main.dart file and import material.dart file.

2. Creating void main runApp() method and here we would call our main MyApp widget.

3. Creating our main class MyApp extends StatelessWidget. This is our main Parent class.

4. Creating a sample function named as printMSG(). We would call this message on button click onPress event. In this function we would simply print a console message on terminal window.

5. Creating Widget Build Area -> Material App -> Scaffold Widget -> Center Widget -> Container Widget.

6. Now we would create the ElevatedButton widget as child of Container widget. Here you can see we are using onPressed method to set click event on elevated button.

7. Complete source code for main.dart file :-

Screenshots:-

Flutter Set onPressed onClick on Elevated Button Example

Leave a Reply

Your email address will not be published.