Home > Net >  How to use dynamic map name in flutter
How to use dynamic map name in flutter

Time:11-05

I want to create a new map every time the button is pressed. I want the names of the maps to be regular. I tried using ${} in the map name but it doesn't seem to work. is there any solution?

CodePudding user response:

There are a few ways to do this:

  1. Use the sprintf function:

String mapName = sprintf("map_%d", mapNumber);

  1. Use string interpolation:

String mapName = "map_${mapNumber}";

  1. Use a template string:

String mapName = map_${mapNumber};

CodePudding user response:

You may think you want this, but you don't. Information and meta-information should remain separate. Very likely, a Map of Maps will accomplish everything you want with dynamic names.

  • Related