forked from eatvio/eatvio_app
refactor(diary): Refactoring continues
This commit is contained in:
@@ -51,8 +51,7 @@ class MyProfileScreen extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMyProfileScreen(
|
||||
BuildContext context, MyProfileLoadedState state) {
|
||||
_buildMyProfileScreen(BuildContext context, MyProfileLoadedState state) {
|
||||
mediaQueryData = MediaQuery.of(context);
|
||||
return SafeArea(
|
||||
child: Scaffold(
|
||||
@@ -100,31 +99,35 @@ class MyProfileScreen extends StatelessWidget {
|
||||
ExitButton(
|
||||
text: "exit".tr,
|
||||
margin: EdgeInsets.symmetric(horizontal: 16.h, vertical: 17.v),
|
||||
onTap: () async {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
final response = await http.post(
|
||||
Uri.parse(dotenv.env['SERVER_ROOT']! + '/profile/logout'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 204) {
|
||||
print(response.statusCode);
|
||||
box.delete('token'); // Удаляем токен из Hive
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
AppRoutes.authScreen,
|
||||
);
|
||||
}
|
||||
},
|
||||
onTap: _onTapLogout(context),
|
||||
)
|
||||
]);
|
||||
}
|
||||
|
||||
Function _onTapLogout(BuildContext context) {
|
||||
return () async {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
final response = await http.post(
|
||||
Uri.parse(dotenv.env['SERVER_ROOT']! + '/profile/logout'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 204) {
|
||||
print(response.statusCode);
|
||||
box.delete('token'); // Удаляем токен из Hive
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
AppRoutes.authScreen,
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Section Widget
|
||||
Widget _buildMyBlog(BuildContext context) {
|
||||
_buildMyBlog(BuildContext context) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 7.h),
|
||||
child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
|
||||
@@ -142,7 +145,7 @@ class MyProfileScreen extends StatelessWidget {
|
||||
}
|
||||
|
||||
/// Section Widget
|
||||
Widget _buildSettings(BuildContext context) {
|
||||
_buildSettings(BuildContext context) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 7.h),
|
||||
child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
|
||||
@@ -154,19 +157,23 @@ class MyProfileScreen extends StatelessWidget {
|
||||
Expanded(
|
||||
child: NextStepButton(
|
||||
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(context, AppRoutes.mySettings);
|
||||
},
|
||||
onPressed: onTapSettings(context),
|
||||
text: "my_settings".tr.toUpperCase(),
|
||||
margin: EdgeInsets.only(left: 10.h))),
|
||||
]));
|
||||
}
|
||||
|
||||
Widget _buildBottomBar(BuildContext context) {
|
||||
onTapSettings(BuildContext context) {
|
||||
return () {
|
||||
Navigator.pushNamed(context, AppRoutes.mySettings);
|
||||
};
|
||||
}
|
||||
|
||||
_buildBottomBar(BuildContext context) {
|
||||
return CustomBottomBar(onChanged: (BottomBarEnum type) {});
|
||||
}
|
||||
|
||||
Widget _buildCarousel(BuildContext contex, MyProfileLoadedState state) {
|
||||
_buildCarousel(BuildContext contex, MyProfileLoadedState state) {
|
||||
return CarouselSlider(
|
||||
options: CarouselOptions(height: 340.0),
|
||||
items: [1, 2, 3].map((chartType) {
|
||||
@@ -175,9 +182,7 @@ class MyProfileScreen extends StatelessWidget {
|
||||
switch (chartType) {
|
||||
case 1: // График веса
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
_editWeight(context, state);
|
||||
},
|
||||
onTap: _editWeight(context, state),
|
||||
child: Column(children: [
|
||||
Text(
|
||||
"weight_chart".tr,
|
||||
@@ -220,9 +225,7 @@ class MyProfileScreen extends StatelessWidget {
|
||||
]);
|
||||
case 3: //График обхватов
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
_editCircumference(context, state);
|
||||
},
|
||||
onTap: _editCircumference(context, state),
|
||||
child: Column(children: [
|
||||
Text(
|
||||
"circumferences_chart".tr,
|
||||
@@ -244,7 +247,7 @@ class MyProfileScreen extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildChartLegend() {
|
||||
_buildChartLegend() {
|
||||
final colors = [Colors.pink, Colors.green, Colors.purple];
|
||||
final titles = ["chest".tr, "waist".tr, "hips".tr];
|
||||
final style = TextStyle(
|
||||
@@ -277,7 +280,7 @@ class MyProfileScreen extends StatelessWidget {
|
||||
}
|
||||
|
||||
/// Section Widget
|
||||
Widget _buildChart(
|
||||
_buildChart(
|
||||
BuildContext context, List<double> chartPoints, List<String>? dates) {
|
||||
// Определение осей графика
|
||||
List<FlSpot> spots = [];
|
||||
@@ -340,20 +343,7 @@ class MyProfileScreen extends StatelessWidget {
|
||||
touchTooltipData: LineTouchTooltipData(
|
||||
maxContentWidth: 100,
|
||||
tooltipBgColor: Colors.black,
|
||||
getTooltipItems: (touchedSpots) {
|
||||
return touchedSpots.map((LineBarSpot touchedSpot) {
|
||||
final textStyle = TextStyle(
|
||||
color: touchedSpot.bar.gradient?.colors[0] ??
|
||||
touchedSpot.bar.color,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14,
|
||||
);
|
||||
return LineTooltipItem(
|
||||
'${touchedSpot.x}, ${touchedSpot.y.toStringAsFixed(2)}',
|
||||
textStyle,
|
||||
);
|
||||
}).toList();
|
||||
},
|
||||
getTooltipItems: mapSpots(),
|
||||
),
|
||||
handleBuiltInTouches: true,
|
||||
getTouchLineStart: (data, index) => 0,
|
||||
@@ -410,9 +400,7 @@ class MyProfileScreen extends StatelessWidget {
|
||||
drawVerticalLine: true,
|
||||
horizontalInterval: 1.5,
|
||||
verticalInterval: 5,
|
||||
checkToShowHorizontalLine: (value) {
|
||||
return value.toInt() == 0;
|
||||
},
|
||||
checkToShowHorizontalLine: valuteToInt(),
|
||||
getDrawingHorizontalLine: (_) => FlLine(
|
||||
color: Colors.blue.withOpacity(1),
|
||||
dashArray: [8, 2],
|
||||
@@ -423,9 +411,7 @@ class MyProfileScreen extends StatelessWidget {
|
||||
dashArray: [8, 2],
|
||||
strokeWidth: 0.8,
|
||||
),
|
||||
checkToShowVerticalLine: (value) {
|
||||
return value.toInt() == 0;
|
||||
},
|
||||
checkToShowVerticalLine: valuteToInt(),
|
||||
),
|
||||
borderData: FlBorderData(show: false),
|
||||
),
|
||||
@@ -436,7 +422,29 @@ class MyProfileScreen extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCircumferenceChart(
|
||||
valuteToInt() {
|
||||
return (value) {
|
||||
return value.toInt() == 0;
|
||||
};
|
||||
}
|
||||
|
||||
mapSpots() {
|
||||
return (touchedSpots) {
|
||||
return touchedSpots.map((LineBarSpot touchedSpot) {
|
||||
final textStyle = TextStyle(
|
||||
color: touchedSpot.bar.gradient?.colors[0] ?? touchedSpot.bar.color,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14,
|
||||
);
|
||||
return LineTooltipItem(
|
||||
'${touchedSpot.x}, ${touchedSpot.y.toStringAsFixed(2)}',
|
||||
textStyle,
|
||||
);
|
||||
}).toList();
|
||||
};
|
||||
}
|
||||
|
||||
_buildCircumferenceChart(
|
||||
BuildContext context, chartPoints, List<String>? dates) {
|
||||
// Определение осей графика
|
||||
final chestCircumferences =
|
||||
@@ -526,20 +534,7 @@ class MyProfileScreen extends StatelessWidget {
|
||||
touchTooltipData: LineTouchTooltipData(
|
||||
maxContentWidth: 100,
|
||||
tooltipBgColor: Colors.black,
|
||||
getTooltipItems: (touchedSpots) {
|
||||
return touchedSpots.map((LineBarSpot touchedSpot) {
|
||||
final textStyle = TextStyle(
|
||||
color: touchedSpot.bar.gradient?.colors[0] ??
|
||||
touchedSpot.bar.color,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14,
|
||||
);
|
||||
return LineTooltipItem(
|
||||
'${touchedSpot.x}, ${touchedSpot.y.toStringAsFixed(2)}',
|
||||
textStyle,
|
||||
);
|
||||
}).toList();
|
||||
},
|
||||
getTooltipItems: mapTouchedSpots(),
|
||||
),
|
||||
handleBuiltInTouches: true,
|
||||
getTouchLineStart: (data, index) => 0,
|
||||
@@ -618,9 +613,7 @@ class MyProfileScreen extends StatelessWidget {
|
||||
drawVerticalLine: true,
|
||||
horizontalInterval: 1.5,
|
||||
verticalInterval: 5,
|
||||
checkToShowHorizontalLine: (value) {
|
||||
return value.toInt() == 0;
|
||||
},
|
||||
checkToShowHorizontalLine: valuteToInt(),
|
||||
getDrawingHorizontalLine: (_) => FlLine(
|
||||
color: Colors.blue.withOpacity(1),
|
||||
dashArray: [8, 2],
|
||||
@@ -631,9 +624,7 @@ class MyProfileScreen extends StatelessWidget {
|
||||
dashArray: [8, 2],
|
||||
strokeWidth: 0.8,
|
||||
),
|
||||
checkToShowVerticalLine: (value) {
|
||||
return value.toInt() == 0;
|
||||
},
|
||||
checkToShowVerticalLine: valuteToInt(),
|
||||
),
|
||||
borderData: FlBorderData(show: false),
|
||||
),
|
||||
@@ -644,8 +635,24 @@ class MyProfileScreen extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
mapTouchedSpots() {
|
||||
return (touchedSpots) {
|
||||
return touchedSpots.map((LineBarSpot touchedSpot) {
|
||||
final textStyle = TextStyle(
|
||||
color: touchedSpot.bar.gradient?.colors[0] ?? touchedSpot.bar.color,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14,
|
||||
);
|
||||
return LineTooltipItem(
|
||||
'${touchedSpot.x}, ${touchedSpot.y.toStringAsFixed(2)}',
|
||||
textStyle,
|
||||
);
|
||||
}).toList();
|
||||
};
|
||||
}
|
||||
|
||||
/// Section Widget
|
||||
Widget _buildPlans(BuildContext context, List<dynamic>? plans,
|
||||
_buildPlans(BuildContext context, List<dynamic>? plans,
|
||||
List<dynamic>? imagePaths, List<dynamic>? states) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(left: 7.h),
|
||||
@@ -829,46 +836,7 @@ class MyProfileScreen extends StatelessWidget {
|
||||
child: Text("Отмена", style: theme.textTheme.bodyLarge),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Map<String, dynamic> data = {
|
||||
"chest_circumference":
|
||||
state.chestCircumferenceController?.text,
|
||||
"waist_circumference":
|
||||
state.waistCircumferenceController?.text,
|
||||
"hip_circumference": state.hipCircumferenceController?.text,
|
||||
};
|
||||
|
||||
// Преобразование Map в JSON
|
||||
String jsonData = json.encode(data);
|
||||
|
||||
// Отправка HTTP-запроса
|
||||
try {
|
||||
final token = state.token;
|
||||
final response = await http.post(
|
||||
Uri.parse(dotenv.env['SERVER_ROOT']! +
|
||||
'/profile/addCircumference'),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer $token',
|
||||
},
|
||||
body: jsonData,
|
||||
);
|
||||
|
||||
if (response.statusCode == 201) {
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
AppRoutes.myProfile,
|
||||
);
|
||||
} else {
|
||||
// Ошибка от сервера
|
||||
print(
|
||||
"Ошибка при отправке данных. Код ответа: ${response.statusCode}");
|
||||
}
|
||||
} catch (e) {
|
||||
// Обработка ошибок при отправке запроса
|
||||
print("Ошибка при отправке запроса: $e");
|
||||
}
|
||||
},
|
||||
onPressed: sendEditData(state, context),
|
||||
child: Text("Изменить",
|
||||
style: CustomTextStyles.titleMediumBlack.copyWith(
|
||||
color: Colors.blue,
|
||||
@@ -883,6 +851,46 @@ class MyProfileScreen extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
sendEditData(MyProfileLoadedState state, BuildContext context) {
|
||||
return () async {
|
||||
Map<String, dynamic> data = {
|
||||
"chest_circumference": state.chestCircumferenceController?.text,
|
||||
"waist_circumference": state.waistCircumferenceController?.text,
|
||||
"hip_circumference": state.hipCircumferenceController?.text,
|
||||
};
|
||||
|
||||
// Преобразование Map в JSON
|
||||
String jsonData = json.encode(data);
|
||||
|
||||
// Отправка HTTP-запроса
|
||||
try {
|
||||
final token = state.token;
|
||||
final response = await http.post(
|
||||
Uri.parse(dotenv.env['SERVER_ROOT']! + '/profile/addCircumference'),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer $token',
|
||||
},
|
||||
body: jsonData,
|
||||
);
|
||||
|
||||
if (response.statusCode == 201) {
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
AppRoutes.myProfile,
|
||||
);
|
||||
} else {
|
||||
// Ошибка от сервера
|
||||
print(
|
||||
"Ошибка при отправке данных. Код ответа: ${response.statusCode}");
|
||||
}
|
||||
} catch (e) {
|
||||
// Обработка ошибок при отправке запроса
|
||||
print("Ошибка при отправке запроса: $e");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
_editWeight(BuildContext context, MyProfileLoadedState state) {
|
||||
showDialog(
|
||||
context: context,
|
||||
@@ -913,41 +921,7 @@ class MyProfileScreen extends StatelessWidget {
|
||||
child: Text("Отмена", style: theme.textTheme.bodyLarge),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Map<String, dynamic> data = {
|
||||
"weight": state.weightController!.text,
|
||||
};
|
||||
// Преобразование Map в JSON
|
||||
String jsonData = json.encode(data);
|
||||
|
||||
// Отправка HTTP-запроса
|
||||
try {
|
||||
final token = state.token;
|
||||
final response = await http.post(
|
||||
Uri.parse(
|
||||
dotenv.env['SERVER_ROOT']! + '/profile/addWeight'),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer $token',
|
||||
},
|
||||
body: jsonData,
|
||||
);
|
||||
|
||||
if (response.statusCode == 201) {
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
AppRoutes.myProfile,
|
||||
);
|
||||
} else {
|
||||
// Ошибка от сервера
|
||||
print(
|
||||
"Ошибка при отправке данных. Код ответа: ${response.statusCode}");
|
||||
}
|
||||
} catch (e) {
|
||||
// Обработка ошибок при отправке запроса
|
||||
print("Ошибка при отправке запроса: $e");
|
||||
}
|
||||
},
|
||||
onPressed: addWeight(state, context),
|
||||
child: Text("Изменить",
|
||||
style: CustomTextStyles.titleMediumBlack.copyWith(
|
||||
color: Colors.blue,
|
||||
@@ -961,4 +935,41 @@ class MyProfileScreen extends StatelessWidget {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
addWeight(MyProfileLoadedState state, BuildContext context) {
|
||||
return () async {
|
||||
Map<String, dynamic> data = {
|
||||
"weight": state.weightController!.text,
|
||||
};
|
||||
// Преобразование Map в JSON
|
||||
String jsonData = json.encode(data);
|
||||
|
||||
// Отправка HTTP-запроса
|
||||
try {
|
||||
final token = state.token;
|
||||
final response = await http.post(
|
||||
Uri.parse(dotenv.env['SERVER_ROOT']! + '/profile/addWeight'),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer $token',
|
||||
},
|
||||
body: jsonData,
|
||||
);
|
||||
|
||||
if (response.statusCode == 201) {
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
AppRoutes.myProfile,
|
||||
);
|
||||
} else {
|
||||
// Ошибка от сервера
|
||||
print(
|
||||
"Ошибка при отправке данных. Код ответа: ${response.statusCode}");
|
||||
}
|
||||
} catch (e) {
|
||||
// Обработка ошибок при отправке запроса
|
||||
print("Ошибка при отправке запроса: $e");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ class _ExpandableListState extends State<ExpandableList> {
|
||||
};
|
||||
}
|
||||
|
||||
Widget _buildForm(BuildContext context, MyProfileLoadedState state) {
|
||||
_buildForm(BuildContext context, MyProfileLoadedState state) {
|
||||
List<String> cities = [
|
||||
'Москва',
|
||||
'Санкт-Петербург',
|
||||
|
||||
@@ -89,7 +89,7 @@ class CustomOutlinedButton extends BaseButton {
|
||||
}
|
||||
}
|
||||
|
||||
/*Widget _buildOutlinedButtonWidget() {
|
||||
/*_buildAppBarbuildOutlinedButtonWidget() {
|
||||
return Container(
|
||||
height: this.height ?? 30.v,
|
||||
width: this.width ?? double.maxFinite,
|
||||
|
||||
Reference in New Issue
Block a user