Find Calculate Square Root Of Given Number In Flutter

admin_img Posted By Bajarangi soft , Posted On 12-10-2020

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.

Find Calculate Square Root Of Given Number In Flutter

Calculate Square Root Of Given Number 
Complete Code For  Calculate Square Root Of Given Number  In Flutter
main.dart

import 'package:flutter/material.dart';
import 'dart:math';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  double SQUARE_1 = 625;
  double SQUARE_2;
  findSquareRoot() {
    SQUARE_2 = sqrt(SQUARE_1);
    print(SQUARE_2);
  }
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
        home: Scaffold(
          appBar: AppBar(
            backgroundColor: Colors.lightGreen,
            title: Text("Square Root Of Given Number"),
          ),
            body: Center(
                child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Container(
                          margin: const EdgeInsets.fromLTRB(20, 10, 20, 10),
                          child: RaisedButton(
                            onPressed: () =>findSquareRoot(),
                            child: Text(' Find Square Root Of Number '),
                            textColor: Colors.white,
                            color: Color(0xFFFFC107),
                            padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
                          )),
                    ]
                )
            )
        )
    );
  }
}

Related Post