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

パッケージ詳細v4.1.0

selector

関数型プログラミングを書くための、複数のタイプをサポートするプラットフォームセレクタ。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
58
いいね数
22
Pub ポイント
160

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

flutter pub add selector

パッケージ概要

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

複数のデータ型をサポートする、プラットフォームに依存しないセレクターパッケージで、Flutterアプリケーションでの関数型プログラミングパターンを可能にするように設計されています。状態を管理し、値を導出するための明確で合成可能な方法を提供し、プラットフォーム間でコードの読みやすさと保守性を向上させます。Dartで作成され、Flutterプロジェクトにスムーズに統合でき、Android、iOS、Web、macOS、Windows、Linuxなどすべての主要なプラットフォームをサポートしています。このパッケージは、効率的な状態処理のために型安全性と関数型パラダイムを重視しています。

用途

  • 複雑なUIにおける状態の導出
  • 関数型反応型プログラミング
  • クロスプラットフォーム状態管理
  • 選択ロジックの再利用可能性
  • 派生状態の計算を簡素化する
  • ストリームベースの値選択

主な機能

  • マルチタイプ対応
  • 関数型プログラミングスタイル
  • プラットフォームに依存しない設計
  • 型安全な選択
  • コンポーザブルセレクタ
  • 組み込みプラットフォーム互換性

適している対象

  • 関数型パターンを使用する開発者
  • 再利用可能な状態ロジックを求めるチーム
  • クロスプラットフォームのFlutterアプリ
  • 複雑な状態の導出を必要とするアプリ
  • クリーンでテスト可能なコードを重視するプロジェクト

注意事項

  • 関数型プログラミングの理解が必要です
  • 初心者にとって学習曲線を導入する可能性があります
  • 状態管理ソリューションと併用するのが最適です
  • Dart/Flutterエコシステムに限定
  • 単純な状態の保存には向いていません

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

Selector

Multi-type support Platform Selector for Flutter. This library helps you write platform-specific code in a clean and functional way.

Features

  • Basic Selector (selector): Choose a value based on the current platform (Android, iOS, macOS, Windows, Linux, Fuchsia, Web). All platform parameters are required. Throws UnsupportedError if the platform is not identified.
  • Optional Selector (optionalSelector): Similar to selector, but platform parameters are optional. Returns null if the current platform's value is not provided or if the platform is unidentified.
  • Device Selector (deviceSelector): Select a value based on device type (mobile, desktop, web). All device type parameters are required. Throws UnsupportedError if the device type is not identified.
  • Optional Device Selector (optionalDeviceSelector): Similar to deviceSelector, but device type parameters are optional. Returns null if the current device type's value is not provided or if the device type is unidentified.
  • OrElse Selector (selectOrElse): Provides a fallback orElse value if the current platform's value is not provided.
  • Query (isMobile, isDesktop): Convenient getters to check if the current device is mobile or desktop.

Usage

Basic selector (selector)

Use selector when you need to provide a value for every supported platform.

import 'package:selector/selector.dart';

String message = selector(
      web: 'Hello Web!',
      android: 'Hello Android!',
      ios: 'Hello iOS!',
      fuchsia: 'Hello Fuchsia!',
      linux: 'Hello Linux!',
      macos: 'Hello macOS!',
      windows: 'Hello Windows!',
);
print(message); // e.g., "Hello Android!" on an Android device
Optional selector (optionalSelector)

Use optionalSelector when you only need to provide values for a subset of platforms. If the current platform's value is not provided, it returns null.

import 'package:selector/selector.dart';

String? specialMessage = optionalSelector(
      android: 'Special message for Android!',
      ios: 'Special message for iOS!',
);
print(specialMessage); // "Special message for Android!" on Android, null on macOS
Device selector (deviceSelector)

Use deviceSelector to differentiate between mobile, desktop, and web environments.

import 'package:selector/selector.dart';

String deviceType = deviceSelector(
      mobile: 'This is a mobile device.',
      desktop: 'This is a desktop device.',
      web: 'This is a web browser.',
);
print(deviceType); // e.g., "This is a mobile device." on an iOS phone
Optional Device selector (optionalDeviceSelector)

Similar to deviceSelector, but device type parameters are optional. Returns null if the current device type's value is not provided.

import 'package:selector/selector.dart';

String? specificDeviceMessage = optionalDeviceSelector(
      mobile: 'Mobile specific UI.',
      web: 'Web specific UI.',
);
print(specificDeviceMessage); // "Mobile specific UI." on Android, null on Windows desktop
OrElse selector (androidOrElse, iosOrElse, etc.)

Use these platform-specific orElse functions for direct, explicit choices.

import 'package:selector/selector.dart';

String admobKey = androidOrElse('android-key', 'iOS-key');
String iosPreferredKey = iosOrElse('iOS-key', 'android-key');
String mobileSpecific = mobileOrElse('mobile_value', 'default_value');
String desktopSpecific = desktopOrElse('desktop_value', 'default_value');
String webSpecific = webOrElse('web_value', 'default_value');

Alternatively, use the more flexible selectOrElse for multiple platform options:

import 'package:selector/selector.dart

String apiKey = selectOrElse(
      android: 'YOUR_ANDROID_API_KEY',
      ios: 'YOUR_IOS_API_KEY',
      orElse: 'DEFAULT_API_KEY', // Used if platform is not Android or iOS
);
print(apiKey); // "YOUR_ANDROID_API_KEY" on Android, "DEFAULT_API_KEY" on Windows
Query

Convenient getters to check the device type.

import 'package:selector/selector.dart';

print('isDesktop: $isDesktop'); // true if on Windows, Linux, macOS
print('isMobile: $isMobile');   // true if on Android, iOS, Fuchsia

カテゴリー

ソースリポジトリ

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

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