-
Notifications
You must be signed in to change notification settings - Fork 26.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[web] Use platform detection from Flutter web engine. (#147346)
> [!IMPORTANT] > Requires the following engine PR: > * flutter/engine#52380 > ---- This PR refactors Flutter `foundation`'s library `platform` for the web with the same code we use to detect platforms in the engine. ## Issues * Fixes: #128943 ## Testing Demo app deployed here: * https://dit-browser-detect.web.app
- Loading branch information
Showing
2 changed files
with
68 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2014 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
@TestOn('chrome') | ||
library; | ||
|
||
import 'dart:ui_web' as ui_web; | ||
|
||
import 'package:flutter/foundation.dart' show TargetPlatform, defaultTargetPlatform; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
tearDown(() { | ||
// Remove the `debugOperatingSystemOverride`. | ||
ui_web.browser.debugOperatingSystemOverride = null; | ||
}); | ||
|
||
group('defaultTargetPlatform', () { | ||
testWidgets('returns what ui_web says', (WidgetTester _) async { | ||
// Set the OS reported by web_ui to anything that is not linux. | ||
ui_web.browser.debugOperatingSystemOverride = ui_web.OperatingSystem.iOs; | ||
|
||
expect(defaultTargetPlatform, TargetPlatform.iOS); | ||
}); | ||
|
||
testWidgets('defaults `unknown` to android', (WidgetTester _) async { | ||
ui_web.browser.debugOperatingSystemOverride = ui_web.OperatingSystem.unknown; | ||
|
||
expect(defaultTargetPlatform, TargetPlatform.android); | ||
}); | ||
}); | ||
} |