Skip to content

Instantly share code, notes, and snippets.

@pinkeshdarji
Created May 24, 2021 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pinkeshdarji/8ca450cce185befdde0ebf24c9b232d8 to your computer and use it in GitHub Desktop.
Save pinkeshdarji/8ca450cce185befdde0ebf24c9b232d8 to your computer and use it in GitHub Desktop.
class ResponsiveWidget extends StatelessWidget {
final Widget smallScreen;
final Widget mediumScreen;
final Widget largeScreen;
const ResponsiveWidget({Key key,
this.mediumScreen,
@required this.smallScreen,
this.largeScreen})
: 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;
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment