Skip to content

Instantly share code, notes, and snippets.

@kranfix
Last active January 9, 2022 17:18
Show Gist options
  • Save kranfix/e8d221df54e6c004f1b974cc9f63d5a3 to your computer and use it in GitHub Desktop.
Save kranfix/e8d221df54e6c004f1b974cc9f63d5a3 to your computer and use it in GitHub Desktop.
late final solution to the var problem in Dart
void main() {
final list = <int>[1, 2, 3, 4, 2, -1, 5];
final maxValue = 12;
late final int sum;
{
var _sum = 0;
for(final val in list) {
_sum += val;
}
if(_sum > maxValue) {
_sum = maxValue;
}
sum = _sum;
}
/// ... more code that uses `sum` ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment