-
Notifications
You must be signed in to change notification settings - Fork 64
/
46.flutter_ios_calender_picker.dart
73 lines (67 loc) · 2.64 KB
/
46.flutter_ios_calender_picker.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:ig_posts/season_2/63.transperant_design_pattern.dart';
import 'package:ig_posts/utils/colors.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
class CalenderNotifier extends ChangeNotifier {
DateTime? pickedDate = DateTime.now();
void setPickedDate({required DateTime dateTime}) {
pickedDate = dateTime;
notifyListeners();
}
}
class FlutteCalenderPickerView extends StatelessWidget {
const FlutteCalenderPickerView({super.key});
@override
Widget build(BuildContext context) {
CalenderNotifier calenderNotifier({required bool renderUI}) =>
Provider.of<CalenderNotifier>(context, listen: renderUI);
String renderValue() {
var format = DateFormat.yMd();
var dateString =
format.format(calenderNotifier(renderUI: true).pickedDate!);
return dateString;
}
return Scaffold(
backgroundColor: KConstantColors.bgColor,
appBar: CustomAppBar(title: "Flutter Calender Picker"),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text("Flutter 3 IOS date picker",
style: KConstantTextstyles.bold(fontSize: 32)),
SizedBox(height: 20),
SizedBox(
height: 200,
width: 400,
child: CupertinoTheme(
data: CupertinoThemeData(
textTheme: CupertinoTextThemeData(
dateTimePickerTextStyle: TextStyle(
color: KConstantColors.whiteColor,
fontSize: 16)),
),
child: CupertinoDatePicker(
mode: CupertinoDatePickerMode.date,
onDateTimeChanged: (val) {
debugPrint(val.toString());
calenderNotifier(renderUI: false)
.setPickedDate(dateTime: val);
},
))),
SizedBox(height: 50),
Container(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(renderValue(),
style: KConstantTextstyles.bold(fontSize: 32)),
),
decoration: BoxDecoration(
color: KConstantColors.bgColorFaint,
borderRadius: BorderRadius.circular(12)),
)
]));
}
}