Skip to content

Instantly share code, notes, and snippets.

@MarcinusX
Created August 24, 2018 15:51
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save MarcinusX/a5608f2e9f9642cf7b5e0133b434c30e to your computer and use it in GitHub Desktop.
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