Created
November 16, 2021 05:29
-
-
Save barriehadfield/a952c2edf38a1aad711e855a337f1d7c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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