You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
4.7 KiB
122 lines
4.7 KiB
1 year ago
|
import 'package:flutter/material.dart';
|
||
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||
|
import 'package:widgetpicker/widgetpicker.dart';
|
||
|
|
||
|
import '../../generated/l10n.dart';
|
||
|
import '../../utils/font_weight.dart';
|
||
|
|
||
|
class DatePickerWidget extends StatelessWidget {
|
||
|
final _years = List.generate((DateTime.now().year - 2019 +1), (i) => "${i + 2019}年");
|
||
|
final _months = List.generate(12, (i) => "${i + 1}月");
|
||
|
final showChange;
|
||
|
|
||
|
DatePickerWidget({this.showChange = true});
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
bool monOn = true;
|
||
|
String _currentYear = "${DateTime.now().year.toString()}年";
|
||
|
String _currentMonth = "${DateTime.now().month.toString()}月";
|
||
|
String _currentTimeStr =
|
||
|
"${_currentYear.replaceAll("年", "")}-${_currentMonth.length == 2 ? "0${_currentMonth.replaceAll("月", "")}" : _currentMonth.replaceAll("月", "")}";
|
||
|
return StatefulBuilder(builder: (context1, state) {
|
||
|
return Container(
|
||
|
height: 260.h,
|
||
|
decoration: BoxDecoration(
|
||
|
color: Colors.white,
|
||
|
borderRadius: BorderRadius.only(
|
||
|
topLeft: Radius.circular(8),
|
||
|
topRight: Radius.circular(8),
|
||
|
),
|
||
|
),
|
||
|
child: Column(
|
||
|
children: [
|
||
|
Container(
|
||
|
height: 50.h,
|
||
|
child: Row(
|
||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||
|
children: [
|
||
|
InkWell(
|
||
|
onTap: () {
|
||
|
Navigator.of(context).pop();
|
||
|
},
|
||
|
child: Container(
|
||
|
child: Text(
|
||
|
S.of(context).quxiao,
|
||
|
style: TextStyle(
|
||
|
fontSize: 16,
|
||
|
fontWeight: MyFontWeight.semi_bold,
|
||
|
color: Colors.black),
|
||
|
),
|
||
|
margin: EdgeInsets.only(left: 6),
|
||
|
padding: EdgeInsets.all(10),
|
||
|
),
|
||
|
),
|
||
|
InkWell(
|
||
|
onTap: () {
|
||
|
Navigator.of(context).pop(_currentTimeStr);
|
||
|
},
|
||
|
child: Container(
|
||
|
child: Text(
|
||
|
S.of(context).queren,
|
||
|
style: TextStyle(
|
||
|
fontSize: 16,
|
||
|
fontWeight: MyFontWeight.semi_bold,
|
||
|
color:Color(0xFF30415B)),
|
||
|
),
|
||
|
margin: EdgeInsets.only(left: 6),
|
||
|
padding: EdgeInsets.all(10),
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
Container(
|
||
|
height: 2.h,
|
||
|
color: Color(0xFFF4F4F4),
|
||
|
),
|
||
|
Expanded(child: Container(
|
||
|
child:
|
||
|
Row(
|
||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||
|
children: [
|
||
|
WidgetPicker(
|
||
|
value: _currentYear,
|
||
|
options: _years,
|
||
|
textStyle: TextStyle(
|
||
|
fontSize: 16.sp, color: Color(0xFFDDDDDD),),
|
||
|
selectedTextStyle:
|
||
|
TextStyle(fontSize: 16.sp, color: Colors.black,fontWeight: MyFontWeight.medium),
|
||
|
onChanged: (value) => state(() => {
|
||
|
_currentYear = value,
|
||
|
_currentTimeStr = monOn
|
||
|
? "${_currentYear.replaceAll("年", "")}-${_currentMonth.length == 2 ? "0${_currentMonth.replaceAll("月", "")}" : _currentMonth.replaceAll("月", "")}"
|
||
|
: "${_currentYear.replaceAll("年", "")}"
|
||
|
}),
|
||
|
),
|
||
|
if (monOn)
|
||
|
WidgetPicker(
|
||
|
value: _currentMonth,
|
||
|
options: _months,
|
||
|
textStyle: TextStyle(
|
||
|
fontSize: 16.sp, color: Color(0xFFDDDDDD)),
|
||
|
selectedTextStyle:
|
||
|
TextStyle(fontSize: 16.sp, color: Colors.black,fontWeight: MyFontWeight.medium),
|
||
|
onChanged: (value) => state(() => {
|
||
|
_currentMonth = value,
|
||
|
_currentTimeStr = monOn
|
||
|
? "${_currentYear.replaceAll("年", "")}-${_currentMonth.length == 2 ? "0${_currentMonth.replaceAll("月", "")}" : _currentMonth.replaceAll("月", "")}"
|
||
|
: "${_currentYear.replaceAll("年", "")}"
|
||
|
}),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
)),
|
||
|
],
|
||
|
),
|
||
|
);
|
||
|
});
|
||
|
}
|
||
|
}
|