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.
79 lines
2.7 KiB
Dart
79 lines
2.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:test_sa/extensions/context_extension.dart';
|
|
import 'package:test_sa/extensions/int_extensions.dart';
|
|
import 'package:test_sa/extensions/text_extensions.dart';
|
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
|
import 'package:test_sa/new_views/app_style/app_color.dart';
|
|
|
|
class ATimePicker extends StatelessWidget {
|
|
final TimeOfDay? time; // Nullable
|
|
final String label;
|
|
final String? hint; // Nullable
|
|
final Function(TimeOfDay)? onTimePicker; // Nullable
|
|
final bool enable;
|
|
final bool withBorder;
|
|
final Color? backgroundColor; // Nullable
|
|
final double? height; // Nullable
|
|
|
|
const ATimePicker({
|
|
Key? key,
|
|
required this.label,
|
|
this.withBorder = true,
|
|
this.height,
|
|
this.backgroundColor,
|
|
this.hint,
|
|
this.time,
|
|
this.onTimePicker,
|
|
this.enable = true,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
height: height,
|
|
decoration: BoxDecoration(
|
|
color: backgroundColor ??
|
|
(context.isDark && !enable
|
|
? AppColor.neutral50
|
|
: !enable
|
|
? AppColor.neutral40
|
|
: AppColor.background(context)),
|
|
borderRadius: BorderRadius.circular(10),
|
|
border: withBorder ? Border.all(width: 1, color: Theme.of(context).scaffoldBackgroundColor) : const Border(),
|
|
boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.05), blurRadius: 10)],
|
|
),
|
|
padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth, vertical: 8.toScreenHeight),
|
|
child: Row(
|
|
children: [
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
label.tinyFont(context),
|
|
(time == null
|
|
? hint ?? context.translation.pickTime
|
|
: (time!.format(context) ?? // Use null assertion operator
|
|
context.translation.pickADate))
|
|
.bodyText(context)
|
|
.custom(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50),
|
|
],
|
|
).expanded,
|
|
enable ? 16.width : const Spacer(),
|
|
"calender".toSvgAsset(width: 20, color: context.isDark ? AppColor.neutral10 : null),
|
|
],
|
|
),
|
|
).onPress(enable
|
|
? () async {
|
|
final TimeOfDay? pickedTime = await showTimePicker(
|
|
// Nullable TimeOfDay
|
|
context: context,
|
|
initialTime: TimeOfDay.now(),
|
|
);
|
|
if (pickedTime != null && onTimePicker != null) {
|
|
onTimePicker!(pickedTime); // Use null-aware operator
|
|
}
|
|
}
|
|
: null);
|
|
}
|
|
}
|