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.
 
 
 
 
 
 

121 lines
4.7 KiB

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("", "")}"
}),
),
],
),
)),
],
),
);
});
}
}