Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
137 lines (128 sloc) 3.98 KB
import 'package:bmi_calculator/app_bar.dart';
import 'package:bmi_calculator/calculator.dart' as calculator;
import 'package:bmi_calculator/input_page/input_page_styles.dart';
import 'package:bmi_calculator/model/gender.dart';
import 'package:flutter/material.dart';
class ResultPage extends StatefulWidget {
final int height;
final int weight;
final Gender gender;
const ResultPage({Key key, this.height, this.weight, this.gender})
: super(key: key);
@override
_ResultPageState createState() => _ResultPageState();
}
class _ResultPageState extends State<ResultPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: PreferredSize(
child: BmiAppBar(isInputPage: false),
preferredSize: Size.fromHeight(appBarHeight(context)),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
ResultCard(
bmi: calculator.calculateBMI(
height: widget.height, weight: widget.weight),
minWeight:
calculator.calculateMinNormalWeight(height: widget.height),
maxWeight:
calculator.calculateMaxNormalWeight(height: widget.height),
),
_buildBottomBar(),
],
),
);
}
Widget _buildBottomBar() {
return Padding(
padding: const EdgeInsets.only(bottom: 30.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 40.0),
child: IconButton(
icon: Icon(
Icons.delete,
color: Colors.grey,
size: 28.0,
),
onPressed: () => Navigator.of(context).pop(),
),
),
Container(
height: 52.0,
width: 80.0,
child: RaisedButton(
child: Icon(
Icons.refresh,
color: Colors.white,
size: 28.0,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6.0),
),
onPressed: () => Navigator.of(context).pop(),
color: Theme.of(context).primaryColor,
)),
Padding(
padding: const EdgeInsets.only(left: 40.0),
child: IconButton(
icon: Icon(
Icons.share,
color: Colors.grey,
size: 28.0,
),
onPressed: () {},
),
),
],
),
);
}
}
class ResultCard extends StatelessWidget {
final double bmi;
final double minWeight;
final double maxWeight;
ResultCard({Key key, this.bmi, this.minWeight, this.maxWeight})
: super(key: key);
@override
Widget build(BuildContext context) {
return Card(
margin: EdgeInsets.all(16.0),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 24.0),
child: Container(
width: double.infinity,
child: Column(children: [
Text(
'🔥',
style: TextStyle(fontSize: 80.0),
),
Text(
bmi.toStringAsFixed(1),
style: TextStyle(fontSize: 140.0, fontWeight: FontWeight.bold),
),
Text(
'BMI = ${bmi.toStringAsFixed(2)} kg/m²',
style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.w700),
),
Padding(
padding: const EdgeInsets.only(top: 16.0),
child: Text(
'Normal BMI weight range for the height:\n${minWeight.round()}kg - ${maxWeight.round()}kg',
style: TextStyle(fontSize: 14.0, color: Colors.grey),
textAlign: TextAlign.center,
),
),
]),
),
),
);
}
}