Last active
November 19, 2019 17:06
-
-
Save ggichure/d3441a8cfc5bb9a32e104d9467b8fc5b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| @override | |
| Widget build(BuildContext context) { | |
| return ResponsiveWidget( | |
| largeScreen: Scaffold( | |
| appBar: ResponsiveWidget.isSmallScreen(context) | |
| ?AppBar( | |
| leading: ClipRRect( | |
| child: Container( | |
| height: 20, | |
| width: 20, | |
| child: Text("small screen"), | |
| ), | |
| actions: <Widget>[], | |
| elevation: 0.0, | |
| ): | |
| AppBar( | |
| leading: ClipRRect( | |
| child: Container( | |
| height: 20, | |
| width: 20, | |
| child: Text("large screen"), | |
| ), | |
| actions: <Widget>[], | |
| elevation: 0.0, | |
| ) | |
| body: ResponsiveWidget.isSmallScreen(context) | |
| ? smallScreen() | |
| : largeScreen(), | |
| ), | |
| ); |
This file contains hidden or 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
| import 'package:flutter_web/material.dart'; | |
| class ResponsiveWidget extends StatelessWidget { | |
| final Widget largeScreen; | |
| final Widget mediumScreen; | |
| final Widget smallScreen; | |
| const ResponsiveWidget( | |
| {Key key, | |
| @required this.largeScreen, | |
| this.mediumScreen, | |
| this.smallScreen}) | |
| : super(key: key); | |
| static bool isSmallScreen(BuildContext context) { | |
| return MediaQuery.of(context).size.width < 800; | |
| } | |
| static bool isLargeScreen(BuildContext context) { | |
| return MediaQuery.of(context).size.width > 800; | |
| } | |
| static bool isMediumScreen(BuildContext context) { | |
| return MediaQuery.of(context).size.width >= 800 && | |
| MediaQuery.of(context).size.width <= 1200; | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return LayoutBuilder( | |
| builder: (context, constraints) { | |
| if (constraints.maxWidth > 1200) { | |
| return largeScreen; | |
| } else if (constraints.maxWidth <= 1200 && constraints.maxWidth >= 800) { | |
| return mediumScreen ?? largeScreen; | |
| } else { | |
| return smallScreen ?? largeScreen; | |
| } | |
| }, | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment