0

I am getting a lot of strings whos' names are those of icons. If I try to create and Icon with a string as name

Icon(
   Icons._transactionType
)

I get 'the getter _transactionType is not defined for for the class 'Icons''.

That is all the ideas I had so far, and also the flutter docs for icon and icons didn't help.

As of now i have hardcoded the icons in, but since i am now storing them in .json, i can only save them in strings, and i want to avoid a method that goes through all icons and choses the one i need.

Here you see it working now, and i want to get the icon istead of with 'Icons.train' with 'Icons._transactionType'

1 Answer 1

1

One way is to create a map

Map<String, IconData> iconMapping = {
 'train' : Icons.train,
 'airplane' : Icons.airplanemode_active,
 ...
};

and while using, instead of Icon(Icons._transactionType) use Icon(iconMapping[_transactionType])

Sign up to request clarification or add additional context in comments.

1 Comment

while this is the kind of solution i tried to avoid i still think it is the best one. i will do this then, thank you!

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.