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.
cloudsolutions-atoms/lib/views/widgets/date_and_time/date_picker.dart

55 lines
1.9 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 ADatePicker extends StatelessWidget {
final DateTime date;
final DateTime from;
final DateTime to;
final String label;
final Function(DateTime) onDatePicker;
final bool enable;
const ADatePicker({Key key, @required this.label, this.date, this.onDatePicker, this.from, this.to, this.enable = true}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
border: Border.all(width: 1, color: Theme.of(context).scaffoldBackgroundColor),
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),
(date?.toIso8601String() ?? context.translation.pickDate).bodyText(context).custom(color: AppColor.neutral50),
],
).expanded,
16.width,
"calender".toSvgAsset(width: 20),
],
),
).onPress(enable
? () async {
DateTime picked = await showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: from ?? DateTime.now(),
lastDate: to ?? DateTime.now().add(const Duration(days: 365)),
);
onDatePicker(picked);
}
: null);
}
}