You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HMG_Patient_App_New/lib/presentation/weather/weather_details_page.dart

186 lines
6.4 KiB
Dart

import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/core/app_export.dart';
import 'package:hmg_patient_app_new/core/app_state.dart';
import 'package:hmg_patient_app_new/core/dependencies.dart';
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
import 'package:hmg_patient_app_new/features/weather/models/waether_cities_model.dart';
import 'package:hmg_patient_app_new/features/weather/weather_view_model.dart';
import 'package:hmg_patient_app_new/generated/locale_keys.g.dart';
import 'package:hmg_patient_app_new/presentation/hmg_services/widgets/weather_widget.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';
import 'package:hmg_patient_app_new/widgets/appbar/collapsing_list_view.dart';
import 'package:provider/provider.dart';
class WeatherDetailsPage extends StatelessWidget {
const WeatherDetailsPage({super.key});
Color _getColorFromColorName(ColorName? colorName) {
if (colorName == null) return AppColors.successColor;
switch (colorName) {
case ColorName.GREEN:
return AppColors.successColor;
case ColorName.ORANGE:
return AppColors.warningColor;
case ColorName.RED:
return AppColors.errorColor;
}
}
Color _getBackgroundColorFromColorName(ColorName? colorName) {
if (colorName == null) return AppColors.successLightColor.withValues(alpha: 0.1);
switch (colorName) {
case ColorName.GREEN:
return AppColors.successLightColor.withValues(alpha: 0.1);
case ColorName.ORANGE:
return AppColors.warningLightColor.withValues(alpha: 0.1);
case ColorName.RED:
return AppColors.errorLightColor.withValues(alpha: 0.1);
}
}
IconData _getIconFromCategory(String? category) {
if (category == null) return Icons.wb_sunny_outlined;
final lowerCategory = category.toLowerCase();
if (lowerCategory.contains('walking') || lowerCategory.contains('activity')) {
return Icons.directions_walk;
} else if (lowerCategory.contains('weather') || lowerCategory.contains('temperature')) {
return Icons.thermostat_outlined;
} else if (lowerCategory.contains('elderly') || lowerCategory.contains('hiking')) {
return Icons.elderly;
}
return Icons.wb_sunny_outlined;
}
@override
Widget build(BuildContext context) {
return Consumer<WeatherMonitorViewModel>(
builder: (context, weatherVM, child) {
return Scaffold(
backgroundColor: AppColors.bgScaffoldColor,
body: CollapsingListView(
title: LocaleKeys.healthWeatherIndicators.tr(),
isLeading: true,
child: weatherVM.isLoading
? Center(
child: CircularProgressIndicator(
color: AppColors.primaryRedColor,
),
)
: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Reuse WeatherWidget at the top (without the button)
const WeatherWidget(showButton: false),
SizedBox(height: 16.h),
// Categories List (Sliders)
...weatherVM.cityInfoList.map((cityInfo) {
return _buildCategoryCard(
description: cityInfo.name ?? '',
categoryLabel: cityInfo.category ?? '',
color: _getColorFromColorName(cityInfo.colorName),
backgroundColor: _getBackgroundColorFromColorName(cityInfo.colorName),
icon: _getIconFromCategory(cityInfo.category),
);
}),
SizedBox(height: 24.h),
],
),
),
);
},
);
}
Widget _buildCategoryCard({
required String description,
required String categoryLabel,
required Color color,
required Color backgroundColor,
required IconData icon,
}) {
return Container(
margin: EdgeInsets.only(bottom: 16.h),
padding: EdgeInsets.all(16.w),
decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
color: AppColors.whiteColor,
borderRadius: 16.r,
hasShadow: false,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Icon
Container(
width: 40.w,
height: 40.w,
decoration: BoxDecoration(
color: backgroundColor,
borderRadius: BorderRadius.circular(8.r),
),
child: Icon(
icon,
color: color,
size: 24.w,
),
),
SizedBox(width: 12.w),
// Content
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
description.toText14(
isBold: true,
color: AppColors.textColor,
),
SizedBox(height: 8.h),
// Progress bar
Container(
height: 4.h,
decoration: BoxDecoration(
color: AppColors.lightGrayBGColor,
borderRadius: BorderRadius.circular(2.r),
),
child: FractionallySizedBox(
alignment: Alignment.centerLeft,
widthFactor: 0.7,
child: Container(
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(2.r),
),
),
),
),
],
),
),
SizedBox(width: 12.w),
// Category Label
Container(
padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 6.h),
decoration: BoxDecoration(
color: backgroundColor,
borderRadius: BorderRadius.circular(8.r),
),
child: categoryLabel.toText12(
color: color,
fontWeight: FontWeight.w600,
maxLine: 1
),
),
],
),
).paddingSymmetrical(24.w, 0.w);
}
}