diff --git a/example/lib/main.dart b/example/lib/main.dart index 48c545b..2fd3400 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -79,7 +79,23 @@ class _SampleDatePickerState extends State { fontWeight: FontWeight.w500, color: Colors.black, fontSize: 16), - ) + ), + const SizedBox(height: 16), + WrapTextButton('Show date picker single view', + height: 50, + backgroundColor: Colors.blue, + padding: + const EdgeInsets.symmetric(horizontal: 16, vertical: 10), + textStyle: const TextStyle( + fontWeight: FontWeight.w500, + color: Colors.white, + fontSize: 16), + onTap: () { + MaterialDateRangePickerDialog.showDatePicker( + context, + selectDateActionCallback: (date) {} + ); + }), ]), ), ); diff --git a/lib/material_date_range_picker_dialog.dart b/lib/material_date_range_picker_dialog.dart index 172a234..24f55bb 100644 --- a/lib/material_date_range_picker_dialog.dart +++ b/lib/material_date_range_picker_dialog.dart @@ -25,43 +25,45 @@ class MaterialDateRangePickerDialog { SelectDateRangeActionCallback? selectDateRangeActionCallback } ) { - showModalBottomSheet( + showGeneralDialog( context: context, - isScrollControlled: true, barrierColor: Colors.black26, - backgroundColor: Colors.transparent, - enableDrag: false, - constraints: ResponsiveUtils.isLandscapeMobile(context) - ? const BoxConstraints(maxWidth: 450) - : null, - shape: RoundedRectangleBorder( - borderRadius: ResponsiveUtils.isMobile(context) - ? BorderRadius.only( - topLeft: Radius.circular(radius ?? 16.0), - topRight: Radius.circular(radius ?? 16.0) - ) - : BorderRadius.all(Radius.circular(radius ?? 16.0)) - ), - builder: (context) { - return PointerInterceptor(child: Padding( - padding: MediaQuery.of(context).viewInsets, - child: MultipleViewDateRangePicker( - confirmText: confirmText, - cancelText: cancelText, - startDateTitle: startDateTitle, - endDateTitle: endDateTitle, - last7daysTitle: last7daysTitle, - last30daysTitle: last30daysTitle, - last6monthsTitle: last6monthsTitle, - lastYearTitle: lastYearTitle, - startDate: initStartDate, - endDate: initEndDate, - radius: radius, - autoClose: autoClose, - selectDateRangeActionCallback: selectDateRangeActionCallback + useRootNavigator: false, + pageBuilder: (context, _, __) { + return Container( + alignment: ResponsiveUtils.isMobile(context) + ? Alignment.bottomCenter + : Alignment.center, + constraints: ResponsiveUtils.isLandscapeMobile(context) + ? const BoxConstraints(maxWidth: 450) + : const BoxConstraints(), + child: Material( + borderRadius: ResponsiveUtils.isMobile(context) + ? BorderRadius.only( + topLeft: Radius.circular(radius ?? 16.0), + topRight: Radius.circular(radius ?? 16.0)) + : BorderRadius.all(Radius.circular(radius ?? 16.0)), + child: PointerInterceptor(child: Padding( + padding: MediaQuery.of(context).viewInsets, + child: MultipleViewDateRangePicker( + confirmText: confirmText, + cancelText: cancelText, + startDateTitle: startDateTitle, + endDateTitle: endDateTitle, + last7daysTitle: last7daysTitle, + last30daysTitle: last30daysTitle, + last6monthsTitle: last6monthsTitle, + lastYearTitle: lastYearTitle, + startDate: initStartDate, + endDate: initEndDate, + radius: radius, + autoClose: autoClose, + selectDateRangeActionCallback: selectDateRangeActionCallback + ), + )), ), - )); - } + ); + }, ); } @@ -75,35 +77,49 @@ class MaterialDateRangePickerDialog { SelectDateActionCallback? selectDateActionCallback } ) { - showModalBottomSheet( + showGeneralDialog( context: context, - isScrollControlled: true, barrierColor: Colors.black26, - backgroundColor: Colors.transparent, - enableDrag: false, - constraints: ResponsiveUtils.isLandscapeMobile(context) - ? const BoxConstraints(maxWidth: 450) - : null, - shape: RoundedRectangleBorder( - borderRadius: ResponsiveUtils.isMobile(context) - ? BorderRadius.only( - topLeft: Radius.circular(radius ?? 16.0), - topRight: Radius.circular(radius ?? 16.0) - ) - : BorderRadius.all(Radius.circular(radius ?? 16.0)) - ), - builder: (context) { - return PointerInterceptor(child: Padding( - padding: MediaQuery.of(context).viewInsets, - child: SingleViewDatePicker( - title: title, - radius: radius, - autoClose: autoClose, - currentDate: currentDate, - selectDateActionCallback: selectDateActionCallback + useRootNavigator: false, + pageBuilder: (context, animation, _) { + return AnimatedBuilder( + animation: animation, + child: Container( + alignment: ResponsiveUtils.isMobile(context) + ? Alignment.bottomCenter + : Alignment.center, + constraints: ResponsiveUtils.isLandscapeMobile(context) + ? const BoxConstraints(maxWidth: 450) + : null, + child: Material( + borderRadius: ResponsiveUtils.isMobile(context) + ? BorderRadius.only( + topLeft: Radius.circular(radius ?? 16.0), + topRight: Radius.circular(radius ?? 16.0)) + : BorderRadius.all(Radius.circular(radius ?? 16.0)), + type: MaterialType.transparency, + child: PointerInterceptor(child: Padding( + padding: MediaQuery.viewInsetsOf(context), + child: SingleViewDatePicker( + title: title, + radius: radius, + autoClose: autoClose, + currentDate: currentDate, + selectDateActionCallback: selectDateActionCallback + ), + )), + ), ), - )); - } + builder: (BuildContext context, Widget? child) { + return SlideTransition( + position: Tween( + begin: const Offset(0, 1), + end: Offset.zero) + .animate(animation), + child: child); + }, + ); + }, ); } } \ No newline at end of file