패키지, 저장소 및 앱 카테고리 검색

패키지 상세v2.1.6

platform_detect

실행 중인 브라우저와 운영 체제를 감지하기 위한 가벼운 라이브러리

Web
30일 다운로드
10.2만
좋아요
38
Pub 점수
125

패키지 설치

flutter pub add platform_detect

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

platform_detect는 런타임에 현재 운영 체제 및 브라우저 환경을 식별하기 위해 설계된 가벼운 Flutter Web 라이브러리입니다. OS(예: Windows, macOS, Linux)와 브라우저(예: Chrome, Safari, Firefox)와 같은 플랫폼 세부 정보를 간단하고 신뢰성 있게 감지할 수 있으며, 사용자의 환경에 따라 동작이나 UI를 맞춤화할 수 있도록 도와줍니다. 이 패키지는 웹 애플리케이션에 최적화되어 있으며 Flutter의 웹 플랫폼과 원활하게 통합됩니다. 외부 종속성이 없이 클라이언트 측 JavaScript 탐지에 의존합니다.

사용 사례

  • 다른 브라우저에 맞게 UI 레이아웃 조정
  • 운영 체제에 따라 기능을 조건부로 활성화하기
  • 플랫폼별 문제 디버깅
  • 브라우저별 성능 최적화
  • 브라우저 호환성 문제 처리

주요 기능

  • 경량이고 빠름
  • 외부 종속성 없음
  • 주요 브라우저 및 OS를 지원합니다
  • 간단한 API, 명확한 결과
  • Flutter Web 전용으로 특별히 제작됨

적합한 대상

  • 웹 전용 플러터 앱
  • 크로스 브라우저 호환성 논리
  • 환경 인식형 UI 렌더링
  • 개발자 도구 및 진단

고려 사항

  • 웹 플랫폼 전용
  • 브라우저/사용자 에이전트 문자열에 의존합니다
  • 새로운 브라우저 버전에 대한 업데이트가 필요할 수 있습니다
  • 모바일 또는 데스크톱 앱에 적합하지 않습니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

codecov documentation

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.

import 'package:platform_detect/platform_detect.dart';
import 'package:platform_detect/decorator.dart';

main() {
  decorateRootNodeWithPlatformClasses();
}

The <html> node of your application will now look like something like this:

<html lang="en" class="ua-chrome ua-chrome45 ua-lt-chrome46 ua-lt-chrome47 os-mac no-touch no-mstouch">
  <!-- ... -->
</html>
Feature detection

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 = new Feature('canvas', new CanvasElement().context2D != null);

main() {
  // Decorate HTML element
  decorateRootNodeWithPlatformClasses(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:

<html lang="en" class="canvas ...">
  <!-- ... -->
</html>

and something like this for browsers that don't support canvas:

<html lang="en" class="no-canvas ...">
  <!-- ... -->
</html>

카테고리

의존성

의존성 목록 2 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.