If you are attempting to put a String variable inside another static String you can do the following for simple variables:
String firstString = 'sentence';
String secondString = 'This is a $firstString';
Which will output This is a sentence.
If the String is a property of an object, then you must use ${}like this:
person.name = 'Shilpa';
String newString = 'This is my name: ${person.name}';
Which will output This is my name: Shilpa.
If you are attempting to put a String variable inside another static String you can do the following for simple variables:
String firstString = 'sentence';
String secondString = 'This is a $firstString';
Which will output This is a sentence.
If the String is a property of an object, then you must use ${}like this:
person.name = 'Shilpa';
String newString = 'This is my name: ${person.name}';
Which will output This is my name: Shilpa.
Try like this
String Roll_no='3250\$10'
Videos
I'm new to FF and struggling to learn how to reference a variable within a string after searching fro far and wide. Seems like a pretty basic feature, ie in a prompt for an APICall be able to put something like "I want this type of {paddle_pop}" where paddle_pop is the variable. Brackets. don't seem to work.
Is this possible or do I have to code it in a custom action?
Change this:
const ListTile(
leading: const Icon(Icons.album),
title: Text(_placeCard.title),
subtitle: const Text('Come and dance tonight!'),
);
into this:
const ListTile(
leading: const Icon(Icons.album),
title: const Text(_placeCard.title),
subtitle: const Text('Come and dance tonight!'),
);
Since in your screenshot ListTile is a constant then all the properties need to be constant also, therefore add const before Text(_placeCard.title),
Const will be assumed for Icon and Text, as they have to be constant, so that the ListTile can be constant as a whole.
So it's the same to write:
const ListTile(
leading: const Icon(Icons.album),
title: const Text(_placeCard.title),
subtitle: const Text('Come and dance tonight!'),
);
as
const ListTile(
leading: Icon(Icons.album),
title: Text(_placeCard.title),
subtitle: Text('Come and dance tonight!'),
);
But you seem to confuse the meaning of const anyway, as this probably won't work in your application.
From news.dartlang.org,
"const" has a meaning that's a bit more complex and subtle in Dart. const modifies values. You can use it when creating collections, like const [1, 2, 3], and when constructing objects (instead of new) like const Point(2, 3). Here, const means that the object's entire deep state can be determined entirely at compile time and that the object will be frozen and completely immutable
so that means that you could say
const ListTile(
leading: Icon(Icons.album),
title: Text("foo"),
subtitle: Text('Come and dance tonight!'),
);
but not create that Object constant while running the application, as you don't have all data at compile-time.
You should just not use const and then it should be alrighto.
Dart when used in flutter doesn't support reflection.
If it's text that you want to have directly in your code for some reason, I'd advise using a text replace (using your favourite tool or using intellij's find + replace with regex) to change it into a map, i.e.
final Map<String, String> whee = {
'XVG': 'url 1',
'BTC': 'url 2',
};
Another alternative is saving it as a JSON file in your assets, and then loading it and reading it when the app opens, or even downloading it from a server on first run / when needed (in case the URLs need updating more often than you plan on updating the app). Hardcoding a bunch of data like that isn't necessarily always a good idea.
EDIT: how to use.
final Map<String, String> whee = .....
String getIconsURL(String symbol) {
//symbol = 'XVG'
return whee[symbol];
}
If you define it in a class make sure you set it to static as well so it doesn't make another each time the class is instantiated.
Also, if you want to iterate through them you have the option of using entries, keys, or values - see the Map Class documentation
I'd just implement a getProperty(String name) method or the [] operator like:
class URLsList{
var XVG = 'some url';
var BTC = 'some url';
String get operator [](String key) {
switch(key) {
case 'XVG': return XVG;
case 'BTC': return BTC;
}
}
}
String getIconsURL(String symbol) {
var list = new URLsList();
return list[symbol];
}
You can also use reflectable package that enables you to use reflection-like code by code generation.