0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Flutterで基礎代謝計算するappを作ってみた

Posted at

appのスクショ

image.png

ソースコード

学んだ事

TextFieldで入力した文字列を、基礎代謝を計算するために整数に変換したい。

main.dart
onPressed: () => setState(
   () {              
        _weight = double.parse(_weightController.text);
        _height = double.parse(_heightController.text);
        _age = int.parse(_ageController.text);
     }
                       

型.parse()で型変換を行った。TextFieldで値を操作するTextEddingControllerがString型なのでなんとかして整数に変換したかった。

Textで値を出力するためにString型に変換

main.dart
Text("あなたの基礎代謝は" +
 (((13.397 * _weight + 4.799 * _height - 5.677 * _age + 88.362) * base_number) .round() / base_number) 
.toString() + "(kcal)です"),

TextがString型なので(計算式).toString()で文字列に変換した。

終わりに(自分用)

dartのキャストが意外と時間がかかった印象なのでメモとして残しておく。テキストが入力されなかった場合など実装してないところがあるのでそこら辺を書いていこうと思う。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?