getPresentationWidgetsCommonDatePickerTemplate function
String
getPresentationWidgetsCommonDatePickerTemplate(
- String projectName
)
Implementation
String getPresentationWidgetsCommonDatePickerTemplate(String projectName) {
return '''
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
class CommonDatePicker {
/// Returns formatted date (dd/MM/yyyy)
static Future<String?> pickBirthDate(BuildContext context) async {
final DateTime today = DateTime.now();
/// Minimum age = 18
final DateTime lastDate = DateTime(today.year - 18, today.month, today.day);
/// Maximum age = 100
final DateTime firstDate = DateTime(
today.year - 100,
today.month,
today.day,
);
final DateTime? pickedDate = await showDatePicker(
context: context,
initialDate: lastDate,
firstDate: firstDate,
lastDate: lastDate,
builder: (context, child) {
return Theme(
data: Theme.of(context).copyWith(
colorScheme: const ColorScheme.light(
primary: Colors.black,
onPrimary: Colors.white,
onSurface: Colors.black,
),
),
child: child!,
);
},
);
if (pickedDate != null) {
/// Format date dd/MM/yyyy
return DateFormat('dd/MM/yyyy').format(pickedDate);
}
return null;
}
/// Optional method if you need raw DateTime
static Future<DateTime?> pickBirthDateRaw(BuildContext context) async {
final DateTime today = DateTime.now();
final DateTime lastDate = DateTime(today.year - 18, today.month, today.day);
final DateTime firstDate = DateTime(
today.year - 100,
today.month,
today.day,
);
return await showDatePicker(
context: context,
initialDate: lastDate,
firstDate: firstDate,
lastDate: lastDate,
);
}
}
''';
}