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

responsive_sizer のカバー
パッケージ詳細v3.3.1

responsive_sizer

Responsive Sizer は、ヘルパー小道具と拡張機能を提供することで、応答性のあるレイアウトの実装を支援します。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
1.6万
いいね数
596
Pub ポイント
160

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

flutter pub add responsive_sizer

パッケージ概要

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

Responsive Sizer は、さまざまな画面サイズおよび向きでレスポンシブレイアウトを作成することを容易にするFlutterパッケージです。デバイスの画面寸法に基づいてフォント、サイズ、余白を簡単にスケーリングできるヘルパーウィジェットと拡張メソッドを提供します。`vs`(垂直サイズ)および`hs`(水平サイズ)といった論理単位を使用することで、さまざまなデバイスで一貫したUI表示を保証できます。このパッケージは既存のFlutterプロジェクトにスムーズに統合でき、Android、iOS、Web、macOS、Windows、Linuxなどの主要プラットフォームをすべてサポートしています。

用途

  • クロスデバイス対応のレスポンシブUIの構築
  • テキストとレイアウト要素の動的スケーリング
  • 複数の画面サイズに対応するアダプティブデザインの作成
  • デバイス間で一貫した間隔を確保する
  • 複雑な計算なしでレスポンシブデザインを簡素化

主な機能

  • 使いやすい拡張メソッド
  • vsおよびhs単位のサポート
  • 組み込みの応答性ウィジェット
  • クロスプラットフォーム互換性
  • 最小限のボイラープレートコード
  • 自動スクリーンサイズ検出

適している対象

  • マルチプラットフォームアプリを開発する開発者
  • 応答性のデザインを重視するチーム
  • 動的スケーリングを必要とするプロジェクト
  • 初心者が応答性のあるFlutterを学ぶ
  • さまざまなデバイス画面をターゲットにするアプリ

注意事項

  • 既存のレイアウト値の初期調整が必要になる場合があります
  • 一貫したデザインシステムと併用するのが最適です
  • 非常にカスタム化された、または非一様なスケーリングのニーズには適していません
  • パフォーマンスへの影響は無視できるが、低スペックデバイスでテストするべきです
  • レスポンシブデザインの原則を理解する必要がある

元の README

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

Responsive Sizer

Responsive Sizer helps implement a responsive layout by providing helper widgets and extensions.

Responsive Image

Responsive Image

Content

Installation

Add responsive_sizer to pubspec.yaml

dependencies:
  responsive_sizer: ^3.3.1

Usage

Import the Package

import 'package:responsive_sizer/responsive_sizer.dart';

Wrap MaterialApp with ResponsiveSizer widget

ResponsiveSizer( 
  builder: (context, orientation, screenType) {
    return MaterialApp(
      home: HomePage(),
    );
  },
);

Widget Size

Container(
  width: Adaptive.w(20),    // This will take 20% of the screen's width
  height: 30.5.h     // This will take 30.5% of the screen's height
)

Font size

Text(
  'Responsive Sizer', 
  style: TextStyle(fontSize: 15.dp), 
  // 15.sp can also be used instead of .dp
  // To know their differences, check #FAQ
)

Orientation

If you want to support both portrait and landscape orientations

Device.orientation == Orientation.portrait
  ? Container(   // Widget for Portrait
      width: 100.w,
      height: 20.5.h,
   )
  : Container(   // Widget for Landscape
      width: 100.w,
      height: 12.5.h,
   )

ScreenType

If you want the same layout to look different in tablet and mobile, use the Device.screenType method:

Device.screenType == ScreenType.tablet
  ? Container(   // Widget for Tablet
      width: 100.w,
      height: 20.5.h,
   )
  : Container(   // Widget for Mobile
      width: 100.w,
      height: 12.5.h,
   )

*Device.ScreenType can not be Desktop unless maxTabletWidth is set

Parameters

ResponsiveSizer

  • maxMobileWidth - Maximum width of a mobile device (If the device's width is larger than this, it will be categorized as a tablet) - Default value: 599
  • maxTabletWidth - Maximum width of a tablet device (If the device's width is larger than this, it will be categorized as a desktop) - Optional: enables Desktop ScreenType if enabled

Extensions

  • Adaptive.h() or .h - Calculated percentage of the device's height (40.h -> 40% of device's height)
  • Adaptive.w() or .w - Calculated percentage of the device's width (40.w -> 40% of device's width)
  • Adaptive.sp() or .sp - Calculated sp based on the device's pixel density and aspect ratio (See FAQ)
  • Adaptive.dp() or .dp - Calculated dp based on the device's pixel density (See FAQ)
*Note: Only use .sh and .sw if you want height and width to depend on the device's available height and width after applying SafeArea. Use .h and .w by default.
  • Adaptive.sh() or .sh - Calculated percentage of the remaining device's height after applying SafeArea
  • Adaptive.sw() or .sw - Calculated percentage of the remaining device's width after applying SafeArea

  • Device.boxConstraints - BoxConstraints of the device
  • Device.orientation - Screen Orientation of the device (portrait or landscape)
  • Device.screenType - Screen type of the device (mobile or tablet)
  • Device.aspectRatio - Aspect ratio of the device
  • Device.pixelRatio - Pixel density ratio of the device

  • Adaptive.cm() or .cm - The respective value in value in centimeters
  • Adaptive.mm() or .mm - The respective value in value in millimeters
  • Adaptive.Q() or .Q - The respective value in quarter-millimeters
  • Adaptive.inches() or .inches - The respective value in inches
  • Adaptive.pc() or .pc - The respective value in picas (1/6th of 1 inch)
  • Adaptive.pt() or .pt - The respective value in points (1/72th of 1 inch)
  • Adaptive.px() or .px - The respective value in pixels

Take Note

You need to import responsive_sizer package in order to access number.h, number.w, number.dp, and number.sp

Auto import in VSCode and Android Studio doesn't work for dart extension methods. Typing 10.h would not bring up auto import suggestion for this package

One workaround is to type Device so that the auto import suggestion would show up:

import 'package:responsive_sizer/responsive_sizer.dart';

FAQ

What is the difference between .sp and .dp?

.dp is supposedly calculated see below based on Material Design's dp calculation while.sp is calculated based on the device's pixel density and aspect ratio

Why is dp not calculated using the device's screen density?

Since there is no way to obtain a device's physical width in inches, we could not calculate for screen density. Material Design's screen density calculation involves a device's physical width in inches. As an alternative, dp is calculated using the device's pixel ratio.

Community Support

If you have any suggestions or issues, feel free to open an issue

If you would like to contribute, feel free to create a PR

カテゴリー

ソースリポジトリ

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