Created
June 25, 2019 06:17
-
-
Save SouravKumarPandit/2153393fd2ed00e9f369103006113637 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
import 'package:dev_rpg/src/style.dart'; | |
import 'package:flutter/material.dart'; | |
/// Layout for the dev_rpg game. | |
enum RpgLayout { slim, wide, ultrawide } | |
/// Signature for a function that builds a widget given an [RpgLayout]. | |
/// | |
/// Used by [RpgLayoutBuilder.builder]. | |
typedef RpgLayoutWidgetBuilder = Widget Function( | |
BuildContext context, RpgLayout layout); | |
/// Builds a widget tree that can depend on the parent widget's width | |
class RpgLayoutBuilder extends StatelessWidget { | |
const RpgLayoutBuilder({ | |
@required this.builder, | |
Key key, | |
}) : assert(builder != null), | |
super(key: key); | |
/// Builds the widgets below this widget given this widget's layout width. | |
final RpgLayoutWidgetBuilder builder; | |
Widget _build(BuildContext context, BoxConstraints constraints) { | |
var mediaWidth = MediaQuery.of(context).size.width; | |
final RpgLayout layout = mediaWidth >= ultraWideLayoutThreshold | |
? RpgLayout.ultrawide | |
: mediaWidth > wideLayoutThreshold ? RpgLayout.wide : RpgLayout.slim; | |
return builder(context, layout); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return LayoutBuilder(builder: _build); | |
} | |
} | |
/* | |
RpgLayoutBuilder( | |
builder: (context, layout) => layout != RpgLayout.slim | |
? Padding( | |
padding: const EdgeInsets.only(top: 58), | |
child: FractionallySizedBox( | |
widthFactor: 0.5, | |
child: WelcomeButton( | |
onPressed: () => | |
Navigator.of(context).pop(), | |
background: | |
Colors.white.withOpacity(0.15), | |
label: 'DONE', | |
), | |
), | |
) | |
: Container(), | |
), | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment