The String path1 is derived from concatenating two strings. One string is hardcoded and the other string might be null. If the id string is null, I'd like path1 to be null. I'm thinking of doing a try/catch on electorates.legislatures[lt.type].id. Just wondering is there an elegant way to do this in line?
path1 = '/legislatures/' + electorates.legislatures[lt.type].id,
Since you want to allow the first string to be null, you could do:
var concatenation = suffix?.replaceRange(0, 0, prefix);
which in your case would be:
path1 = electorates.legislatures[lt.type].id?.replaceRange(0, 0, '/legislatures/');
(If eliminating null values could be an option instead of propagating them, a typical approach would be to do var concatenation = prefix ?? '' + suffix ?? '';.)