Flutter Convert Int Variable To String Data Type App

admin_img Posted By Bajarangi soft , Posted On 03-11-2020

Flutter comes with inbuilt string methods and one of them is String toString() function which is used in Flutter to cast Int Variable to String type. The String toString() function returns integer into String format so we can easily use the number directly as String data type.

Flutter Convert Int Variable To String Data Type App

Convert Int Variable to String Data
Complete Code For In Flutter
main.dart

import 'package:flutter/material.dart';

void main(){
  runApp(MyApp());
}
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: MyHomePage(),
    );
  }
}
class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin {
  int value = 2034567890 ;
  String holder ;
  changeType(){
    setState(() {
      holder = value.toString();
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      appBar: AppBar(
        backgroundColor: Colors.pink[900],
        title: Text('Convert Int Integer Variable'),
      ),
            body: Center(
                child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[

                      Container(
                          padding: EdgeInsets.fromLTRB(0, 10, 0, 10),
                          child: Text('$value', style: TextStyle(fontSize: 22,color: Colors.white),)),

                      RaisedButton(
                        onPressed: () => changeType(),
                        child: Text('Convert Int Type to String on Button Click'),
                        textColor: Colors.white,
                        color: Colors.pink[900],
                        padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
                      )

                    ]))
    );
  }
}

Related Post