Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BMI calculator example #130

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions bmi_calculator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
.DS_Store
.dart_tool/

.vscode/

.packages
.pub/

.idea/
.vagrant/
.sconsign.dblite
.svn/

migrate_working_dir/

*.swp
profile

DerivedData/

.generated/

*.pbxuser
*.mode1v3
*.mode2v3
*.perspectivev3

!default.pbxuser
!default.mode1v3
!default.mode2v3
!default.perspectivev3

xcuserdata

*.moved-aside

*.pyc
*sync/
Icon?
.tags*

build/
.android/
.ios/
.flutter-plugins
.flutter-plugins-dependencies

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json
10 changes: 10 additions & 0 deletions bmi_calculator/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: f1875d570e39de09040c8f79aa13cc56baab8db1
channel: stable

project_type: module
7 changes: 7 additions & 0 deletions bmi_calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# bmi_calculator

A person’s Body-Mass Index, or BMI, helps them check whether they’re a healthy weight for their height. If a person weighs less or more than the recommended weight for their height, it could lead to health issues in the future. While BMI is not the only factor individuals should consider while working on their health and fitness, it is a good starting point. To understand what your BMI is, you need to know your height and weight. You can then use an online BMI calculator to check your BMI, which will help you understand if you’re underweight, a healthy weight, overweight or obese. Or, you can measure your height in metres and weight in kilograms. Divide your weight by your height squared to calculate your BMI.

BMI Calculator [Wiki](https://en.wikipedia.org/wiki/Body_mass_index)


4 changes: 4 additions & 0 deletions bmi_calculator/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include: package:flutter_lints/flutter.yaml

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
9 changes: 9 additions & 0 deletions bmi_calculator/lib/bmi_calculator.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'dart:math';

import 'package:bmi_calculator/body_model.dart';

// I've used weight/height^2 (kg/m^2)
// You can expand this logic
double calculateBMI({required BodyModel bodyModel}) {
return (bodyModel.weight) / pow(bodyModel.height / 100, 2);
}
19 changes: 19 additions & 0 deletions bmi_calculator/lib/body_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
enum Sex {
male,
female,
}

// User body model class
class BodyModel {
Sex sex;
int height;
int weight;
int age;

BodyModel({
required this.sex,
required this.height,
required this.weight,
required this.age,
});
}
Loading