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

패키지 상세v1.1.0

universal_platform

웹과 데스크톱, 모바일 모두에서 작동하는 dart:io.Platform 클래스의 대체품입니다. 뷰/모델 계층에서 플랫폼 확인을 쉽게 할 수 있습니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
181만
좋아요
313
Pub 점수
150

패키지 설치

flutter pub add universal_platform

패키지 개요

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

universal_platform 패키지는 Dart의 Platform 클래스에 대한 크로스플랫폼 대체를 제공하여 웹, 모바일 및 데스크톱 환경에서 일관된 플랫폼 감지를 가능하게 합니다. 개발자는 뷰나 모델과 같은 비즈니스 로직 계층에서 플랫폼 확인을 수행할 수 있으며, 플랫폼별 구현에 의존하지 않습니다. 이는 타겟 런타임에 관계없이 신뢰할 수 있는 동작을 보장하며, 기반 플랫폼에 따라 코드를 조정해야 하는 경우 코드를 단순화합니다.

사용 사례

  • 크로스플랫폼 앱 개발
  • 플랫폼별 UI/동작 로직
  • 다중 플랫폼 간 공유 비즈니스 로직
  • 여러 대상에서 테스트하기
  • 플랫폼 전용 가져오기 피하기

주요 기능

  • 통합 플랫폼 감지
  • 웹, 안드로이드, iOS, macOS, Windows, Linux에서 작동
  • 조건부 가져오기 필요 없음
  • dart:io.Platform와 유사한 간단한 API
  • isAndroid, isIOS, isWeb 등과 같은 것을 지원합니다.

적합한 대상

  • 다중 플랫폼을 대상으로 하는 개발자
  • 일관된 플랫폼 확인이 필요한 앱
  • 플랫폼별 코드 중복을 피하는 팀
  • 다중 플랫폼 간에 공유 로직을 사용하는 프로젝트
  • 신뢰할 수 있는 웹 지원이 필요한 사용자

고려 사항

  • dart:io.Platform 대신 명시적 임포트가 필요합니다
  • 모든 특수 플랫폼 기능을 커버하지 않을 수 있습니다
  • 기본 플랫폼 식별에 국한됨
  • dart:io 기능의 완전한 대체물이 아님
  • 외부 종속성 관리에 의존

원본 README

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

Universal Platform - A Web-safe Platform class

pub package

Currently, if you include the dart.io.Platform anywhere in your code, your app will throw the following error on Web:

Unsupported operation: Platform._operatingSystem

With this plugin you can perform platform detection on all platforms, including Web, without errors.

🔨 Installation

dependencies:
  universal_platform: ^1.0.0+1
⚙ Import

Remove any usages of dart.io.Platform, and replace with this:

import 'package:universal_platform/universal_platform.dart';

🕹️ Usage

This acts as a drop-in replacement for dart.io.Platform, with a different name for improved clarity.

//This will explode on Web
bool isIos = Platform.isIOS;

//This will not :)
bool isIos = UniversalPlatform.isIOS;
bool isWeb = UniversalPlatform.isWeb;

🐞 Bugs/Requests

If you encounter any problems feel open an issue. If you feel the library is missing a feature, please raise a ticket on Github and we'll look into it. Pull request are also welcome.

📃 License

MIT License

카테고리

소스 저장소

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