Flutter Dart Find Calculate Square Root of Given Number Example

In flutter there is a inbuilt function named as double sqrt(num x) which is used to find square root of any double number. The number returns value in Double Float format so we have to also use double value here. The double sqrt(num x) method will automatically calculate square. This method is present in dart:math package. So in this tutorial we would Flutter Dart Find Calculate Square Root of Given Number in Android iOS Example Tutorial.

Contents in this project Flutter Dart Find Calculate Square Root of Given Number Example Tutorial:

1. Import material.dart and dart:math package in your app’s main.dart file.

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

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

4. Creating a double variable named as A with some value and another variable named as B. We would not initialize any value to B variable.

5. Creating a function named as findSquareRoot(). Inside this function we would call the dart’s inbuilt sqrt() function and pass the A double variable inside it. After finding Square Root we would save the result into B variable and then print the B variable on Terminal screen using print method.

6. Creating Widget Build area -> Scaffold widget -> Center widget -> Column widget -> Raised Button widget. We would call the findSquareRoot() function on button click event.

7. Complete source code for main.dart file:

Screenshots:

Flutter Dart Find Calculate Square Root of Given Number Example

Leave a Reply

Your email address will not be published. Required fields are marked *