platform_detect는 런타임에 현재 운영 체제 및 브라우저 환경을 식별하기 위해 설계된 가벼운 Flutter Web 라이브러리입니다. OS(예: Windows, macOS, Linux)와 브라우저(예: Chrome, Safari, Firefox)와 같은 플랫폼 세부 정보를 간단하고 신뢰성 있게 감지할 수 있으며, 사용자의 환경에 따라 동작이나 UI를 맞춤화할 수 있도록 도와줍니다. 이 패키지는 웹 애플리케이션에 최적화되어 있으며 Flutter의 웹 플랫폼과 원활하게 통합됩니다. 외부 종속성이 없이 클라이언트 측 JavaScript 탐지에 의존합니다.
사용 사례
다른 브라우저에 맞게 UI 레이아웃 조정
운영 체제에 따라 기능을 조건부로 활성화하기
플랫폼별 문제 디버깅
브라우저별 성능 최적화
브라우저 호환성 문제 처리
주요 기능
경량이고 빠름
외부 종속성 없음
주요 브라우저 및 OS를 지원합니다
간단한 API, 명확한 결과
Flutter Web 전용으로 특별히 제작됨
적합한 대상
웹 전용 플러터 앱
크로스 브라우저 호환성 논리
환경 인식형 UI 렌더링
개발자 도구 및 진단
고려 사항
웹 플랫폼 전용
브라우저/사용자 에이전트 문자열에 의존합니다
새로운 브라우저 버전에 대한 업데이트가 필요할 수 있습니다
모바일 또는 데스크톱 앱에 적합하지 않습니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
platform_detect
A library for detecting browser and platform type and version.
Usage
A simple usage example:
import'package:platform_detect/platform_detect.dart';
main() {
if (browser.isChrome) {
print('thank you for being a friend');
}
if (operatingSystem.isMac) {
print('');
}
}
Decorating the <html> element with CSS classes
This library can also be used to place CSS classes on the <html> element based on the
operating system, browser, or a specific supported feature.
Add the decorator.dart import as shown in the example below, and call decorateRootNodeWithPlatformClasses
within main in your application.
By default, the only browser feature that the library detects for you is touch / mstouch.
You can extend this functionality to bake in a Modernizr-esque implementation by creating your
own Feature instances, and passing a list of them as the features argument to
decorateRootNodeWithPlatformClasses:
import'package:platform_detect/platform_detect.dart';
import'package:platform_detect/decorator.dart';
// For instance, if you need to detect whether a browser supports H5 canvas stuff...var canvasFeature = newFeature('canvas', newCanvasElement().context2D != null);
main() {
// Decorate HTML elementdecorateRootNodeWithPlatformClasses(features: [canvasFeature]);
// Or use the `isSupported` field somewhere else in your app...if (canvasFeature.isSupported) {
// Do something
} else {
// Fall back / warn / etc...
}
}
The <html> node of your application will now look like something like this
for browsers that support canvas: