Skip to content

Instantly share code, notes, and snippets.

@crizant
Created February 7, 2020 17:22
Show Gist options
  • Save crizant/e83b3f880d749c7577301455a5218450 to your computer and use it in GitHub Desktop.
Save crizant/e83b3f880d749c7577301455a5218450 to your computer and use it in GitHub Desktop.
Flutter conditional rendering plugin: switch condition
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
ConditionalSwitch.single<String>(
context: context,
valueBuilder: (BuildContext context) => 'A',
caseBuilders: {
'A': (BuildContext context) => Text('The value is A!'),
'B': (BuildContext context) => Text('The value is B!'),
},
fallbackBuilder: (BuildContext context) => Text('None of the cases matched!'),
),
],
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment