Skip to content

Instantly share code, notes, and snippets.

@ptyagicodecamp
Created June 11, 2019 20:26
Show Gist options
  • Save ptyagicodecamp/5257246165f81224cf7a6573d8a83edd to your computer and use it in GitHub Desktop.
Save ptyagicodecamp/5257246165f81224cf7a6573d8a83edd to your computer and use it in GitHub Desktop.
class ResponsiveWidget {
...
final Widget largeScreen;
final Widget mediumScreen;
final Widget smallScreen;
const ResponsiveWidget(
{Key key, this.largeScreen, this.mediumScreen, this.smallScreen})
: super(key: key);
@override
Widget build(BuildContext context) {
//Returns the widget which is more appropriate for the screen size
return LayoutBuilder(builder: (context, constraints) {
if (constraints.maxWidth > 1200) {
return largeScreen;
} else if (constraints.maxWidth > 800 && constraints.maxWidth < 1200) {
//if medium screen not available, then return large screen
return mediumScreen ?? largeScreen;
} else {
//if small screen implementation not available, then return large screen
return smallScreen ?? largeScreen;
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment