David Iglesias d7656f2fcf
[web] Use platform detection from Flutter web engine. (#147346)
> [!IMPORTANT]
> Requires the following engine PR:
> * https://github.com/flutter/engine/pull/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: https://github.com/flutter/flutter/issues/128943

## Testing

Demo app deployed here:

* https://dit-browser-detect.web.app
2024-05-07 22:44:56 +00:00

34 lines
1.0 KiB
Dart

// 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);
});
});
}