Skip to content

Instantly share code, notes, and snippets.

@yarn-rp
Created October 22, 2022 19:08
Show Gist options
  • Save yarn-rp/cd758c5b7607180ff6c8c02ea49151ca to your computer and use it in GitHub Desktop.
Save yarn-rp/cd758c5b7607180ff6c8c02ea49151ca to your computer and use it in GitHub Desktop.
class NewIntCaseWidget extends CaseWidget<int> {
NewIntCaseWidget({
super.key,
required int super.value,
}) {
onEquals(0, (value, context) => Text('Value is zero'));
onEquals(1, (value, context) => Text('Value is 1'));
onLessThan(1, (value, context) => Text('Value is less than 1'));
onGreaterThan(1, (value, context) => Text('Value is greater than 1'));
}
}
class OldIntCaseWidget extends StatelessWidget {
final int value;
const OldIntCaseWidget({
super.key,
required this.value,
});
@override
Widget build(BuildContext context) {
if (value == 0) {
return Text('Value is zero');
}
if (value == 1) {
return Text('Value is 1');
}
if (value < 1) {
return Text('Value is less than 1');
}
if (value > 1) {
return Text('Value is greater than 1');
}
return Text('$value not mathing any posibility');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment