Repository: fujidaiti/smooth_sheets
Pull request #269 (2024-10-19 08:10:09)

Refactor: Replace Platform (dart:io) with TargetPlatform
## Related issues (optional)

None.

## Description

Support WASM.
![image](https://github.com/user-attachments/assets/590e28bc-133d-4810-a4fd-54f4228b9e65)


## Summary (check all that apply)

- [x] Modified / added code
- [x] Modified / added tests
- [x] Modified / added examples
- [ ] Modified / added others (pubspec.yaml, workflows, etc...)
- [ ] Updated README
- [ ] Contains breaking changes
  - [ ] Created / updated migration guide
- [ ] Incremented version number
  - [ ] Updated CHANGELOG



Patch:
diff --git a/example/lib/showcase/ai_playlist_generator.dart b/example/lib/showcase/ai_playlist_generator.dart
index b4f3aac..723069b 100644
--- a/example/lib/showcase/ai_playlist_generator.dart
+++ b/example/lib/showcase/ai_playlist_generator.dart
@@ -1,6 +1,7 @@
 import 'dart:async';
-import 'dart:io';
 
+import 'package:flutter/foundation.dart'
+    show TargetPlatform, defaultTargetPlatform;
 import 'package:flutter/material.dart';
 import 'package:flutter/services.dart';
 import 'package:go_router/go_router.dart';
@@ -8,7 +9,7 @@ import 'package:smooth_sheets/smooth_sheets.dart';
 
 void main() {
   // Make the system navigation bar transparent on Android.
-  if (Platform.isAndroid) {
+  if (defaultTargetPlatform == TargetPlatform.android) {
     WidgetsFlutterBinding.ensureInitialized();
     SystemChrome.setEnabledSystemUIMode(
       SystemUiMode.edgeToEdge,
diff --git a/lib/src/foundation/sheet_physics.dart b/lib/src/foundation/sheet_physics.dart
index 0b04a51..f7f7751 100644
--- a/lib/src/foundation/sheet_physics.dart
+++ b/lib/src/foundation/sheet_physics.dart
@@ -1,7 +1,8 @@
-import 'dart:io';
 import 'dart:math';
 
 import 'package:collection/collection.dart';
+import 'package:flutter/foundation.dart'
+    show TargetPlatform, defaultTargetPlatform;
 import 'package:flutter/gestures.dart';
 import 'package:flutter/widgets.dart';
 
@@ -36,11 +37,12 @@ abstract class SheetPhysics {
   /// the first time or after each time the drag motion stopped.
   ///
   /// If null, no minimum threshold is enforced.
-  double? get dragStartDistanceMotionThreshold {
-    return Platform.isIOS
-        ? const BouncingScrollPhysics().dragStartDistanceMotionThreshold
-        : null;
-  }
+  double? get dragStartDistanceMotionThreshold =>
+      switch (defaultTargetPlatform) {
+        TargetPlatform.iOS =>
+          const BouncingScrollPhysics().dragStartDistanceMotionThreshold,
+        _ => null,
+      };
 
   /// Create a copy of this object appending the [ancestor] to
   /// the physics chain, much like [ScrollPhysics.applyTo].


Test patch:
diff --git a/test/foundation/physics_test.dart b/test/foundation/physics_test.dart
index 1bb1f4a..79d17f8 100644
--- a/test/foundation/physics_test.dart
+++ b/test/foundation/physics_test.dart
@@ -1,4 +1,6 @@
 // ignore_for_file: lines_longer_than_80_chars
+import 'package:flutter/foundation.dart'
+    show debugDefaultTargetPlatformOverride;
 import 'package:flutter/widgets.dart';
 import 'package:flutter_test/flutter_test.dart';
 import 'package:smooth_sheets/smooth_sheets.dart';
@@ -71,6 +73,22 @@ void main() {
       physicsUnderTest = const _SheetPhysicsWithDefaultConfiguration();
     });
 
+    test('dragStartDistanceMotionThreshold for different platforms', () {
+      for (final testTargetPlatform in TargetPlatform.values) {
+        debugDefaultTargetPlatformOverride = testTargetPlatform;
+        switch (testTargetPlatform) {
+          case TargetPlatform.iOS:
+            expect(
+              physicsUnderTest.dragStartDistanceMotionThreshold,
+              const BouncingScrollPhysics().dragStartDistanceMotionThreshold,
+            );
+          case _:
+            expect(physicsUnderTest.dragStartDistanceMotionThreshold, null);
+        }
+        debugDefaultTargetPlatformOverride = null;
+      }
+    });
+
     test('does not allow over/under dragging', () {
       expect(
         physicsUnderTest.computeOverflow(10, _positionAtTopEdge),