Skip to content

Commit 0b79621

Browse files
committed
fix: Making cupertino work for Flutter Web. #1
1 parent 0994279 commit 0b79621

File tree

1 file changed

+57
-44
lines changed

1 file changed

+57
-44
lines changed

Diff for: lib/cupertino.dart

+57-44
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
import 'package:flutter/cupertino.dart';
2+
import 'package:flutter/gestures.dart';
23
import 'package:flutter/material.dart';
34
import 'package:intl/intl.dart';
45

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+
515
/// Cupertino example page.
616
/// Showcases the usage of `DatePicker` and `TimePicker` to change date and time.
717
class CupertinoExamplePage extends StatefulWidget {
@@ -19,20 +29,23 @@ class _CupertinoExamplePageState extends State<CupertinoExamplePage> {
1929
void _showDialog(Widget child) {
2030
showCupertinoModalPopup<void>(
2131
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+
),
3649
),
3750
),
3851
);
@@ -67,18 +80,18 @@ class _CupertinoExamplePageState extends State<CupertinoExamplePage> {
6780
ElevatedButton(
6881
style: ElevatedButton.styleFrom(backgroundColor: Colors.purple.shade300),
6982
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+
),
8295
child: const Text(
8396
"Date",
8497
style: TextStyle(fontSize: 20),
@@ -90,15 +103,15 @@ class _CupertinoExamplePageState extends State<CupertinoExamplePage> {
90103
style: TextStyle(fontSize: 20),
91104
),
92105
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+
))
102115
],
103116
),
104117
),
@@ -110,15 +123,15 @@ class _CupertinoExamplePageState extends State<CupertinoExamplePage> {
110123
ElevatedButton(
111124
style: ElevatedButton.styleFrom(backgroundColor: Colors.green.shade400),
112125
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+
),
122135
child: const Text(
123136
"DateTime",
124137
style: TextStyle(fontSize: 20),

0 commit comments

Comments
 (0)