Skip to content

Commit

Permalink
refactoring end
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmetOcak committed Feb 12, 2022
1 parent 0b1dfe0 commit 2f1ff06
Show file tree
Hide file tree
Showing 13 changed files with 404 additions and 406 deletions.
50 changes: 50 additions & 0 deletions lib/core/components/alert/alert.dart
@@ -0,0 +1,50 @@
import 'package:flutter/cupertino.dart';
import 'package:my_bmi_calculator/core/components/textwidget/text.dart';
import 'package:my_bmi_calculator/core/constants/app_constants.dart';
import 'package:rflutter_alert/rflutter_alert.dart';

class MyAlert {
final String warning = "Warning";
final String ok = "Ok";

Future<bool?> getAlert(String text, BuildContext context) {
return Alert(
context: context,
title: warning,
desc: text,
buttons: [
DialogButton(
color: accentColor,
child: MyText(
text: ok,
color: mainColor,
fontSize: 25,
fontWeight: FontWeight.w400,
),
onPressed: () {
Navigator.pop(context);
},
),
],
style: const AlertStyle(
alertBorder: RoundedRectangleBorder(
side: BorderSide.none,
borderRadius: BorderRadius.all(
Radius.circular(20),
),
),
backgroundColor: mainColor,
titleStyle: TextStyle(
color: accentColor,
fontSize: 30,
fontWeight: FontWeight.w500,
),
descStyle: TextStyle(
color: accentColor,
fontSize: 25,
fontWeight: FontWeight.w300,
),
),
).show();
}
}
57 changes: 57 additions & 0 deletions lib/core/components/button/calculate_button.dart
@@ -0,0 +1,57 @@
import 'package:flutter/material.dart';
import 'package:my_bmi_calculator/core/components/textwidget/text.dart';
import 'package:my_bmi_calculator/core/constants/app_constants.dart';
import 'package:my_bmi_calculator/home/viewmodel/home_view_model.dart';

class CalculateButton extends StatefulWidget {
const CalculateButton({
Key? key,
required this.heightController,
required this.weightController,
required this.callback,
}) : super(key: key);

final TextEditingController heightController;
final TextEditingController weightController;
final VoidCallback callback;
final String buttonText = "Calculate";

@override
_CalculateButtonState createState() => _CalculateButtonState();
}

class _CalculateButtonState extends State<CalculateButton> {
@override
Widget build(BuildContext context) {
return ClipRRect(
borderRadius: const BorderRadius.all(
Radius.circular(75),
),
child: Container(
width: MediaQuery.of(context).size.width * 0.5,
height: MediaQuery.of(context).size.height * 0.1,
color: accentColor,
child: TextButton(
onPressed: () {
setState(() {
FocusScope.of(context).unfocus();
bool isItChecked = HomeViewModel().nullTextControl(
widget.heightController.text.isEmpty,
widget.weightController.text.isEmpty,
context,
);
if (isItChecked == false) {
widget.callback();
}
});
},
child: MyText(
text: widget.buttonText,
color: mainColor,
fontSize: 25.0,
),
),
),
);
}
}
33 changes: 33 additions & 0 deletions lib/core/components/textfield/textfield.dart
@@ -0,0 +1,33 @@
import 'package:flutter/material.dart';
import 'package:my_bmi_calculator/core/constants/app_constants.dart';

class MyTextField extends StatelessWidget {
const MyTextField({
Key? key,
required this.controller,
}) : super(key: key);

final TextEditingController controller;

@override
Widget build(BuildContext context) {
return TextField(
controller: controller,
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
cursorColor: accentColor,
decoration: const InputDecoration(
border: InputBorder.none,
hintText: '0',
hintStyle: TextStyle(
color: accentColor,
fontSize: 42,
),
),
style: const TextStyle(
color: accentColor,
fontSize: 42,
),
);
}
}
26 changes: 26 additions & 0 deletions lib/core/components/textwidget/text.dart
@@ -0,0 +1,26 @@
import 'package:flutter/material.dart';

class MyText extends StatelessWidget {
const MyText({
Key? key, required this.text, required this.fontSize, required this.color, this.textAlign, this.fontWeight,
}) : super(key: key);

final String text;
final double fontSize;
final Color color;
final TextAlign? textAlign;
final FontWeight? fontWeight;

@override
Widget build(BuildContext context) {
return Text(
text,
style: TextStyle(
color: color,
fontSize: fontSize,
fontWeight: fontWeight,
),
textAlign: textAlign,
);
}
}
File renamed without changes.
14 changes: 5 additions & 9 deletions lib/widgets/bottom_bar.dart → lib/home/model/bottom_bar.dart
@@ -1,12 +1,8 @@
// ignore_for_file: prefer_const_constructors

