1
1
import 'package:flutter/cupertino.dart' ;
2
+ import 'package:flutter/gestures.dart' ;
2
3
import 'package:flutter/material.dart' ;
3
4
import 'package:intl/intl.dart' ;
4
5
6
+ class WebScrollBehaviour extends MaterialScrollBehavior {
7
+ // Override behaviour methods and getters like dragDevices
8
+ @override
9
+ Set <PointerDeviceKind > get dragDevices => {
10
+ PointerDeviceKind .touch,
11
+ PointerDeviceKind .mouse,
12
+ };
13
+ }
14
+
5
15
/// Cupertino example page.
6
16
/// Showcases the usage of `DatePicker` and `TimePicker` to change date and time.
7
17
class CupertinoExamplePage extends StatefulWidget {
@@ -19,20 +29,23 @@ class _CupertinoExamplePageState extends State<CupertinoExamplePage> {
19
29
void _showDialog (Widget child) {
20
30
showCupertinoModalPopup <void >(
21
31
context: context,
22
- builder: (BuildContext context) => Container (
23
- height: 216 ,
24
- padding: const EdgeInsets .only (top: 6.0 ),
25
- // The Bottom margin is provided to align the popup above the system
26
- // navigation bar.
27
- margin: EdgeInsets .only (
28
- bottom: MediaQuery .of (context).viewInsets.bottom,
29
- ),
30
- // Provide a background color for the popup.
31
- color: CupertinoColors .systemBackground.resolveFrom (context),
32
- // Use a SafeArea widget to avoid system overlaps.
33
- child: SafeArea (
34
- top: false ,
35
- child: child,
32
+ builder: (BuildContext context) => ScrollConfiguration (
33
+ behavior: WebScrollBehaviour (),
34
+ child: Container (
35
+ height: 216 ,
36
+ padding: const EdgeInsets .only (top: 6.0 ),
37
+ // The Bottom margin is provided to align the popup above the system
38
+ // navigation bar.
39
+ margin: EdgeInsets .only (
40
+ bottom: MediaQuery .of (context).viewInsets.bottom,
41
+ ),
42
+ // Provide a background color for the popup.
43
+ color: CupertinoColors .systemBackground.resolveFrom (context),
44
+ // Use a SafeArea widget to avoid system overlaps.
45
+ child: SafeArea (
46
+ top: false ,
47
+ child: child,
48
+ ),
36
49
),
37
50
),
38
51
);
@@ -67,18 +80,18 @@ class _CupertinoExamplePageState extends State<CupertinoExamplePage> {
67
80
ElevatedButton (
68
81
style: ElevatedButton .styleFrom (backgroundColor: Colors .purple.shade300),
69
82
onPressed: () => _showDialog (
70
- CupertinoDatePicker (
71
- initialDateTime: dateTime,
72
- mode: CupertinoDatePickerMode .date,
73
- use24hFormat: true ,
74
- // This shows day of week alongside day of month
75
- showDayOfWeek: true ,
76
- // This is called when the user changes the date.
77
- onDateTimeChanged: (DateTime newDate) {
78
- setState (() => dateTime = newDate);
79
- },
80
- ),
81
- ),
83
+ CupertinoDatePicker (
84
+ initialDateTime: dateTime,
85
+ mode: CupertinoDatePickerMode .date,
86
+ use24hFormat: true ,
87
+ // This shows day of week alongside day of month
88
+ showDayOfWeek: true ,
89
+ // This is called when the user changes the date.
90
+ onDateTimeChanged: (DateTime newDate) {
91
+ setState (() => dateTime = newDate);
92
+ },
93
+ ),
94
+ ),
82
95
child: const Text (
83
96
"Date" ,
84
97
style: TextStyle (fontSize: 20 ),
@@ -90,15 +103,15 @@ class _CupertinoExamplePageState extends State<CupertinoExamplePage> {
90
103
style: TextStyle (fontSize: 20 ),
91
104
),
92
105
onPressed: () => _showDialog (
93
- CupertinoDatePicker (
94
- initialDateTime: dateTime,
95
- mode: CupertinoDatePickerMode .time,
96
- use24hFormat: true ,
97
- onDateTimeChanged: (DateTime newDate) {
98
- setState (() => dateTime = newDate);
99
- },
100
- ),
101
- ))
106
+ CupertinoDatePicker (
107
+ initialDateTime: dateTime,
108
+ mode: CupertinoDatePickerMode .time,
109
+ use24hFormat: true ,
110
+ onDateTimeChanged: (DateTime newDate) {
111
+ setState (() => dateTime = newDate);
112
+ },
113
+ ),
114
+ ))
102
115
],
103
116
),
104
117
),
@@ -110,15 +123,15 @@ class _CupertinoExamplePageState extends State<CupertinoExamplePage> {
110
123
ElevatedButton (
111
124
style: ElevatedButton .styleFrom (backgroundColor: Colors .green.shade400),
112
125
onPressed: () => _showDialog (
113
- CupertinoDatePicker (
114
- initialDateTime: dateTime,
115
- mode: CupertinoDatePickerMode .dateAndTime,
116
- use24hFormat: true ,
117
- onDateTimeChanged: (DateTime newDate) {
118
- setState (() => dateTime = newDate);
119
- },
120
- ),
121
- ),
126
+ CupertinoDatePicker (
127
+ initialDateTime: dateTime,
128
+ mode: CupertinoDatePickerMode .dateAndTime,
129
+ use24hFormat: true ,
130
+ onDateTimeChanged: (DateTime newDate) {
131
+ setState (() => dateTime = newDate);
132
+ },
133
+ ),
134
+ ),
122
135
child: const Text (
123
136
"DateTime" ,
124
137
style: TextStyle (fontSize: 20 ),
0 commit comments