Created
October 11, 2019 05:18
-
-
Save McLarenCollege/bd5f49f464728a22ce36a40407b0e612 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:flutter/material.dart'; | |
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; | |
class InputPage extends StatefulWidget { | |
@override | |
_InputPageState createState() => _InputPageState(); | |
} | |
class _InputPageState extends State<InputPage> { | |
int gender; // Male = 0, Female = 1 | |
Color activeCardColor = Color(0xFF1D1F31); | |
Color inactiveCardColor = Color(0xFF111328); | |
@override | |
Widget build(BuildContext context) { | |
Color backgroundColorMale = inactiveCardColor; | |
Color backgroundColorFemale = inactiveCardColor; | |
if (gender == 0) { | |
backgroundColorMale = activeCardColor; | |
} else if (gender == 1) { | |
backgroundColorFemale = activeCardColor; | |
} | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('BMI CALCULATOR'), | |
centerTitle: true, | |
), | |
body: Column( | |
children: <Widget>[ | |
Expanded( | |
child: Row( | |
children: <Widget>[ | |
Expanded( | |
child: ReusableCard( | |
child: Column( | |
mainAxisSize: MainAxisSize.max, | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Icon( | |
FontAwesomeIcons.mars, | |
size: 100, | |
), | |
SizedBox( | |
height: 10, | |
), | |
Text( | |
'MALE', | |
style: TextStyle(fontSize: 24), | |
) | |
], | |
), | |
color: backgroundColorMale, | |
tapCallback: () { | |
setState(() { | |
gender = 0; | |
}); | |
print('Male selected'); | |
}, | |
), | |
), | |
Expanded( | |
child: ReusableCard( | |
child: Column( | |
mainAxisSize: MainAxisSize.max, | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Icon( | |
FontAwesomeIcons.venus, | |
size: 100, | |
), | |
SizedBox( | |
height: 10, | |
), | |
Text( | |
'FEMALE', | |
style: TextStyle(fontSize: 24), | |
) | |
], | |
), | |
color: backgroundColorFemale, | |
tapCallback: () { | |
setState(() { | |
gender = 1; | |
}); | |
print('Female selected'); | |
}, | |
), | |
) | |
], | |
), | |
), | |
Expanded( | |
child: ReusableCard(), | |
), | |
Expanded( | |
child: Row( | |
children: <Widget>[ | |
Expanded( | |
child: ReusableCard(), | |
), | |
Expanded( | |
child: ReusableCard(), | |
) | |
], | |
), | |
), | |
], | |
), | |
); | |
} | |
} | |
class ReusableCard extends StatelessWidget { | |
final Color color; | |
final Widget child; | |
final Function tapCallback; | |
ReusableCard( | |
{this.color = const Color(0xFF1D1F31), this.child, this.tapCallback}); | |
@override | |
Widget build(BuildContext context) { | |
return GestureDetector( | |
onTap: tapCallback, | |
child: Container( | |
margin: EdgeInsets.all(12), | |
decoration: BoxDecoration( | |
color: color, | |
borderRadius: BorderRadius.all( | |
Radius.circular(12), | |
), | |
), | |
child: child, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment