TextButton(
onPressed: () {
//Scafflod에서 제공하는 하단에서 올라오는 메세지 창 (IOS 모양)
showModalBottomSheet(
context: context,
backgroundColor: Color(0xff161616),
//테두리 모양 변경
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(20))),
builder: (BuildContext context) {
//showModalBottomSheet에는 넓이, 높이를 조절하는 기능이 없음으로 Container로 조절 해야한다.
return Container(
height: 200,
//IOS Date 선택 UI 함수
child: selectDate(),
);
});
},
- 사용된 코드 (selectDate IOS디자인의 캘린더 선택)
//Cupertino형 날짜 선택
Widget selectDate() {
DateTime selectDate;
if (_adminProvider.cupertinoDate == null) {
selectDate = DateTime.now();
} else {
selectDate = _adminProvider.cupertinoDate!;
}
return Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: Icon(
CupertinoIcons.back,
color: Colors.white,
size: 26,
)),
IconButton(
onPressed: () {
_adminProvider.setDateTime(selectDate);
Navigator.pop(context);
},
icon: Icon(
CupertinoIcons.check_mark,
color: Colors.blue,
size: 26,
)),
],
),
Divider(
height: 1,
color: Colors.blueGrey,
),
SizedBox(
height: 10,
),
Container(
//위에 작성 코드는 기타 다른 코드임 여기서 부터 보면 됨
//CuperitnoDatePicker를 사용하기 위해서 상위에 크기를 반드시 지정 해줘야한다.
height: 80,
//Cupertino형 위젯을 스타일 할때 사용하는 위젯
child: CupertinoTheme(
data: CupertinoThemeData(
textTheme: CupertinoTextThemeData(
dateTimePickerTextStyle: TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.bold),
),
),
//Cupertino형 날짜 선택 위젯
child: CupertinoDatePicker(
backgroundColor: Color(0xff161616),
//현재 날짜
initialDateTime: selectDate,
//끝 연도
maximumYear: DateTime.now().year,
//끝날짜
maximumDate: DateTime.now(),
//첫 연도
minimumYear: 2021,
//날짜 선택 모드
mode: CupertinoDatePickerMode.date,
onDateTimeChanged: (dateTime) {
selectDate = dateTime;
},
),
),
),
],
);
}
- 참고사항Cupertino Date Pick에서 한국어 사용 하려면 반드시 블로그에 있는
[Flutter]플러터(캘린더-각종 한국어 적용)|안드로이드, IOS 설정을 해줘야 한다