Example of Add onLongPress on ElevatedButton in Flutter

Hello friends, Our today’s tutorial is very simple and required by many beginner developers. As we all know soon Raised Button widget will be deprecated, In that case we have to start working with ElevatedButton widget in flutter. Now when we start working with ElevatedButton then some times we have to implement onLongPress event on ElevatedButton. The onLongPress is same as normal onPressed event but there are a major difference between them which we can understand from the name. The onLongPress event will fire a function or event when user touch and hold the button for more than 1 second. So in this tutorial we would learn about Example of Add onLongPress on ElevatedButton in Flutter.

Contents in this project Example of Add onLongPress on ElevatedButton in Flutter :-

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

2. Creating void main runApp() event, Here we would call our main MyApp class.

3. Creating our main MyApp extends StatelessWidget class.

4. Creating a function named as _callingLongPress(). In this function we would simply print a message on the Console window.

5. Creating Widget build area -> Here we would make the ElevatedButton widget with onLongPress event. Now the main catch we have seen in this widget that you must have to implement onPressed event. Event if you don’t need it but you have to otherwise it will throw us a error. So we have to implement onPressed event and pass empty argument inside it to work it properly.

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

Screenshots :-

Example of Add onLongPress on ElevatedButton in Flutter

Leave a Reply

Your email address will not be published.