import 'package:flutter/material.dart';
import 'package:my_bmi_calculator/constants/app_constants.dart';
import 'package:my_bmi_calculator/core/constants/app_constants.dart';

class BottomBar extends StatelessWidget {
const BottomBar({Key? key, required this.barHeight}) : super(key: key);

final double barHeight;
const BottomBar({Key? key, }) : super(key: key);

@override
Widget build(BuildContext context) {
Expand All @@ -17,9 +13,9 @@ class BottomBar extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
width: 20,
height: barHeight,
decoration: BoxDecoration(
width: MediaQuery.of(context).size.width * 0.1,
height: MediaQuery.of(context).size.height * 0.1,
decoration: const BoxDecoration(
color: accentColor,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(25),
Expand Down
@@ -1,29 +1,31 @@
// ignore_for_file: prefer_const_constructors
import 'package:flutter/material.dart';

class GenderContanier extends StatelessWidget {
const GenderContanier({Key? key, required this.gender, required this.contColor}) : super(key: key);
const GenderContanier({
Key? key,
required this.gender,
required this.contColor,
}) : super(key: key);

final String gender;
final Color contColor;

@override
Widget build(BuildContext context) {
return ClipRRect(
borderRadius: BorderRadius.all(
borderRadius: const BorderRadius.all(
Radius.circular(20),
),
child: Center(
child: Container(
child: Image.asset(
'assets/images/$gender.png',
),
width: MediaQuery.of(context).size.width / 2.5,
height: MediaQuery.of(context).size.height / 9.5,
width: MediaQuery.of(context).size.width * 0.4,
height: MediaQuery.of(context).size.height * 0.12,
color: contColor,
),
),
);
}
}

92 changes: 92 additions & 0 deletions lib/home/model/inputs.dart
@@ -0,0 +1,92 @@
import 'package:flutter/material.dart';
import 'package:my_bmi_calculator/core/components/button/calculate_button.dart';
import 'package:my_bmi_calculator/core/components/textfield/textfield.dart';
import 'package:my_bmi_calculator/core/components/textwidget/text.dart';
import 'package:my_bmi_calculator/core/constants/app_constants.dart';
import 'package:my_bmi_calculator/home/viewmodel/home_view_model.dart';

class DataInput extends StatefulWidget {
const DataInput({Key? key}) : super(key: key);

@override
_DataInputState createState() => _DataInputState();
}

class _DataInputState extends State<DataInput> {
final TextEditingController _heightController = TextEditingController();
final TextEditingController _weightController = TextEditingController();
double _bmiResult = 0.0;
static const String heigthText = "Your Height in cm";
static const String weigthText = "Your Weight in kg";

@override
Widget build(BuildContext context) {
return Column(
children: [
const MyText(
text: heigthText,
fontSize: 25,
color: accentColor,
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.01,
),
// HEIGHT INPUT
MyTextField(controller: _heightController),
SizedBox(
height: MediaQuery.of(context).size.height * 0.01,
),
const MyText(
text: weigthText,
fontSize: 25,
color: accentColor,
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.01,
),
// WEIGHT INPUT
MyTextField(
controller: _weightController,
),
CalculateButton(
heightController: _heightController,
weightController: _weightController,
callback: () {
setState(() {
_bmiResult = HomeViewModel().result(
_heightController.text, _weightController.text, context)!;
});
}),
SizedBox(
height: MediaQuery.of(context).size.height * 0.03,
),
MyText(
text: 'Your BMI : ${_bmiResult.toStringAsFixed(2)}',
fontSize: 42,
color: accentColor,
fontWeight: FontWeight.w300,
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.01,
),
SizedBox(
width: MediaQuery.of(context).size.width * 0.5,
child: const Divider(
color: accentColor,
height: 1,
),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.01,
),
MyText(
text: HomeViewModel().controlResult(_bmiResult),
fontSize: 42,
color: accentColor,
textAlign: TextAlign.center,
fontWeight: FontWeight.w300,
),
],
);
}
}

0 comments on commit 2f1ff06

Please sign in to comment.