Created
December 27, 2019 05:16
-
-
Save tarek360/6a0f1f22a8371b32f302cb9c176e3f77 to your computer and use it in GitHub Desktop.
SafeSpace top or bottom, (in progress)
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/widgets.dart'; | |
enum _Position { | |
bottom, | |
top, | |
right, | |
left, | |
} | |
class SafeSpace extends StatelessWidget { | |
const SafeSpace.top({this.color}) : this._position = _Position.top; | |
const SafeSpace.bottom({this.color}) : this._position = _Position.bottom; | |
final Color color; | |
final _Position _position; | |
@override | |
Widget build(BuildContext context) { | |
final double bottom = MediaQuery.of(context).padding.bottom; | |
final double top = MediaQuery.of(context).padding.top; | |
final double right = MediaQuery.of(context).padding.right; | |
final double left = MediaQuery.of(context).padding.left; | |
print('bottom: $bottom'); | |
print('top: $top'); | |
print('right: $right'); | |
print('left: $left'); | |
Widget space; | |
switch (_position) { | |
case _Position.top: | |
space = Container(color: color, height: top); | |
break; | |
case _Position.left: | |
space = Container(color: color, height: left); | |
break; | |
case _Position.right: | |
space = Container(color: color, height: right); | |
break; | |
case _Position.bottom: | |
space = Container(color: color, height: bottom); | |
break; | |
} | |
return space; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment