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

fitted_text_field_container 표지
패키지 상세v2.0.0

fitted_text_field_container

Material TextField의 텍스트 값을 자동으로 맞추어 크기가 조절되는 컨테이너입니다.

30일 다운로드
45
좋아요
27
Pub 점수
70

패키지 설치

flutter pub add fitted_text_field_container

패키지 개요

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

텍스트 내용에 맞춰 동적으로 크기가 조정되는 컨테이너 안에 Material TextField를 감싸는 Flutter 패키지입니다. 사용자가 입력할 때 컨테이너의 치수는 자동으로 조정되어 수동 크기 지정 없이 시각적 일관성을 유지합니다. 공간 효율성과 레이아웃 반응성에 중점을 두는 폼 및 입력 필드에 이상적입니다. 이 패키지는 가볍고 기존의 Flutter UI와 원활하게 통합됩니다.

사용 사례

  • 동적 폼 레이아웃
  • 반응형 입력 컨테이너
  • 자동 크기 조정 텍스트 필드
  • 변동하는 텍스트 길이를 가진 깔끔한 UI 디자인
  • 제한된 공간 내 입력 필드

주요 기능

  • 자동 컨테이너 크기 조정
  • Material TextField 통합
  • 수동 폭/높이 설정 없음
  • 경량이고 간단함
  • Flutter와의 원활한 호환성

적합한 대상

  • 반응형 입력 컨테이너가 필요한 개발자
  • 깔끔한 레이아웃에 집중하는 UI 디자이너
  • 변수 텍스트 입력을 가진 폼 빌더
  • 최소한의 뼈대 코드가 필요한 프로젝트

고려 사항

  • 텍스트 콘텐츠만 가능
  • 다중 줄 텍스트를 지원하지 않습니다
  • 내장된 검증 또는 마스킹 없음
  • 복잡한 폼 로직에 적합하지 않습니다
  • 부모 위젯 제약 조건에 의존합니다

원본 README

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

Fitted TextField Container

A Container that automatically resizes it's width to fit the containing TextField's text value.

Read the short blog: https://medium.com/@huyffs/fitted-textfield-container-for-flutter-c9c63644441c

Usage

FittedTextFieldContainer
Param Type Default Description
child TextField * required The TextField to fit
calculator CalculateFunction FittedTextFieldCalculator.fitVisible A function to calculate the width. The default function fits the visible content & decorations (i.e. it collapses to the content/label's width when hint text disappears)
builder Widget Function(BuildContext context, TextField child) null A builder that can be used to build complex layouts. The child TextField is provided to the build function
Example
FittedTextFieldContainer(
    child: TextField(
        controller: someTextEditingController,
        textAlign: TextAlign.right,
        decoration: InputDecoration(
            prefixText: "£",
            labelText: "Amount",
        ),
    ),
)
AnimatedFittedTextFieldContainer

All params from FittedTextFieldContainer plus the following

Param Type Default Description
growCurve Curve Curves.easeOutCirc The curve to use in the grow animation
growDuration Duration Duration(milliseconds: 300) Duration to animate the container's width when TextField grows
shrinkCurve Curve Curves.easeInCirc The curve to use in the shrink animation
shrinkDuration Duration Duration(milliseconds: 600) Duration to animate the container's width when TextField shrinks
Example
AnimatedFittedTextFieldContainer(
    growDuration: Duration(milliseconds: 300),
    shrinkDuration: Duration(milliseconds: 600),
    growCurve: Curves.easeOutCirc,
    shrinkCurve: Curves.easeInCirc,
    child: TextField(
        controller: someTextEditingController,
        textAlign: TextAlign.right,
        decoration: InputDecoration(
            prefixText: "£",
            labelText: "Amount",
        ),
    ),
)
FittedTextFieldMeasurer

A class that takes a TextField and TextStyle and returns the following measurements:

  • textField The fitted textfield
  • textStyle The fitted textfield's style or the default style
  • textWidth Width of the text content
  • labelWidth Width of the label
  • hintWidth Width of the hint text
  • fixedWidths Width of fixed elements (prefixText, suffixText, contentPadding and cursorWidth)
CalculateFunction

This function takes measured values and returns a width value.

Signature:
double CalculateFunction(FittedTextFieldMeasurer)
Example:
FittedTextFieldContainer(
    calculator: (m) =>
        m.fixedWidths +
        max(m.labelWidth, max(m.hintWidth, m.textWidth)),
    child: TextField(
        controller: someTextEditingController,
        textAlign: TextAlign.right,
        decoration: InputDecoration(
            hintText: "Width of hint text",
        ),
    ),
);
Predefined functions

A few calculators are provided for common use-cases

  • fitAll fits content, label and hint texts
  • fitVisible fits the visible content & decorations (i.e. it collapses to the content/label's width when hint text disappears)
  • fitVisibleWithPadding(double padding) in addition to fitting visible content it adds a fixed padding value
  • fitVisibleWithRange(double min, double max) in addition to fitting visible content it enforces a minimum and (optional) maximum width
Example:

Fit all

FittedTextFieldContainer(
    calculator: FittedTextFieldCalculator.fitAll,
    child: ...
);

Fit visible with minimum

FittedTextFieldContainer(
    calculator: FittedTextFieldCalculator.fitVisibleWithRange(120),
    child: ...
);

Fit visible with maximum

FittedTextFieldContainer(
    calculator: FittedTextFieldCalculator.fitVisibleWithRange(0, 180),
    child: ...
);
Using the builder
AnimatedFittedTextFieldContainer(
    child: TextField(
        controller: someTextEditingController,
        textAlign: TextAlign.right,
        decoration: InputDecoration(
            labelText: "Twinkle twinkle",
        ),
    ),
    builder: (context, child) => Container(
        child: Stack(
            overflow: Overflow.visible,
            children: <Widget>[
                child,
                Positioned(
                    top: 0,
                    right: -22,
                    child: _aniWholePoundCtl.text.isEmpty
                        ? Icon(Icons.star_border)
                        : Icon(Icons.star, color: Colors.amber),
                ),
            ],
        ),
    ),
)

Contribute

Pull requests are welcome!

Licence

MIT License

Copyright (c) 2020 Huy Dinh

카테고리

소스 저장소

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

아직 데이터가 없습니다.