Skip to content

Instantly share code, notes, and snippets.

@barriehadfield
Created November 16, 2021 05:29
Show Gist options
  • Save barriehadfield/a952c2edf38a1aad711e855a337f1d7c to your computer and use it in GitHub Desktop.
Save barriehadfield/a952c2edf38a1aad711e855a337f1d7c to your computer and use it in GitHub Desktop.
enum EngagementType { unknown, newsItem, coachingTip, facilitation, surveyEngagement, videoMessage, textMessage, reflection, }
/// this one extension provides all the central policy logic for all EngagementTypes
extension EngagementManagement on EngagementType {
String get displayName {
switch (this) {
case EngagementType.reflection:
return 'Reflection';
case EngagementType.textMessage:
return 'Text Message';
case EngagementType.videoMessage:
return 'Video Message';
case EngagementType.surveyEngagement:
return 'Survey Engagement';
case EngagementType.facilitation:
return 'Facilitation';
case EngagementType.coachingTip:
return 'Coaching Tip';
case EngagementType.newsItem:
return 'News Item';
default:
return 'UNKNOWN';
}
}
bool get isAllowedInFacilitation {
// All types are allowed in a Facilitation other then the unknown one
if(this == EngagementType.unknown) return false;
return true;
}
bool get isAllowedOnHomeScreen {
// Only some types are allowed on the home screen
switch (this) {
case EngagementType.textMessage:
case EngagementType.videoMessage:
case EngagementType.surveyEngagement:
return true;
default:
return false;
}
}
// we add new methods as we need them....
}
main() {
// to get data from an enum type
print('My name is ${EngagementType.videoMessage.displayName} and I am allowed in a Facilitation: ${EngagementType.videoMessage.isAllowedInFacilitation}' );
// to iterate through all types and take some action based on the policy
for (var type in EngagementType.values) {
print('Is ${type.displayName} allowd on home screen? ${type.isAllowedOnHomeScreen}');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment