Skip to content

Instantly share code, notes, and snippets.

@JohanScheepers
Created September 24, 2025 19:20
Show Gist options
  • Select an option

  • Save JohanScheepers/7848dbc4e2fff4ddaf1471d320d38c70 to your computer and use it in GitHub Desktop.

Select an option

Save JohanScheepers/7848dbc4e2fff4ddaf1471d320d38c70 to your computer and use it in GitHub Desktop.
class OpinionOnDart {
const OpinionOnDart({
required this.love,
this.hate,
});
final String love;
final String? hate;
void express() {
// I love Dart's type safety, which ensures 'love' is never null.
print('What I love: $love');
// I use the if-null operator (??) to provide a default value
// in case there's nothing to hate.
print('What I hate: ${hate ?? 'Nothing at all! Dart is great.'}');
}
}
void main() {
// My opinion is constant and unchanging.
const myOpinion = OpinionOnDart(
love: 'Its expressive syntax, incredible performance on multiple platforms (from mobile to web), and a developer-friendly, pragmatic approach to building software.',
// The 'hate' property is null, so there are no complaints.
);
myOpinion.express();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment