Created
June 11, 2019 20:26
-
-
Save ptyagicodecamp/5257246165f81224cf7a6573d8a83edd 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 { | |
... | |
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