Dart Convert String To Double Float Using Flutter App

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

As we all know Double data type is like parent of Float data type. In current programming arena most of developers use Double data type as place of Float data type. Dart gives us a inbuilt function named as double.parse(String) which is used to convert String numbered value to Double so the user can perform any type of mathematical operation on that value.

Dart Convert String To Double Float Using Flutter App

Dart Convert String To Double Float
Complete Code For Dart Convert String To Double Float In Flutter
Main.dart

import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
  String value1 = '87654321';
  double value2;
  changeType() {
    value2 = double.parse(value1);
    print(value2);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
        home: Scaffold(
          appBar: AppBar(
            backgroundColor: Colors.deepOrange,
            title: Text('Custom New Widget'),
          ),
          body: Center(
              child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    Container(
                        margin: const EdgeInsets.fromLTRB(20, 10, 20, 10),
                        child: RaisedButton(
                          onPressed: () => changeType(),
                          child: Text('Convert String to Double on Click'),
                          textColor: Colors.white,
                          color: Colors.lightBlue,
                          padding: EdgeInsets.fromLTRB(12, 12, 12, 12),
                        )),
                  ])))
    );
  }
}

Related Post