Created
May 24, 2021 13:45
-
-
Save pinkeshdarji/8ca450cce185befdde0ebf24c9b232d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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