Search
Duplicate

calendar_date_picker2

calendar_date_picker2 ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

์–ธ์ œ ์‚ฌ์šฉํ•˜๋Š”๊ฐ€

โ€ข
์ผ์ • ์„ ํƒ (์บ˜๋ฆฐ๋” ์•ฑ)
โ€ข
์˜ˆ์•ฝ ์‹œ์Šคํ…œ (ํ˜ธํ…”, ๋ณ‘์›, ๋ฏธ์šฉ์‹ค)
โ€ข
๊ธฐ๊ฐ„ ์„ ํƒ (์‹œ์ž‘์ผ ~ ์ข…๋ฃŒ์ผ)
โ€ข
์ถœ์„ ์ฒดํฌ / ์ด๋ฒคํŠธ ๋‚ ์งœ ์„ ํƒ

์„ค์น˜ ๋ฐฉ๋ฒ•

dependencies: calendar_date_picker2: ^0.5.0
YAML
๋ณต์‚ฌ
flutter pub get
Bash
๋ณต์‚ฌ

๊ธฐ๋ณธ ์‚ฌ์šฉ๋ฒ•

import 'package:calendar_date_picker2/calendar_date_picker2.dart';
Dart
๋ณต์‚ฌ
CalendarDatePicker2( config: CalendarDatePicker2Config(), value: [], onValueChanged: (dates) { print(dates); }, )
Dart
๋ณต์‚ฌ

์ฃผ์š” ๊ฐœ๋…

value

์„ ํƒ๋œ ๋‚ ์งœ ๋ฆฌ์ŠคํŠธ
value: [DateTime.now()]
Dart
๋ณต์‚ฌ
โ€ข
๋‹จ์ผ ์„ ํƒ โ†’ 1๊ฐœ
โ€ข
๋‹ค์ค‘ ์„ ํƒ โ†’ ์—ฌ๋Ÿฌ ๊ฐœ
โ€ข
๋ฒ”์œ„ ์„ ํƒ โ†’ ์‹œ์ž‘ / ๋ ๋‚ ์งœ 2๊ฐœ

onValueChanged

๋‚ ์งœ ์„ ํƒ ์‹œ ์‹คํ–‰๋˜๋Š” ์ฝœ๋ฐฑ
onValueChanged: (dates) { setState(() { selectedDates = dates; }); }
Dart
๋ณต์‚ฌ

config

์บ˜๋ฆฐ๋” ์„ค์ • (ํ•ต์‹ฌ )
config: CalendarDatePicker2Config( calendarType: CalendarDatePicker2Type.single, )
Dart
๋ณต์‚ฌ

์บ˜๋ฆฐ๋” ํƒ€์ž…

๋‹จ์ผ ์„ ํƒ

calendarType: CalendarDatePicker2Type.single
Dart
๋ณต์‚ฌ
ํ•˜๋ฃจ๋งŒ ์„ ํƒ

๋‹ค์ค‘ ์„ ํƒ

calendarType: CalendarDatePicker2Type.multi
Dart
๋ณต์‚ฌ
์—ฌ๋Ÿฌ ๋‚ ์งœ ์„ ํƒ ๊ฐ€๋Šฅ

๋ฒ”์œ„ ์„ ํƒ (๊ฐ€์žฅ ๋งŽ์ด ์”€)

calendarType: CalendarDatePicker2Type.range
Dart
๋ณต์‚ฌ
์‹œ์ž‘์ผ ~ ์ข…๋ฃŒ์ผ ์„ ํƒ

UI ์ปค์Šคํ„ฐ๋งˆ์ด์ง•

์ƒ‰์ƒ ๋ณ€๊ฒฝ

config: CalendarDatePicker2Config( selectedDayHighlightColor: Colors.blue, todayTextStyle: TextStyle(color: Colors.red), )
Dart
๋ณต์‚ฌ

์š”์ผ ์Šคํƒ€์ผ

weekdayLabelTextStyle: TextStyle( fontWeight: FontWeight.bold, )
Dart
๋ณต์‚ฌ

ํฌ๊ธฐ ์กฐ์ ˆ

dayMaxWidth: 40,
Dart
๋ณต์‚ฌ

์„ ํƒ ์Šคํƒ€์ผ

selectedDayTextStyle: TextStyle( color: Colors.white, )
Dart
๋ณต์‚ฌ

๋‹ค์ด์–ผ๋กœ๊ทธ๋กœ ๋„์šฐ๊ธฐ (์‹ค์ „ )

showDialog( context: context, builder: (context) { return AlertDialog( content: CalendarDatePicker2( config: CalendarDatePicker2Config(), value: selectedDates, onValueChanged: (dates) { setState(() { selectedDates = dates; }); }, ), ); }, );
Dart
๋ณต์‚ฌ

์ „์ฒด ์˜ˆ์ œ

class CalendarExample extends StatefulWidget { _CalendarExampleState createState() => _CalendarExampleState(); } class _CalendarExampleState extends State<CalendarExample> { List<DateTime?> selectedDates = []; Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text("์บ˜๋ฆฐ๋” ์˜ˆ์ œ")), body: Column( children: [ CalendarDatePicker2( config: CalendarDatePicker2Config( calendarType: CalendarDatePicker2Type.range, selectedDayHighlightColor: Colors.blue, ), value: selectedDates, onValueChanged: (dates) { setState(() { selectedDates = dates; }); }, ), Text("์„ ํƒ๋œ ๋‚ ์งœ: $selectedDates"), ], ), ); } }
Dart
๋ณต์‚ฌ