Skip to content

Commit

Permalink
User targetPlatform to detect PointerDeviceKind
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesblasco committed Sep 17, 2020
1 parent da6d525 commit 8b4d3da
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions lib/src/bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// found in the LICENSE file.

import 'dart:async';
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
Expand Down Expand Up @@ -301,15 +300,8 @@ class _ModalBottomSheetState extends State<ModalBottomSheet>
// Otherwise the calculate the velocity with a VelocityTracker
if (_velocityTracker == null) {
// Checking the device type as per the OS installed in it
_velocityTracker = VelocityTracker(
// SmartPhone Devices
(Platform.isAndroid || Platform.isIOS)
? PointerDeviceKind.touch
: // PCs or desktops or Laptops devices has mouse pointers
(Platform.isLinux || Platform.isWindows || Platform.isMacOS)
? PointerDeviceKind.mouse
: // Some unknown devices
PointerDeviceKind.unknown);
final pointerKind = defaultPointerDeviceKind(context);
_velocityTracker = VelocityTracker(pointerKind);
_startTime = DateTime.now();
}
DragUpdateDetails dragDetails;
Expand Down Expand Up @@ -474,3 +466,21 @@ class _CustomBottomSheetLayout extends SingleChildLayoutDelegate {
return false;
}
}

// Used by VelocityTracker
// https://github.com/flutter/flutter/pull/64267#issuecomment-694196304
PointerDeviceKind defaultPointerDeviceKind(BuildContext context) {
final platform = Theme.of(context)?.platform ?? defaultTargetPlatform;
switch (platform) {
case TargetPlatform.iOS:
case TargetPlatform.android:
return PointerDeviceKind.touch;
case TargetPlatform.linux:
case TargetPlatform.macOS:
case TargetPlatform.windows:
return PointerDeviceKind.mouse;
case TargetPlatform.fuchsia:
return PointerDeviceKind.unknown;
}
return PointerDeviceKind.unknown;
}

0 comments on commit 8b4d3da

Please sign in to comment.