283 lines
12 KiB
Dart
283 lines
12 KiB
Dart
import 'package:ef/ef.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:vbvs_app/common/color/appConstants.dart';
|
|
import 'package:vbvs_app/common/util/FitTool.dart';
|
|
import 'package:vbvs_app/common/util/MyUtils.dart';
|
|
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
|
|
|
|
Future showDateSelectionDialog(BuildContext context,
|
|
{required DateTime checkDate, Function? checkChange, String title = "生日"}) {
|
|
ThemeController themeController = Get.find();
|
|
List years = [], months = [], days = [];
|
|
var days_select = [].obs;
|
|
int day_len = 31;
|
|
int year = DateTime.now().year;
|
|
for (var i = 0; i < 100; i++) {
|
|
years.insert(0, year - i);
|
|
}
|
|
for (var i = 1; i < 13; i++) {
|
|
months.add(i);
|
|
}
|
|
for (var i = 1; i < 32; i++) {
|
|
days.add(i);
|
|
}
|
|
int yearIndex = years.lastIndexOf(checkDate.year);
|
|
int monthIndex = months.lastIndexOf(checkDate.month);
|
|
day_len = DateTime.fromMillisecondsSinceEpoch(
|
|
DateTime(years[yearIndex], months[monthIndex] + 1)
|
|
.millisecondsSinceEpoch -
|
|
1000)
|
|
.day;
|
|
days_select.value = days.sublist(0, day_len);
|
|
int dayIndex = days.lastIndexOf(checkDate.day);
|
|
return showDialog(
|
|
context: context,
|
|
barrierDismissible: true, // 点击对话框外部可关闭
|
|
builder: (BuildContext context) {
|
|
return Stack(
|
|
children: [
|
|
Positioned(
|
|
bottom: 0, // 控制弹窗距离顶部的位置
|
|
left: 0,
|
|
right: 0,
|
|
child: Material(
|
|
color: Colors.transparent,
|
|
child: Dialog(
|
|
backgroundColor: themeController.currentColor.sc17,
|
|
insetPadding: EdgeInsets.zero,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(0),
|
|
),
|
|
child: Container(
|
|
width: double.infinity,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.only(
|
|
topLeft: Radius.circular(
|
|
AppConstants().normal_container_radius),
|
|
topRight: Radius.circular(
|
|
AppConstants().normal_container_radius),
|
|
bottomLeft: Radius.circular(0.rpx),
|
|
bottomRight: Radius.circular(0.rpx),
|
|
),
|
|
),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: <Widget>[
|
|
Container(
|
|
color: themeController.currentColor.sc5,
|
|
alignment: Alignment.centerLeft,
|
|
height: 80.rpx,
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
InkWell(
|
|
child: Text(
|
|
"日期.取消".tr,
|
|
style: FlutterFlowTheme.of(context)
|
|
.bodyMedium
|
|
.override(
|
|
fontFamily: 'Readex Pro',
|
|
color: themeController.currentColor.sc3,
|
|
letterSpacing: 0,
|
|
fontSize: AppConstants()
|
|
.normal_text_fontSize),
|
|
),
|
|
onTap: () {
|
|
Get.back();
|
|
},
|
|
),
|
|
Text(
|
|
"$title",
|
|
style: FlutterFlowTheme.of(context)
|
|
.bodyMedium
|
|
.override(
|
|
fontFamily: 'Readex Pro',
|
|
color: themeController.currentColor.sc3,
|
|
letterSpacing: 0,
|
|
fontSize:
|
|
AppConstants().title_text_fontSize),
|
|
),
|
|
// closeIconWhite,
|
|
InkWell(
|
|
child: Text(
|
|
"日期.确定".tr,
|
|
style: FlutterFlowTheme.of(context)
|
|
.bodyMedium
|
|
.override(
|
|
fontFamily: 'Readex Pro',
|
|
color: themeController.currentColor.sc3,
|
|
letterSpacing: 0,
|
|
fontSize: AppConstants()
|
|
.normal_text_fontSize),
|
|
),
|
|
onTap: () {
|
|
checkChange?.call(DateTime(years[yearIndex],
|
|
months[monthIndex], days[dayIndex]));
|
|
Get.back();
|
|
},
|
|
)
|
|
],
|
|
),
|
|
),
|
|
Container(
|
|
height: 240.rpx,
|
|
margin: EdgeInsets.only(top: 60.rpx, bottom: 60.rpx),
|
|
padding: EdgeInsets.only(left: 30.rpx, right: 30.rpx),
|
|
child: Container(
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Container(
|
|
padding: EdgeInsets.only(
|
|
left: 40.rpx, right: 30.rpx),
|
|
child: getOnePicker(context, years, yearIndex,
|
|
(d) {
|
|
yearIndex = d;
|
|
dayIndex = 0;
|
|
day_len =
|
|
DateTime.fromMillisecondsSinceEpoch(
|
|
DateTime(
|
|
years[yearIndex],
|
|
months[monthIndex] +
|
|
1)
|
|
.millisecondsSinceEpoch -
|
|
1000)
|
|
.day;
|
|
days_select.value =
|
|
days.sublist(0, day_len);
|
|
}),
|
|
),
|
|
),
|
|
Container(
|
|
child: Text(
|
|
"年",
|
|
style: FlutterFlowTheme.of(context)
|
|
.bodyMedium
|
|
.override(
|
|
fontFamily: 'Readex Pro',
|
|
color:
|
|
themeController.currentColor.sc3,
|
|
letterSpacing: 0,
|
|
fontSize: 30.rpx),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Container(
|
|
padding: EdgeInsets.only(
|
|
left: 30.rpx, right: 30.rpx),
|
|
child: getOnePicker(
|
|
context, months, monthIndex, (d) {
|
|
monthIndex = d;
|
|
dayIndex = 0;
|
|
day_len =
|
|
DateTime.fromMillisecondsSinceEpoch(
|
|
DateTime(
|
|
years[yearIndex],
|
|
months[monthIndex] +
|
|
1)
|
|
.millisecondsSinceEpoch -
|
|
1000)
|
|
.day;
|
|
days_select.value =
|
|
days.sublist(0, day_len);
|
|
}),
|
|
),
|
|
),
|
|
Container(
|
|
child: Text(
|
|
"月",
|
|
style: FlutterFlowTheme.of(context)
|
|
.bodyMedium
|
|
.override(
|
|
fontFamily: 'Readex Pro',
|
|
color:
|
|
themeController.currentColor.sc3,
|
|
letterSpacing: 0,
|
|
fontSize: 30.rpx),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Container(
|
|
padding: EdgeInsets.only(
|
|
left: 30.rpx, right: 40.rpx),
|
|
child: Obx(
|
|
() {
|
|
// print("${dayIndex} ${day_len}");
|
|
return getOnePicker(
|
|
context,
|
|
days_select,
|
|
dayIndex,
|
|
(d) {
|
|
dayIndex = d;
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
Container(
|
|
child: Text(
|
|
"日",
|
|
style: FlutterFlowTheme.of(context)
|
|
.bodyMedium
|
|
.override(
|
|
fontFamily: 'Readex Pro',
|
|
color:
|
|
themeController.currentColor.sc3,
|
|
letterSpacing: 0,
|
|
fontSize: 30.rpx),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
getOnePicker(context, List arr, int checkIndex, Function onSelectedItemChanged,
|
|
{bool looping = false}) {
|
|
ThemeController themeController = Get.find();
|
|
return CupertinoPicker(
|
|
key: UniqueKey(),
|
|
useMagnifier: false,
|
|
itemExtent: 80.rpx,
|
|
magnification: 1,
|
|
diameterRatio: 3,
|
|
squeeze: 1,
|
|
looping: looping,
|
|
scrollController: FixedExtentScrollController(initialItem: checkIndex),
|
|
selectionOverlay: Container(),
|
|
onSelectedItemChanged: (int value) {
|
|
// print("$value");
|
|
onSelectedItemChanged.call(value);
|
|
},
|
|
children: [
|
|
...List.generate(arr.length, (index) {
|
|
return Container(
|
|
alignment: Alignment.center,
|
|
width: 400.rpx,
|
|
child: Text("${arr[index]}",
|
|
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
|
fontFamily: 'Readex Pro',
|
|
color: themeController.currentColor.sc3,
|
|
letterSpacing: 0,
|
|
fontSize: 30.rpx)),
|
|
);
|
|
})
|
|
],
|
|
);
|
|
}
|