0

I have a problem when I want to display a double value in flutter. I use Text widget and I need to transform my double 0.00 in a string to display it in the widget Text. The problem is it returns "null". I want to display "BALANCE: 0.00 €", I have the 0.00 stored in double var but I can't display the value with Text Widget. Here is my code :

 Container(
                child: Text(
                "BALANCE: "+globals.balance.toString()+" €",
                style: TextStyle(
                    fontSize: 15.0,
                    fontWeight: FontWeight.w500,
                    color: Colors.white),
               ),
          ),

Result is : BALANCE : null €

Hamed
  • 5,867
  • 4
  • 32
  • 56
axis-medias
  • 527
  • 2
  • 7
  • 17
  • Does this answer your question? [How do you round a double in Dart to a given degree of precision AFTER the decimal point?](https://stackoverflow.com/questions/28419255/how-do-you-round-a-double-in-dart-to-a-given-degree-of-precision-after-the-decim) – Tokenyet Apr 14 '20 at 04:51

1 Answers1

0

you can check if null and convert it to 0 like this:

"BALANCE : "+(globals.balance??0).toStringAsFixed(2)+" €",
Zvi Karp
  • 3,621
  • 3
  • 25
  • 40