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

패키지 상세v1.0.7

flexible_wrap

자식 요소를 유연한 래핑 레이아웃으로 정렬하는 위젯으로, 사용 가능한 공간에 따라 확장되면서도 지정된 레이아웃 속성을 유지합니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
972
좋아요
41
Pub 점수
160

패키지 설치

flutter pub add flexible_wrap

패키지 개요

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

유연한 레이아웃에서 자식 위젯들을 정렬하는 플러터 위젯으로, 사용 가능한 공간을 채우기 위해 동적으로 확장하면서도 레이아웃 제약 조건을 유지합니다. 반응형 디자인에 이상적이며 다양한 화면 크기와 방향에 자연스럽게 적응합니다. 사용자 지정 가능한 간격과 정렬을 지원하는 수평 및 수직 레이아웃 모두를 제공합니다. 수동 계산 없이 유연하고 적응형 UI를 만들기에 특히 유용합니다. 성능과 단순성에 중점을 두어 설계되었으며, 기존 플러터 프로젝트에 원활하게 통합됩니다.

사용 사례

  • 반응형 폼 레이아웃
  • 다이나믹 그리드 표시
  • 적응형 카드 배열
  • 유동적 콘텐츠 컨테이너
  • 크로스 플랫폼 UI 디자인

주요 기능

  • 자동 확장 자식
  • 유연한 방향 제어
  • 사용자 정의 간격
  • 반응형 동작
  • Flutter와의 간편한 통합

적합한 대상

  • 반응형 UI를 구축하는 개발자
  • 적응형 레이아웃이 필요한 디자이너
  • 다중 플랫폼을 대상으로 하는 프로젝트
  • 동적 콘텐츠를 가진 앱
  • UI 일관성을 우선시하는 팀

고려 사항

  • 다양한 화면 크기에서 테스트가 필요할 수 있습니다
  • 대규모 자식 수로 인한 성능 영향
  • 기본 레이아웃 속성 외의 사용자 정의는 제한적
  • 고정 크기의 강성 그리드에는 적합하지 않습니다

원본 README

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

support-palestine-banner

FlexibleWrap

Test Demo deployment Pub Monthly Downloads Pub Publisher Pub Version Pub Likes


FlexibleWrap is a Flutter widget that provides an advanced wrap layout with flexible spacing and RTL support. It automatically distributes available space between items in a row, similar to Wrap widget but with additional features

Perfect for implementing uniform grid layouts like product cards, image galleries, or any UI that requires evenly-spaced wrapped items.

Showcase

showcase

Features

  • Dynamic Wrapping: Automatically wraps widgets onto the next line based on the available space.
  • Expanded Items: Expands the items to fill the available space on the row.
  • RTL Support: Provides support for right-to-left text direction, ensuring proper layout and alignment for RTL languages.
  • Customizable Spacing: Control both horizontal and vertical spacing between items
  • One Row Expansion: Option to expand items when they fit in a single row

Note: We currently support only items that have the same width; height direction is not supported yet

Benchmarks: GridView vs. FlexibleWrap

Feature GridView FlexibleWrap
Description A layout that arranges items in a grid format. It automatically distributes available space between items in a row.
Usage Efficient for uniform item sizes. Ideal for dynamic item sizes and wrapping.
Performance Better performance with a builder pattern. Currently does not support a builder; uses children instead.
Screen Recording GridView FlexibleWrap

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  flexible_wrap: ^latest_version

Then run:

$ flutter pub get

Example Demo

Check out the live demo of FlexibleWrap at https://bixat.github.io/flexible_wrap/

Usage

First, import the package:

import 'package:flexible_wrap/flexible_wrap.dart';

Here's a basic example of how to use FlexibleWrap:


class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final spacing = 12.0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: SingleChildScrollView(
        child: FlexibleWrap(
          spacing: spacing,
          runSpacing: spacing,
          textDirection: TextDirection.rtl,
          children: List.generate(20, (int index) {
            return Container(
              height: 100,
              width: 300,
              decoration: BoxDecoration(
                  color: Colors.blue, borderRadius: BorderRadius.circular(8.0)),
              child: const Center(
                child: ListTile(
                  title: Text(
                    "Lorem Ipsum is simply dummy text",
                    style: TextStyle(color: Colors.white),
                    overflow: TextOverflow.ellipsis,
                  ),
                  subtitle: Text(
                    "Lorem Ipsum has been the industry's standard",
                    style: TextStyle(color: Colors.white),
                    overflow: TextOverflow.ellipsis,
                  ),
                  leading: Icon(
                    Icons.insert_emoticon,
                    color: Colors.white,
                    size: 60.0,
                  ),
                  trailing: Icon(
                    Icons.favorite,
                    color: Colors.white,
                  ),
                ),
              ),
            );
          }).toList(),
        ),
      ),
    );
  }
}

Important Implementation Note

When using FlexibleWrap with dynamic dimensions (height, width, or item count), you should add a ValueKey to force widget rebuilds when these properties change:

FlexibleWrap(
  key: ValueKey('$itemHeight-$itemWidth-$itemCount'), // Force rebuild when dimensions change
  spacing: spacing,
  runSpacing: runSpacing,
  isOneRowExpanded: isOneRowExpanded,
  textDirection: isRTL ? TextDirection.rtl : TextDirection.ltr,
  children: [
    // Your widgets here
  ],
)

Why is this needed?

The ValueKey ensures that Flutter recognizes the widget as "changed" when dimensions are updated, forcing a complete rebuild of the render object. This is particularly important when:

  • Child widget dimensions change dynamically
  • The number of children changes
  • Layout properties are modified at runtime

Without the ValueKey, Flutter's widget tree optimization might prevent the render object from properly updating, leading to visual inconsistencies where dimension changes don't immediately reflect in the UI.

Customization

FlexibleWrap offers several customization options to tailor the layout to your needs:

Parameters
Parameter Type Default Description
children List<Widget> Required The widgets to display in the wrap layout
spacing double 0.0 Horizontal space between children
runSpacing double 0.0 Vertical space between runs
textDirection TextDirection null The text direction for RTL support
isOneRowExpanded bool false Whether to expand items when they fit in one row
Common Use Cases
  1. Grid Layout:
FlexibleWrap(
  spacing: 8.0,
  runSpacing: 8.0,
  children: items,
)
  1. RTL Support:
FlexibleWrap(
  spacing: 8.0,
  textDirection: TextDirection.rtl,
  children: items,
)

Contributing

We welcome contributions to FlexibleWrap! Here's how you can help:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Please make sure to update tests and documentation as appropriate.

License

FlexibleWrap is licensed under the MIT License. See the LICENSE file for details.

카테고리

소스 저장소

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

아직 데이터가 없습니다.