mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-08 23:18:16 -07:00
Init repo
This commit is contained in:
commit
764b6034e3
566 changed files with 212335 additions and 0 deletions
57
lib/widgets/shared/adaptive_date_picker.dart
Normal file
57
lib/widgets/shared/adaptive_date_picker.dart
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
Future<DateTime?> showAdaptiveDatePicker(
|
||||
BuildContext context, {
|
||||
DateTime? initialDateTime,
|
||||
}) async {
|
||||
final ThemeData theme = Theme.of(context);
|
||||
if (theme.platform == TargetPlatform.iOS) {
|
||||
return _buildCupertinoDatePicker(
|
||||
context,
|
||||
initialDateTime: initialDateTime,
|
||||
);
|
||||
} else {
|
||||
return _buildMaterialDatePicker(
|
||||
context,
|
||||
initialDateTime: initialDateTime,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<DateTime?> _buildCupertinoDatePicker(
|
||||
BuildContext context, {
|
||||
DateTime? initialDateTime,
|
||||
}) async {
|
||||
DateTime? newDate;
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (BuildContext builder) {
|
||||
return Container(
|
||||
height: MediaQuery.of(context).copyWith().size.height / 3,
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
child: CupertinoDatePicker(
|
||||
onDateTimeChanged: (value) {
|
||||
newDate = value;
|
||||
},
|
||||
initialDateTime: initialDateTime,
|
||||
dateOrder: DatePickerDateOrder.ymd,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
return newDate;
|
||||
}
|
||||
|
||||
Future<DateTime?> _buildMaterialDatePicker(
|
||||
BuildContext context, {
|
||||
DateTime? initialDateTime,
|
||||
}) async {
|
||||
final DateTime? picked = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: initialDateTime ?? DateTime.now(),
|
||||
firstDate: DateTime(2000),
|
||||
lastDate: DateTime(2025),
|
||||
);
|
||||
return picked;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue