stack_wallet/lib/widgets/date_picker/date_picker.dart

109 lines
3 KiB
Dart
Raw Normal View History

2024-05-07 22:34:08 +00:00
import 'dart:math';
import 'package:calendar_date_picker2/calendar_date_picker2.dart';
2024-05-07 18:48:59 +00:00
import 'package:flutter/material.dart';
import '../../themes/stack_colors.dart';
import '../../utilities/constants.dart';
import '../../utilities/util.dart';
import '../conditional_parent.dart';
import '../desktop/primary_button.dart';
import '../desktop/secondary_button.dart';
2024-05-07 22:34:08 +00:00
part 'sw_date_picker.dart';
2024-05-07 18:48:59 +00:00
Future<DateTime?> showSWDatePicker(BuildContext context) async {
2024-05-07 22:34:08 +00:00
final Size size;
if (Util.isDesktop) {
size = const Size(450, 450);
} else {
final _size = MediaQuery.of(context).size;
size = Size(
_size.width - 32,
_size.height >= 550 ? 450 : _size.height - 32,
);
}
print("=====================================");
print(size);
2024-05-07 18:48:59 +00:00
2024-05-07 22:34:08 +00:00
final now = DateTime.now();
2024-05-07 18:48:59 +00:00
2024-05-07 22:34:08 +00:00
final date = await _showDatePickerDialog(
context: context,
value: [now],
dialogSize: size,
config: CalendarDatePicker2WithActionButtonsConfig(
firstDate: DateTime(2007),
lastDate: now,
currentDate: now,
buttonPadding: const EdgeInsets.only(
right: 16,
),
centerAlignModePicker: true,
selectedDayHighlightColor:
Theme.of(context).extension<StackColors>()!.accentColorDark,
daySplashColor: Theme.of(context)
.extension<StackColors>()!
.accentColorDark
.withOpacity(0.6),
),
2024-05-07 18:48:59 +00:00
);
2024-05-07 22:34:08 +00:00
return date?.first;
2024-05-07 18:48:59 +00:00
}
2024-05-07 22:34:08 +00:00
Future<List<DateTime?>?> _showDatePickerDialog({
required BuildContext context,
required CalendarDatePicker2WithActionButtonsConfig config,
required Size dialogSize,
List<DateTime?> value = const [],
bool useRootNavigator = true,
bool barrierDismissible = true,
Color? barrierColor = Colors.black54,
bool useSafeArea = true,
RouteSettings? routeSettings,
String? barrierLabel,
TransitionBuilder? builder,
}) {
final dialog = Dialog(
insetPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 16,
2024-05-07 18:48:59 +00:00
),
2024-05-07 22:34:08 +00:00
backgroundColor: Theme.of(context).extension<StackColors>()!.popupBG,
surfaceTintColor: Colors.transparent,
shadowColor: Colors.transparent,
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius * 2,
),
2024-05-07 18:48:59 +00:00
),
2024-05-07 22:34:08 +00:00
clipBehavior: Clip.antiAlias,
child: SizedBox(
width: dialogSize.width,
height: max(dialogSize.height, 410),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_SWDatePicker(
value: value,
config: config.copyWith(openedFromDialog: true),
),
],
),
2024-05-07 18:48:59 +00:00
),
);
2024-05-07 22:34:08 +00:00
return showDialog<List<DateTime?>>(
context: context,
useRootNavigator: useRootNavigator,
routeSettings: routeSettings,
builder: (BuildContext context) {
return builder == null ? dialog : builder(context, dialog);
},
barrierDismissible: barrierDismissible,
barrierColor: barrierColor,
barrierLabel: barrierLabel,
useSafeArea: useSafeArea,
2024-05-07 18:48:59 +00:00
);
}