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

36 lines
1.2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:test_sa/views/app_style/sizing.dart';
class ADatePicker extends StatelessWidget {
final DateTime date;
final DateTime from;
final DateTime to;
final Function(DateTime) onDatePicker;
final bool enable;
const ADatePicker({Key key, this.date, this.onDatePicker, this.from, this.to, this.enable = true}) : 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)),
),
),
onPressed: enable
? () async {
DateTime picked = await showDatePicker(context: context, initialDate: DateTime.now(), firstDate: from ?? DateTime.now(), lastDate: to ?? DateTime.now().add(Duration(days: 365)));
onDatePicker(picked);
}
: null,
child: Text(
date == null ? "Pick Date" : date.toString().split(" ").first,
textScaleFactor: AppStyle.getScaleFactor(context),
),
);
}
}