분류, 패키지 및 저장소 검색

패키지 상세v1.7.0

ua_client_hints

Flutter에 사용자 에이전트 클라이언트 힌트 제공

AndroidiOSWebmacOS
30일 다운로드
19.2만
좋아요
52
Pub 점수
130

패키지 설치

flutter pub add ua_client_hints

패키지 개요

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

ua_client_hints 패키지는 Flutter 애플리케이션에서 User-Agent Client Hints에 접근할 수 있게 해주며, 표준화된 HTTP 헤더를 통해 브라우저 및 장치에 대한 상세한 정보를 제공합니다. 이는 Android, iOS, Web, macOS에서 플랫폼, 모델, 브랜드와 같은 클라이언트 메타데이터를 가져오는 과정을 간소화합니다. 개발자는 User-Agent 문자열의 문자열 파싱에만 의존하지 않고 사용자 디바이스 특성에 따라 콘텐츠 전달을 맞춤화할 수 있도록 도와줍니다. 이 패키지는 HTTP 클라이언트와 원활하게 통합되며, 개인정보 보호를 고려한 현대적인 웹 표준 기반의 디바이스 탐지 기능을 지원합니다.

사용 사례

  • 기기별 콘텐츠 렌더링
  • 브라우저 및 운영체제 감지
  • 최적화된 자산 전달
  • 개인정보 보호 중심의 분석
  • 크로스 플랫폼 호환성 테스트

주요 기능

  • Android, iOS, 웹 및 macOS를 지원합니다
  • HTTP 헤더를 통해 표준화된 클라이언트 힌트 제공
  • 사용자 에이전트 문자열 파싱에 대한 의존도를 줄입니다
  • 기존 HTTP 클라이언트와 통합
  • 장치 탐지에 대해 현대적인 웹 표준을 따릅니다

적합한 대상

  • 정확한 장치 정보가 필요한 개발자
  • 적응형 UI/UX가 필요한 앱
  • 개인정보 및 준수에 중점을 둔 프로젝트
  • 웹 및 모바일 하이브리드 애플리케이션
  • 콘텐츠 전달 최적화

고려 사항

  • 호환되는 서버 측 지원이 필요합니다
  • 클라이언트 힌트를 노출하는 장치에 한정
  • 모든 브라우저가 클라이언트 힌트를 완전히 지원하는 것은 아님
  • 추가 서버 구성이 필요할 수 있습니다
  • 기반 플랫폼 기능에 따라 다릅니다

원본 README

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

User-Agent Client Hints for Flutter

What's User-Agent Client Hints?

User-Agent Client Hints
Improving user privacy and developer experience with User-Agent Client Hints
User-Agent Client Hints Demo on Browser

⬇️ Response Accept-CH ⬆️ Request header ⬆️ RequestExample value Description
UA Sec-CH-UA "Chromium";v="84",
"Google Chrome";v="84"
List of browser brands and their significant version.
UA-Mobile Sec-CH-UA-Mobile ?1 Boolean indicating if the browser is
on a mobile device (?1 for true) or not (?0 for false).
UA-Full-Version Sec-CH-UA-Full-Version "84.0.4143.2" The complete version for the browser.
UA-Platform Sec-CH-UA-Platform "Android" The platform for the device,
usually the operating system (OS).
UA-Platform-Version Sec-CH-UA-Platform-Version "10" The version for the platform or OS.
UA-Arch Sec-CH-UA-Arch "ARM64" The underlying architecture for the device.
While this may not be relevant to displaying the page,
the site may want to offer a download which defaults to the right format.
UA-Model Sec-CH-UA-Model "Pixel 3" The device model.

Installation

This plugin is set the Null Safety.

Add this to your package's pubspec.yaml file by running the following command

$ flutter pub add ua_client_hints

Usage

Supported platforms:

  • Android
  • iOS
  • macOS
  • Web

On Web, values depend on browser support for User-Agent Client Hints. Some fields such as architecture, model, or platformVersion can be empty on browsers that don't expose high-entropy hints.

With Dio

Add to the request header.

class AppDio with DioMixin implements Dio {
  AppDio._([BaseOptions options]) {
    options = BaseOptions(
      baseUrl: 'https://wasabeef.jp',
    );

    this.options = options;
    interceptors.add(InterceptorsWrapper(
      onRequest: (options) async {
        // Add User-Agent Client Hints
        options.headers.addAll(await userAgentClientHintsHeader());
        return options;
      },
    ));
  }

  static Dio getInstance() => AppDio._();
}
APIs
final String ua = await userAgent();

print('User-Agent: $ua');  // e.g.. 'SampleApp/1.0.0 (Android 11; Pixel 4 XL; coral; arm64-v8a)'
// macOS example:
// 'SampleApp/1.0.0 (macOS 15.5.0; Mac; Mac15,12; arm64)'
// Web fallback example:
// 'SampleApp/1.0.0 (macOS 15.5.0; Google Chrome; arm64)'
final UserAgentData uaData = await userAgentData();

print('platform:        ${uaData.platform}');              // e.g.. 'Android'
print('platformVersion: ${uaData.platformVersion}');       // e.g.. '10'
print('model:           ${uaData.model}');                 // e.g.. 'Pixel 4 XL'
print('architecture:    ${uaData.architecture}');          // e.g.. 'arm64-v8a'
print('brand:           ${uaData.brand}');                 // e.g.. 'Google'
print('mobile:          ${uaData.mobile}');                // e.g.. true
print('device:          ${uaData.device}');                // e.g.. 'coral'
print('appName:         ${uaData.package.appName}');       // e.g.. 'SampleApp'
print('appVersion:      ${uaData.package.appVersion}');    // e.g.. '1.0.0'
print('packageName:     ${uaData.package.packageName}');   // e.g.. 'jp.wasabeef.ua'
print('buildNumber:     ${uaData.package.buildNumber}');   // e.g.. '1'
final Map<String, dynamic> header = await userAgentClientHintsHeader();

print("Sec-CH-UA-Arch:             ${header['Sec-CH-UA-Arch']}");             // e.g.. 'arm64-v8a'
print("Sec-CH-UA-Model:            ${header['Sec-CH-UA-Model']}");            // e.g.. 'Pixel 4 XL'
print("Sec-CH-UA-Platform:         ${header['Sec-CH-UA-Platform']}");         // e.g.. 'Android'
print("Sec-CH-UA-Platform-Version: ${header['Sec-CH-UA-Platform-Version']}"); // e.g.. '10'
print("Sec-CH-UA:                  ${header['Sec-CH-UA']}");                  // e.g.. '"SampleApp"; v="1.0.0"'
print("Sec-CH-UA-Full-Version:     ${header['Sec-CH-UA-Full-Version']}");     // e.g.. '1.0.0'
print("Sec-CH-UA-Mobile:           ${header['Sec-CH-UA-Mobile']}");           // e.g.. '?1' (true) or '?0' (false)

카테고리

소스 저장소

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