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.
		
		
		
		
		
			
		
			
	
	
		
			116 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			Dart
		
	
		
		
			
		
	
	
			116 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			Dart
		
	
| 
								 
											2 months ago
										 
									 | 
							
								import 'package:flutter/material.dart';
							 | 
						||
| 
								 | 
							
								import 'package:hmg_patient_app_new/core/utils/utils.dart';
							 | 
						||
| 
								 | 
							
								import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								class DatePickerWidget extends StatelessWidget {
							 | 
						||
| 
								 | 
							
								  final String labelText;
							 | 
						||
| 
								 | 
							
								  final String hintText;
							 | 
						||
| 
								 | 
							
								  final String? selectedValue;
							 | 
						||
| 
								 | 
							
								  final Function(String?)? onChange;
							 | 
						||
| 
								 | 
							
								  final Function(bool)? onCalendarTypeChanged;
							 | 
						||
| 
								 | 
							
								  final bool isEnable;
							 | 
						||
| 
								 | 
							
								  final bool isBorderAllowed;
							 | 
						||
| 
								 | 
							
								  final bool isAllowRadius;
							 | 
						||
| 
								 | 
							
								  final EdgeInsetsGeometry? padding;
							 | 
						||
| 
								 | 
							
								  final String lang;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  const DatePickerWidget({
							 | 
						||
| 
								 | 
							
								    Key? key,
							 | 
						||
| 
								 | 
							
								    required this.labelText,
							 | 
						||
| 
								 | 
							
								    required this.hintText,
							 | 
						||
| 
								 | 
							
								    this.selectedValue,
							 | 
						||
| 
								 | 
							
								    this.onChange,
							 | 
						||
| 
								 | 
							
								    this.onCalendarTypeChanged,
							 | 
						||
| 
								 | 
							
								    this.isEnable = true,
							 | 
						||
| 
								 | 
							
								    this.isBorderAllowed = true,
							 | 
						||
| 
								 | 
							
								    this.isAllowRadius = true,
							 | 
						||
| 
								 | 
							
								    this.padding,
							 | 
						||
| 
								 | 
							
								    this.lang = 'en',
							 | 
						||
| 
								 | 
							
								  }) : super(key: key);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  @override
							 | 
						||
| 
								 | 
							
								  Widget build(BuildContext context) {
							 | 
						||
| 
								 | 
							
								    return Container(
							 | 
						||
| 
								 | 
							
								      padding: padding,
							 | 
						||
| 
								 | 
							
								      alignment: Alignment.center,
							 | 
						||
| 
								 | 
							
								      decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
							 | 
						||
| 
								 | 
							
								        color: Colors.white,
							 | 
						||
| 
								 | 
							
								        borderRadius: isAllowRadius ? 15 : null,
							 | 
						||
| 
								 | 
							
								        side: isBorderAllowed ? BorderSide(color: const Color(0xffefefef), width: 1) : null,
							 | 
						||
| 
								 | 
							
								      ),
							 | 
						||
| 
								 | 
							
								      child: Column(
							 | 
						||
| 
								 | 
							
								        mainAxisSize: MainAxisSize.min,
							 | 
						||
| 
								 | 
							
								        crossAxisAlignment: CrossAxisAlignment.start,
							 | 
						||
| 
								 | 
							
								        children: [
							 | 
						||
| 
								 | 
							
								          _buildLabelText(),
							 | 
						||
| 
								 | 
							
								          _buildDatePicker(context),
							 | 
						||
| 
								 | 
							
								        ],
							 | 
						||
| 
								 | 
							
								      ),
							 | 
						||
| 
								 | 
							
								    );
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  Widget _buildLabelText() {
							 | 
						||
| 
								 | 
							
								    return Text(
							 | 
						||
| 
								 | 
							
								      labelText,
							 | 
						||
| 
								 | 
							
								      style: const TextStyle(
							 | 
						||
| 
								 | 
							
								        fontSize: 12,
							 | 
						||
| 
								 | 
							
								        fontWeight: FontWeight.w500,
							 | 
						||
| 
								 | 
							
								        color: Color(0xff898A8D),
							 | 
						||
| 
								 | 
							
								        letterSpacing: -0.2,
							 | 
						||
| 
								 | 
							
								        height: 18 / 12,
							 | 
						||
| 
								 | 
							
								      ),
							 | 
						||
| 
								 | 
							
								    );
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  Widget _buildDatePicker(BuildContext context) {
							 | 
						||
| 
								 | 
							
								    return GestureDetector(
							 | 
						||
| 
								 | 
							
								      onTap: isEnable
							 | 
						||
| 
								 | 
							
								          ? () async {
							 | 
						||
| 
								 | 
							
								              // bool isGregorian = true;
							 | 
						||
| 
								 | 
							
								              // final picked = await showHijriGregBottomSheet(
							 | 
						||
| 
								 | 
							
								              //   context,
							 | 
						||
| 
								 | 
							
								              //   switcherIcon: Utils.buildSvgWithAssets(icon: "assets/images/svg/language.svg")
							 | 
						||
| 
								 | 
							
								              //   language: lang,
							 | 
						||
| 
								 | 
							
								              //   fontFamily: "poppins",
							 | 
						||
| 
								 | 
							
								              //   initialShowGregorian: true,
							 | 
						||
| 
								 | 
							
								              //   initialDate: DateTime.now(),
							 | 
						||
| 
								 | 
							
								              //   okWidget: Padding(padding: const EdgeInsets.only(right: 8.0), child: Utils.buildSvgWithAssets(icon: "assets/images/svg/confirm.svg")),
							 | 
						||
| 
								 | 
							
								              //   cancelWidget: Padding(padding: const EdgeInsets.only(right: 8.0), child: Utils.buildSvgWithAssets(icon: "assets/images/svg/cancel.svg", iconColor: Colors.white)),
							 | 
						||
| 
								 | 
							
								              //   onCalendarTypeChanged: (bool value) {
							 | 
						||
| 
								 | 
							
								              //     isGregorian = value;
							 | 
						||
| 
								 | 
							
								              //   },
							 | 
						||
| 
								 | 
							
								              // );
							 | 
						||
| 
								 | 
							
								              //
							 | 
						||
| 
								 | 
							
								              // if (picked != null && onChange != null) {
							 | 
						||
| 
								 | 
							
								              //   if (onCalendarTypeChanged != null) {
							 | 
						||
| 
								 | 
							
								              //     onCalendarTypeChanged!.call(isGregorian);
							 | 
						||
| 
								 | 
							
								              //   }
							 | 
						||
| 
								 | 
							
								              //   onChange!(picked.toIso8601String());
							 | 
						||
| 
								 | 
							
								              // }
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								          : null,
							 | 
						||
| 
								 | 
							
								      child: Row(
							 | 
						||
| 
								 | 
							
								        mainAxisAlignment: MainAxisAlignment.spaceBetween,
							 | 
						||
| 
								 | 
							
								        crossAxisAlignment: CrossAxisAlignment.center,
							 | 
						||
| 
								 | 
							
								        children: [
							 | 
						||
| 
								 | 
							
								          Expanded(
							 | 
						||
| 
								 | 
							
								            child: Text(
							 | 
						||
| 
								 | 
							
								              (selectedValue == null || selectedValue!.isEmpty) ? hintText : selectedValue!,
							 | 
						||
| 
								 | 
							
								              textAlign: TextAlign.left,
							 | 
						||
| 
								 | 
							
								              textDirection: TextDirection.ltr,
							 | 
						||
| 
								 | 
							
								              style: TextStyle(
							 | 
						||
| 
								 | 
							
								                fontSize: 14,
							 | 
						||
| 
								 | 
							
								                height: 21 / 14,
							 | 
						||
| 
								 | 
							
								                fontWeight: FontWeight.w500,
							 | 
						||
| 
								 | 
							
								                color: (selectedValue != null && selectedValue!.isNotEmpty) ? const Color(0xff2E3039) : const Color(0xffB0B0B0),
							 | 
						||
| 
								 | 
							
								                letterSpacing: -0.2,
							 | 
						||
| 
								 | 
							
								              ),
							 | 
						||
| 
								 | 
							
								            ),
							 | 
						||
| 
								 | 
							
								          ),
							 | 
						||
| 
								 | 
							
								          const Icon(Icons.keyboard_arrow_down_outlined),
							 | 
						||
| 
								 | 
							
								        ],
							 | 
						||
| 
								 | 
							
								      ),
							 | 
						||
| 
								 | 
							
								    );
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								}
							 |