/gender_card.dart Secret
Created
August 24, 2018 15:51
Star
You must be signed in to star a gist
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 'dart:math' as math; | |
import 'package:flutter_svg/flutter_svg.dart'; | |
const double _defaultGenderAngle = math.pi / 4; | |
const Map<Gender, double> _genderAngles = { | |
Gender.female: -_defaultGenderAngle, | |
Gender.other: 0.0, | |
Gender.male: _defaultGenderAngle, | |
}; | |
class GenderIconTranslated extends StatelessWidget { | |
static final Map<Gender, String> _genderImages = { | |
Gender.female: "images/gender_female.svg", | |
Gender.other: "images/gender_other.svg", | |
Gender.male: "images/gender_male.svg", | |
}; | |
final Gender gender; | |
const GenderIconTranslated({Key key, this.gender}) : super(key: key); | |
bool get _isOtherGender => gender == Gender.other; | |
String get _assetName => _genderImages[gender]; | |
double _iconSize(BuildContext context) { | |
return screenAwareSize(_isOtherGender ? 22.0 : 16.0, context); | |
} | |
double _genderLeftPadding(BuildContext context) { | |
return screenAwareSize(_isOtherGender ? 8.0 : 0.0, context); | |
} | |
@override | |
Widget build(BuildContext context) { | |
Widget icon = Padding( | |
padding: EdgeInsets.only(left: _genderLeftPadding(context)), | |
child: SvgPicture.asset( | |
_assetName, | |
height: _iconSize(context), | |
width: _iconSize(context), | |
), | |
); | |
Widget rotatedIcon = Transform.rotate( | |
angle: -_genderAngles[gender], | |
child: icon, | |
); | |
Widget iconWithALine = Padding( | |
padding: EdgeInsets.only(bottom: _circleSize(context) / 2), | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.center, | |
children: <Widget>[ | |
rotatedIcon, | |
GenderLine(), | |
], | |
), | |
); | |
Widget rotatedIconWithALine = Transform.rotate( | |
alignment: Alignment.bottomCenter, | |
angle: _genderAngles[gender], | |
child: iconWithALine, | |
); | |
Widget centeredIconWithALine = Padding( | |
padding: EdgeInsets.only(bottom: _circleSize(context) / 2), | |
child: rotatedIconWithALine, | |
); | |
return centeredIconWithALine; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment