Showing
1 changed file
with
20 additions
and
10 deletions
@@ -3,7 +3,6 @@ | @@ -3,7 +3,6 @@ | ||
3 | // found in the LICENSE file. | 3 | // found in the LICENSE file. |
4 | 4 | ||
5 | import 'dart:async'; | 5 | import 'dart:async'; |
6 | -import 'dart:io'; | ||
7 | import 'package:flutter/cupertino.dart'; | 6 | import 'package:flutter/cupertino.dart'; |
8 | import 'package:flutter/foundation.dart'; | 7 | import 'package:flutter/foundation.dart'; |
9 | import 'package:flutter/gestures.dart'; | 8 | import 'package:flutter/gestures.dart'; |
@@ -301,15 +300,8 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> | @@ -301,15 +300,8 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> | ||
301 | // Otherwise the calculate the velocity with a VelocityTracker | 300 | // Otherwise the calculate the velocity with a VelocityTracker |
302 | if (_velocityTracker == null) { | 301 | if (_velocityTracker == null) { |
303 | // Checking the device type as per the OS installed in it | 302 | // Checking the device type as per the OS installed in it |
304 | - _velocityTracker = VelocityTracker( | ||
305 | - // SmartPhone Devices | ||
306 | - (Platform.isAndroid || Platform.isIOS) | ||
307 | - ? PointerDeviceKind.touch | ||
308 | - : // PCs or desktops or Laptops devices has mouse pointers | ||
309 | - (Platform.isLinux || Platform.isWindows || Platform.isMacOS) | ||
310 | - ? PointerDeviceKind.mouse | ||
311 | - : // Some unknown devices | ||
312 | - PointerDeviceKind.unknown); | 303 | + final pointerKind = defaultPointerDeviceKind(context); |
304 | + _velocityTracker = VelocityTracker(pointerKind); | ||
313 | _startTime = DateTime.now(); | 305 | _startTime = DateTime.now(); |
314 | } | 306 | } |
315 | DragUpdateDetails dragDetails; | 307 | DragUpdateDetails dragDetails; |
@@ -474,3 +466,21 @@ class _CustomBottomSheetLayout extends SingleChildLayoutDelegate { | @@ -474,3 +466,21 @@ class _CustomBottomSheetLayout extends SingleChildLayoutDelegate { | ||
474 | return false; | 466 | return false; |
475 | } | 467 | } |
476 | } | 468 | } |
469 | + | ||
470 | +// Used by VelocityTracker | ||
471 | +// https://github.com/flutter/flutter/pull/64267#issuecomment-694196304 | ||
472 | +PointerDeviceKind defaultPointerDeviceKind(BuildContext context) { | ||
473 | + final platform = Theme.of(context)?.platform ?? defaultTargetPlatform; | ||
474 | + switch (platform) { | ||
475 | + case TargetPlatform.iOS: | ||
476 | + case TargetPlatform.android: | ||
477 | + return PointerDeviceKind.touch; | ||
478 | + case TargetPlatform.linux: | ||
479 | + case TargetPlatform.macOS: | ||
480 | + case TargetPlatform.windows: | ||
481 | + return PointerDeviceKind.mouse; | ||
482 | + case TargetPlatform.fuchsia: | ||
483 | + return PointerDeviceKind.unknown; | ||
484 | + } | ||
485 | + return PointerDeviceKind.unknown; | ||
486 | +} |
-
Please register or login to post a comment