Skip to content

Commit efcff14

Browse files
committed
clean code
1 parent b1a8092 commit efcff14

22 files changed

+325
-171
lines changed

lib/common/show_capture.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import 'dart:typed_data';
22

33
import 'package:flutter/material.dart';
44

5-
Future<dynamic> showCapturedWidget(BuildContext context, Uint8List capturedImage) {
5+
Future<dynamic> showCapturedWidget(
6+
BuildContext context, Uint8List capturedImage) {
67
return showDialog(
78
useSafeArea: false,
89
context: context,
910
builder: (context) => Scaffold(
1011
appBar: AppBar(
11-
title: Text("Captured Widget Screenshot"),
12+
title: const Text("Captured Widget Screenshot"),
1213
),
1314
body: Center(
1415
child: Image.memory(capturedImage),

lib/const.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ final glucoseWhenLabel = [
5757
final mainMenu = [
5858
Menu(
5959
"Body Mass Index",
60-
FontAwesomeIcons.weight,
60+
FontAwesomeIcons.weightScale,
6161
listColor[1],
6262
const BmiPage(),
6363
),
6464
Menu(
6565
"Blood Pressure",
66-
FontAwesomeIcons.heartbeat,
66+
FontAwesomeIcons.heartPulse,
6767
listColor[2],
6868
const BloodPressurePage(),
6969
),

lib/controllers/app_controller.dart

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class AppController extends GetxController {
4040
// bmi calculation
4141
double bmiCalculation({required double weight, required double height}) {
4242
double bmi = weight / math.pow((height / 100), 2);
43-
log("bmi value -> " + bmi.toString());
43+
log("bmi value -> $bmi");
4444
return bmi;
4545
}
4646

@@ -50,8 +50,9 @@ class AppController extends GetxController {
5050
// 2 - pre-hyper
5151
// 3 - hyper state 1
5252
// 4 - hyper state 2
53-
int bloodPressureCalculation({required int systolic, required int diastolic}) {
54-
log(systolic.toString() + "/" + diastolic.toString());
53+
int bloodPressureCalculation(
54+
{required int systolic, required int diastolic}) {
55+
log("$systolic/$diastolic");
5556
if ((systolic <= 90) && (diastolic <= 60)) {
5657
log("bp status -> 0");
5758
return 0;
@@ -202,27 +203,41 @@ class AppController extends GetxController {
202203
}
203204

204205
// add bmi
205-
addBmi({required DateTime dateTime, required double height, required double weight}) async {
206+
addBmi(
207+
{required DateTime dateTime,
208+
required double height,
209+
required double weight}) async {
206210
final box = await Hive.openBox<Bmi>('Bmi');
207211
final bmi = bmiCalculation(weight: weight, height: height);
208212
final level = bmiDecode(bmi: bmi);
209-
box.put(dateTime.microsecondsSinceEpoch.toString(), Bmi(dateTime, height, weight, bmi, level));
213+
box.put(dateTime.microsecondsSinceEpoch.toString(),
214+
Bmi(dateTime, height, weight, bmi, level));
210215
update();
211216
}
212217

213218
// add blood pressure
214-
addBloodPressure({required DateTime dateTime, required int systolic, required int diastolic, required int pulse}) async {
219+
addBloodPressure(
220+
{required DateTime dateTime,
221+
required int systolic,
222+
required int diastolic,
223+
required int pulse}) async {
215224
final box = await Hive.openBox<BloodPressure>('BloodPressure');
216-
final type = bloodPressureCalculation(systolic: systolic, diastolic: diastolic);
217-
box.put(dateTime.microsecondsSinceEpoch.toString(), BloodPressure(dateTime, systolic, diastolic, pulse, type, []));
225+
final type =
226+
bloodPressureCalculation(systolic: systolic, diastolic: diastolic);
227+
box.put(dateTime.microsecondsSinceEpoch.toString(),
228+
BloodPressure(dateTime, systolic, diastolic, pulse, type, []));
218229
update();
219230
}
220231

221-
addGluecose({required DateTime dateTime, required int glucose, required int when}) async {
232+
addGluecose(
233+
{required DateTime dateTime,
234+
required int glucose,
235+
required int when}) async {
222236
final box = await Hive.openBox<Glucose>('Glucose');
223237
final level = glucoseCalculation(when: when, unit: glucose);
224238
//log('lv -> ' + level.toString());
225-
box.put(dateTime.microsecondsSinceEpoch.toString(), Glucose(dateTime, glucose, [], when, level));
239+
box.put(dateTime.microsecondsSinceEpoch.toString(),
240+
Glucose(dateTime, glucose, [], when, level));
226241
update();
227242
}
228243

@@ -264,15 +279,21 @@ class AppController extends GetxController {
264279

265280
// bmi
266281
final boxBmi = await Hive.openBox<Bmi>('Bmi');
267-
final bmiValue = bmiCalculation(weight: 77 - random.toDouble(), height: 165);
282+
final bmiValue =
283+
bmiCalculation(weight: 77 - random.toDouble(), height: 165);
268284
final bmiLevel = bmiDecode(bmi: bmiValue);
269-
boxBmi.put(key, Bmi(dateTime, 165, 77 - random.toDouble(), bmiValue, bmiLevel));
285+
boxBmi.put(
286+
key, Bmi(dateTime, 165, 77 - random.toDouble(), bmiValue, bmiLevel));
270287
log('sample bmi -> ${boxBmi.values.first.bmi}');
271288

272289
// blood pressure
273290
final boxBp = await Hive.openBox<BloodPressure>('BloodPressure');
274-
final bpLevel = bloodPressureCalculation(systolic: 109 - random, diastolic: 85 - random);
275-
boxBp.put(key, BloodPressure(dateTime, 109 - random, 85 - random, 80 - random, bpLevel, []));
291+
final bpLevel = bloodPressureCalculation(
292+
systolic: 109 - random, diastolic: 85 - random);
293+
boxBp.put(
294+
key,
295+
BloodPressure(
296+
dateTime, 109 - random, 85 - random, 80 - random, bpLevel, []));
276297
log('sample blood pressure sys -> ${boxBp.values.first.systolic}');
277298

278299
// blood pressure

lib/pages/bloodpressure/add_blood_pressure.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore_for_file: use_build_context_synchronously
2+
13
import 'dart:developer';
24

35
import 'package:flutter/material.dart';
@@ -78,7 +80,7 @@ class _AddBloodPressurePageState extends State<AddBloodPressurePage> {
7880
context: context,
7981
initialDate: DateTime.now(),
8082
firstDate: DateTime.now()
81-
.subtract(Duration(days: 365)),
83+
.subtract(const Duration(days: 365)),
8284
lastDate: DateTime.now());
8385
try {
8486
dateTextController.text =
@@ -216,9 +218,7 @@ class _AddBloodPressurePageState extends State<AddBloodPressurePage> {
216218
dateTextController.text.isNotEmpty &&
217219
timeTextController.text.isNotEmpty) {
218220
final dateTime = DateTime.parse(
219-
dateTextController.text +
220-
" " +
221-
timeTextController.text);
221+
"${dateTextController.text} ${timeTextController.text}");
222222
final systolic = int.parse(
223223
systolicTextController.text.trim(),
224224
);

lib/pages/bloodpressure/blood_pressure.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class BloodPressurePage extends StatefulWidget {
1717
const BloodPressurePage({Key? key}) : super(key: key);
1818

1919
@override
20+
// ignore: library_private_types_in_public_api
2021
_BloodPressurePageState createState() => _BloodPressurePageState();
2122
}
2223

lib/pages/bloodpressure/blood_pressure_history.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:phr/models/bloodpressure.dart';
88
import 'package:phr/themes/theme.dart';
99
import 'package:phr/widgets/boxdevider_widget.dart';
1010

11+
// ignore: use_key_in_widget_constructors
1112
class BloodPressureHistoryPage extends StatefulWidget {
1213
@override
1314
State<BloodPressureHistoryPage> createState() =>

lib/pages/bmi/add_bmi.dart

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,14 @@ class _AddBMIPageState extends State<AddBMIPage> {
8181
var dateValue = await showDatePicker(
8282
context: context,
8383
initialDate: DateTime.now(),
84-
firstDate: DateTime.now().subtract(Duration(days: 365)),
84+
firstDate: DateTime.now()
85+
.subtract(const Duration(days: 365)),
8586
lastDate: DateTime.now());
8687
try {
87-
dateTextController.text = (DateFormat('yyyy-MM-dd').format(dateValue!).toString());
88+
dateTextController.text =
89+
(DateFormat('yyyy-MM-dd')
90+
.format(dateValue!)
91+
.toString());
8892
} catch (e) {
8993
log("no select date");
9094
}
@@ -113,13 +117,16 @@ class _AddBMIPageState extends State<AddBMIPage> {
113117
initialTime: TimeOfDay.now(),
114118
builder: (context, child) {
115119
return MediaQuery(
116-
data: MediaQuery.of(context).copyWith(alwaysUse24HourFormat: true),
120+
data: MediaQuery.of(context).copyWith(
121+
alwaysUse24HourFormat: true),
117122
child: child!,
118123
);
119124
},
120125
);
121126
try {
122-
timeTextController.text = timeValue!.format(context);
127+
timeTextController.text =
128+
// ignore: use_build_context_synchronously
129+
timeValue!.format(context);
123130
} catch (e) {
124131
log("no select time");
125132
}
@@ -190,7 +197,7 @@ class _AddBMIPageState extends State<AddBMIPage> {
190197
dateTextController.text.isNotEmpty &&
191198
timeTextController.text.isNotEmpty) {
192199
final dateTime = DateTime.parse(
193-
dateTextController.text + " " + timeTextController.text,
200+
"${dateTextController.text} ${timeTextController.text}",
194201
);
195202
final weight = double.parse(
196203
weightTextController.text.trim(),
@@ -199,7 +206,8 @@ class _AddBMIPageState extends State<AddBMIPage> {
199206
heightTextController.text.trim(),
200207
);
201208

202-
bmi = appController.bmiCalculation(weight: weight, height: height);
209+
bmi = appController.bmiCalculation(
210+
weight: weight, height: height);
203211
level = appController.bmiDecode(bmi: bmi);
204212

205213
appController.addBmi(

lib/pages/bmi/bmi.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class BmiPage extends StatefulWidget {
1616
const BmiPage({Key? key}) : super(key: key);
1717

1818
@override
19+
// ignore: library_private_types_in_public_api
1920
_BmiPageState createState() => _BmiPageState();
2021
}
2122

lib/pages/bmi/bmi_history.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class _BMIHistoryPageState extends State<BMIHistoryPage> {
105105
.dateTime
106106
.microsecondsSinceEpoch
107107
.toString();
108-
log('delete key -> ' + key);
108+
log('delete key -> $key');
109109
appController.deleteBMI(key: key);
110110
Get.back();
111111
},

lib/pages/glucose/add_glucose.dart

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ class _AddGlucosePageState extends State<AddGlucosePage> {
6767
decoration: InputDecoration(
6868
// filled: true,
6969
// fillColor: Colors.grey.shade200,
70-
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12.0)),
70+
border: OutlineInputBorder(
71+
borderRadius: BorderRadius.circular(12.0)),
7172
hintText: 'Date',
7273
prefixIcon: const Icon(
7374
Icons.calendar_today,
@@ -76,9 +77,17 @@ class _AddGlucosePageState extends State<AddGlucosePage> {
7677
readOnly: true,
7778
onTap: () async {
7879
log("tab");
79-
var dateValue = await showDatePicker(context: context, initialDate: DateTime.now(), firstDate: DateTime.now().subtract(Duration(days: 365)), lastDate: DateTime.now());
80+
var dateValue = await showDatePicker(
81+
context: context,
82+
initialDate: DateTime.now(),
83+
firstDate: DateTime.now()
84+
.subtract(const Duration(days: 365)),
85+
lastDate: DateTime.now());
8086
try {
81-
dateTextController.text = (DateFormat('yyyy-MM-dd').format(dateValue!).toString());
87+
dateTextController.text =
88+
(DateFormat('yyyy-MM-dd')
89+
.format(dateValue!)
90+
.toString());
8291
} catch (e) {
8392
log("no select date");
8493
}
@@ -94,7 +103,8 @@ class _AddGlucosePageState extends State<AddGlucosePage> {
94103
decoration: InputDecoration(
95104
// filled: true,
96105
// fillColor: Colors.grey.shade200,
97-
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12.0)),
106+
border: OutlineInputBorder(
107+
borderRadius: BorderRadius.circular(12.0)),
98108
hintText: 'Time',
99109
prefixIcon: const Icon(
100110
Icons.schedule,
@@ -107,13 +117,16 @@ class _AddGlucosePageState extends State<AddGlucosePage> {
107117
initialTime: TimeOfDay.now(),
108118
builder: (context, child) {
109119
return MediaQuery(
110-
data: MediaQuery.of(context).copyWith(alwaysUse24HourFormat: true),
120+
data: MediaQuery.of(context).copyWith(
121+
alwaysUse24HourFormat: true),
111122
child: child!,
112123
);
113124
},
114125
);
115126
try {
116-
timeTextController.text = timeValue!.format(context);
127+
timeTextController.text =
128+
// ignore: use_build_context_synchronously
129+
timeValue!.format(context);
117130
} catch (e) {
118131
log("no select time");
119132
}
@@ -129,7 +142,8 @@ class _AddGlucosePageState extends State<AddGlucosePage> {
129142
decoration: InputDecoration(
130143
// filled: true,
131144
// fillColor: Colors.grey.shade200,
132-
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12.0)),
145+
border: OutlineInputBorder(
146+
borderRadius: BorderRadius.circular(12.0)),
133147
hintText: 'Gluecose (mg/dL)',
134148
prefixIcon: const Icon(
135149
Icons.icecream_outlined,
@@ -212,13 +226,23 @@ class _AddGlucosePageState extends State<AddGlucosePage> {
212226
child: Text("Save"),
213227
),
214228
onPressed: () {
215-
if (formKey.currentState!.validate() && dateTextController.text.isNotEmpty && timeTextController.text.isNotEmpty) {
216-
final dateTime = DateTime.parse(dateTextController.text + " " + timeTextController.text);
217-
final glucose = int.parse(glucoseTextController.text.trim());
229+
if (formKey.currentState!.validate() &&
230+
dateTextController.text.isNotEmpty &&
231+
timeTextController.text.isNotEmpty) {
232+
final dateTime = DateTime.parse(
233+
"${dateTextController.text} ${timeTextController.text}");
234+
final glucose = int.parse(
235+
glucoseTextController.text.trim());
218236

219-
appController.addGluecose(dateTime: dateTime, glucose: glucose, when: whenData!.floor());
237+
appController.addGluecose(
238+
dateTime: dateTime,
239+
glucose: glucose,
240+
when: whenData!.floor());
220241

221-
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(duration: Duration(milliseconds: 500), content: Text("Saved!")));
242+
ScaffoldMessenger.of(context).showSnackBar(
243+
const SnackBar(
244+
duration: Duration(milliseconds: 500),
245+
content: Text("Saved!")));
222246
Get.back();
223247
}
224248
},

0 commit comments

Comments
 (0)