Flutter Create Call Function From Same Class on Button Click Example

There are multiple type of functions available in Flutter like other languages. Like Function Without Argument, Function with single argument and Function with multiple argument. The arguments are the values which we have send along with function calling time inside function scope. The argument values automatically send along the function and using them we would perform certain task. There are main two types of functions in function category like Void and non-Void functions. We are only creating Void non value returnable functions in our tutorial and all the methods are created inside same class. When we call function from same class then there is no need to create object for calling functions. We can call the functions directly from their names. So in this tutorial we would Flutter Create Call Function From Same Class on Button Click Android iOS Example Tutorial.

Contents in this project Flutter Create Call Function From Same Class on Button Click Android iOS Example Tutorial:

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

2. Create void main runApp() method and here we would call our main MyApp parent class.

3. Create our main class named as MyApp extends StatelessWidget.

4. Now we would create a single void function named as sampleFunction_1(). Inside the function i am only printing a message on Terminal screen using Print method. One more thing i am using void keyword with function but in flutter latest version there is no need to use the void keyword you can directly declare the function with function name.

5. Creating another function named as sampleFunction_2() with String argument. We would send a Sting value with function on function calling time from Button.

6. Creating another function named as sampleFunction_3() with Float double value.

7. Creating Widget build area in MyApp class. Now first we would create a Center widget in Body section of Scaffold widget and Create a Column widget.

8. Creating 3 Raised button widgets in Container widgets in Column widgets. We would call each function on Button onPressed event.

9. Complete source code for main.dart file:

Screenshots:

Flutter Create Call Function From Same Class on Button Click Example

Leave a Reply

Your email address will not be published.