パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v2.1.6

platform_detect

実行中のブラウザとOSを検出するための軽量ライブラリ

Web
30日間ダウンロード
10.2万
いいね数
38
Pub ポイント
125

パッケージをインストール

flutter pub add platform_detect

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

platform_detect は、実行時に現在のオペレーティングシステムおよびブラウザ環境を識別するための軽量な Flutter Web ライブラリです。OS(例:Windows、macOS、Linux)やブラウザ(例:Chrome、Safari、Firefox)などのプラットフォーム詳細をシンプルかつ信頼性の高い方法で検出でき、ユーザーの環境に応じて動作やUIをカスタマイズできます。このパッケージはWebアプリケーション向けに最適化されており、FlutterのWebプラットフォームとシームレスに統合されています。外部依存なしにクライアントサイドJavaScriptによる検出に依存しています。

用途

  • 異なるブラウザ向けのUIレイアウトの調整
  • OSに応じて機能を条件付きで有効化する
  • プラットフォーム固有の問題のデバッグ
  • ブラウザごとのパフォーマンス最適化
  • ブラウザ互換性の癖に対処する

主な機能

  • 軽量で高速
  • 外部の依存関係なし
  • 主要なブラウザおよびオペレーティングシステムをサポート
  • シンプルなAPI、明確な結果
  • Flutter Web 専用に構築されています

適している対象

  • ウェブ専用のFlutterアプリ
  • クロスブラウザ互換性ロジック
  • 環境に配慮した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 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。