onufitness_mobile/lib/screens/rise/widgets/input_challenge_performance.dart
2026-01-13 11:36:24 +05:30

285 lines
11 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:onufitness/constants/color_constant.dart';
import 'package:onufitness/constants/text_constant.dart';
import 'package:onufitness/screens/rise/controllers/rise_controller.dart';
import 'package:onufitness/screens/rise/models/get_challenges_response_model.dart';
import 'package:onufitness/utils/custom_sneakbar.dart';
import 'package:onufitness/widgets/Buttons/custom_submit_button.dart';
class ChallengePerformanceInputBottomSheet extends StatefulWidget {
final List<ChallengeTask> challengeTask;
const ChallengePerformanceInputBottomSheet({
super.key,
required this.challengeTask,
});
@override
State<ChallengePerformanceInputBottomSheet> createState() =>
ChallengePerformanceInputBottomSheetState();
}
class ChallengePerformanceInputBottomSheetState
extends State<ChallengePerformanceInputBottomSheet> {
final _formKey = GlobalKey<FormState>();
final RiseController controller = Get.find<RiseController>();
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.vertical(top: Radius.circular(20.r)),
),
child: Padding(
padding: EdgeInsets.all(20.w),
child: Form(
key: _formKey,
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Center(
child: Container(
height: 4.h,
width: 40.w,
decoration: BoxDecoration(
color: Color(darkGreyColor),
borderRadius: BorderRadius.circular(2.r),
),
),
),
SizedBox(height: 20.h),
Text(
'Input Your Performance',
style: TextStyle(
fontSize: largeSizeText,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
SizedBox(height: 24.h),
GestureDetector(
onTap: () => controller.selectDate(context),
child: Container(
width: double.infinity,
padding: EdgeInsets.symmetric(
horizontal: 16.w,
vertical: 16.h,
),
decoration: BoxDecoration(
color: textFieldFillColor,
borderRadius: BorderRadius.circular(12.r),
border: Border.all(
color:
controller.selectedDate.value == null
? Colors.red.withValues(alpha: 0.3)
: lightGreyColor,
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Obx(
() => Text(
controller.showSelectedDateToUI.value.isEmpty
? 'Select Date'
: controller.showSelectedDateToUI.value,
style: TextStyle(
fontSize: regularSizeText,
color:
controller.showSelectedDateToUI.value.isEmpty
? Color(darkGreyColor)
: Colors.black,
),
),
),
Icon(
Icons.calendar_today,
color: Color(darkGreyColor),
size: 20.sp,
),
],
),
),
),
SizedBox(height: 12.h),
Container(
width: double.infinity,
decoration: BoxDecoration(
color: textFieldFillColor,
borderRadius: BorderRadius.circular(12.r),
border: Border.all(color: lightGreyColor),
),
child: TextFormField(
controller: TextEditingController(
text: widget.challengeTask[0].taskTitle,
),
readOnly: true,
style: TextStyle(
fontSize: regularSizeText,
color: Colors.black,
),
decoration: InputDecoration(
hintText: 'Metric',
hintStyle: TextStyle(
color: Color(darkGreyColor),
fontSize: regularSizeText,
),
border: InputBorder.none,
contentPadding: EdgeInsets.symmetric(
horizontal: 16.w,
vertical: 16.h,
),
),
),
),
SizedBox(height: 12.h),
Container(
width: double.infinity,
decoration: BoxDecoration(
color: textFieldFillColor,
borderRadius: BorderRadius.circular(12.r),
border: Border.all(color: lightGreyColor),
),
child: TextFormField(
controller: TextEditingController(
text: widget.challengeTask[0].taskUnit,
),
readOnly: true,
style: TextStyle(
fontSize: regularSizeText,
color: Colors.black,
),
decoration: InputDecoration(
hintText: 'Unit',
hintStyle: TextStyle(
color: Color(darkGreyColor),
fontSize: regularSizeText,
),
border: InputBorder.none,
contentPadding: EdgeInsets.symmetric(
horizontal: 16.w,
vertical: 16.h,
),
),
),
),
SizedBox(height: 12.h),
Container(
width: double.infinity,
decoration: BoxDecoration(
color: textFieldFillColor,
borderRadius: BorderRadius.circular(12.r),
border: Border.all(color: lightGreyColor),
),
child: TextFormField(
controller: controller.inputValueController,
keyboardType: TextInputType.numberWithOptions(
decimal: true,
),
style: TextStyle(
fontSize: regularSizeText,
color: Colors.black,
),
decoration: InputDecoration(
hintText: 'Enter value',
hintStyle: TextStyle(
color: Color(darkGreyColor),
fontSize: regularSizeText,
),
border: InputBorder.none,
contentPadding: EdgeInsets.symmetric(
horizontal: 16.w,
vertical: 16.h,
),
),
validator: (value) {
if (value == null || value.trim().isEmpty) {
return 'Please enter a value';
}
final numValue = double.tryParse(value.trim());
if (numValue == null || numValue <= 0) {
return 'Please enter a valid positive number';
}
return null;
},
),
),
SizedBox(height: 32.h),
Obx(
() => CustomSubmitButton(
isLoading: controller.isChallengeInputLoading.value,
text: "Submit",
onPressed: () async {
if (!_formKey.currentState!.validate()) {
return;
}
final input = controller.inputValueController.text.trim();
if (input.isEmpty) {
customSnackbar(
title: "Empty Field!",
message: "Please enter a value before submitting.",
color: Colors.red,
duration: 1,
);
return;
}
if (controller.selectedDate.value == null) {
customSnackbar(
title: "Date Not Selected!",
message: "Please select a date before submitting.",
color: Colors.red,
duration: 1,
);
return;
}
final success = await controller
.inputChallengeTaskTracking(
challengeID: widget.challengeTask[0].challengeId!,
challengeTaskID:
widget.challengeTask[0].challengeTaskId!,
metricValue: input,
);
if (success) {
await Future.delayed(
const Duration(milliseconds: 600),
() {
Get.back();
controller.fetchChallengeParticipants(
challengeId: widget.challengeTask[0].challengeId!,
isRefresh: true,
);
},
);
}
},
),
),
Container(
padding: EdgeInsetsDirectional.only(
bottom: MediaQuery.of(context).viewPadding.bottom,
),
color: Colors.white,
),
],
),
),
),
),
);
}
}