Categories
Mastering Development

In Dart, is there a better solution than a large switch statement

I have a large multi-level switch statement that I’m using to take a table/field ID combination and return a string. Is there a system in dart that is a better choice in regards to read-ability and performance than a switch statement? Is there anything like a mapping or something that I should be using?

This is a snippet of the switch statement which will have 100s of lines when it is done.

switch (tableID)
    {
        case DBTables.Abbreviations:
            switch (fieldID)
            {
                case TBAbbreviations.ID: result = 'Record ID'; break;
            }
            break;
        case DBTables.Activity:
            switch (fieldID)
            {
                case TBActivity.ID: result = 'Record ID'; break;
                case TBActivity.Nickname1: result = 'Nickname'; break;
                case TBActivity.Nickname2: result = 'Nickname 2'; break;                    
                case TBActivity.FullName: result = 'Fullname'; break;                    
                case TBActivity.Classification: result = 'Classification'; break;                    
            }
            break;
    }

    return 'Field Name: ' + result ;    

Leave a Reply

Your email address will not be published. Required fields are marked *