Flutter convert int variable to string

后端 未结 4 906
北荒
北荒 2020-12-03 17:06

I\'m new with Flutter and I wonder about how difficult is (for me) to find a solution on how to convert my variable var int counter = 0; into a variable var String $

相关标签:
4条回答
  • 2020-12-03 17:20
    int i=10;
    String st = i.toString(); // Converted to String
    
    0 讨论(0)
  • 2020-12-03 17:25

    Use toString and/or toRadixString

      int intValue = 1;
      String stringValue = intValue.toString();
      String hexValue = intValue.toRadixString(16);
    

    or, as in the commment

      String anotherValue = 'the value is $intValue';
    
    0 讨论(0)
  • 2020-12-03 17:25

    You can use the .toString() function in the int class.

    int age = 23;
    String tempAge = age.toString();
    

    then you can simply covert integers to the Strings.

    0 讨论(0)
  • 2020-12-03 17:45

    // String to int

    String s = "45";
    int i = int.parse(s);
    

    // int to String

    int j = 45;
    String t = "$j";
    

    // If the latter one looks weird, look into string interpolation on https://dart.dev

    0 讨论(0)
提交回复
热议问题