0

I am new to flutter and I have an issue to change text style dynamically.

I fetch data from firestore database in map like this

Map data = {"amount": "", "type": ""}

Example data1

data = { "amount": "3000", "type": "income" }

Example data2

data = { "amount": "3000", "type": "expense" }

I want to print this data in text widget like

Text('$ : ${data['amount']', style: $data['type'])"

my style.dart

final textStyle income = TextStyle {
    color: Colors.blue,
    fontSize: 24,
}

final textStyle expense = TextStyle {
    color: Colors.red,
    fontSize: 24
}

Can anyone suggest how I can do that?

1 Answer 1

1

You can do a condition check to change based on type like

Text('${data['amount']}', style: data['type'] == "expense" ? TextStyle(fontSize: 20, color: Colors.red) : TextStyle(fontSize: 12, color: Colors.blue)),
Sign up to request clarification or add additional context in comments.

1 Comment

Yes exactly what i want. thank you for help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.