1

I want to show amount of discount percent in Text widget in flutter, i used the Discount calculation formula but it didn't worked , How can i do that? this is what i want:

Container(
  decoration: BoxDecoration(
  color: Color(0xfff40725),
  borderRadius: BorderRadius.circular(50),
),

child: Padding(
  padding: const EdgeInsets.all(5.0),
  child: Text(
    '50% (but with formula',
    style: TextStyle(
      color: Colors.white, 
      fontWeight: FontWeight.bold),
    ),
  ),
),
Aimnox
  • 895
  • 7
  • 20
Mehrdad Hosseini
  • 357
  • 1
  • 4
  • 17

1 Answers1

3

You can use string substitution.

Text("${your_formula()}%")
  • Thanks but where i can use the formula? when i try to defined it , i got this error: Only static members can be accessed in initializers, what does this mean? – Mehrdad Hosseini Jan 17 '20 at 10:01
  • I think I'd need to see more code to be able to help you with this. See here for how it works: https://dartpad.dev/953579e821cc2c5ddebee07e4fe0894f – Mikołaj Kojdecki Jan 20 '20 at 10:59