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/old_lib/views/widgets/date_and_time/date_picker.dart

43 lines
1.2 KiB
Dart

import 'package:flutter/material.dart';
import '../../app_style/sizing.dart';
class ADatePicker extends StatelessWidget {
final DateTime? date;
final DateTime? from;
final DateTime? to;
final Function(DateTime)? onDatePicker;
const ADatePicker({Key? key, this.date, this.onDatePicker, this.from, this.to}) : super(key: key);
@override
Widget build(BuildContext context) {
return ElevatedButton(
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white,
textStyle: Theme.of(context).textTheme.subtitle2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
12 * AppStyle.getScaleFactor(context)
),
),
),
child: Text(
date == null ? "Pick Date" :
date.toString().split(" ").first,
style: Theme.of(context).textTheme.subtitle2,
textScaleFactor: AppStyle.getScaleFactor(context),
),
onPressed: () async {
DateTime? picked = await showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: from ?? DateTime.now(),
lastDate: to ?? DateTime.now().add(Duration(days: 365))
);
onDatePicker!(picked!);
},
);
}
}