I am trying to make a multiline dropdown menu with multiple options, what I currently have is a line of code that has only one dependency, 'M100007' I want to add more. Explained in the example below.
This is the line of code :
selectedBusLine1 = newValue == 'M100007' ? businessLine2_01 : businessLine2_02;
I want to add more "newValue" values and not just one.
For example :
if "M100007" is selected then businessLine2_01,
if "M100008" is selected then businessLine2_02,
if "M100009" is selected then businessLine2_03,
if "M100010" is selected then businessLine2_04,
if "M100011" is selected then businessLine2_05,
if "M100012" is selected then businessLine2_06,
and so on...
Thank You for your help
CodePudding user response:
I recommend creating a Map
to create a one-to-mapping of the string to you businessLine2_01
-like objects
final mappedValues = {
'M100007' : businessLine2_01,
'M100008' : businessLine2_02,
'M100009' : businessLine2_03,
'M100010' : businessLine2_04,
// and so on..
};
final myValue = mappedValues['M100007']; // this is businessLine2_01
CodePudding user response:
Better try using switch
and case
statements.
For ex:
String selectedBus1 = "";
switch(newValue) {
case "M100010":{
selectedBus1 = buisnessLine2_02;
break;
}
case "M100011":{
selectedBus1 = buisnessLine2_03;
break;
}
case "M100012":{
selectedBus1 = buisnessLine2_04;
break;
}
case "M100013":{
selectedBus1 = buisnessLine2_05;
break;
}
default: {
selectedBus1 = buisnessLine2_default;
}
}
CodePudding user response:
You can add like this
selectedBusLine1 = newValue == 'M100007'
? businessLine2_01
: newValue == 'M100008'
? businessLine2_02
: newValue == 'M100009'
? businessLine2_03
: newValue == 'M100010'
? businessLine2_03
: newValue == 'M100011';