Formz는 폼 표현과 검증을 위한 통합적이고 일반적인 접근 방식을 제공하는 Dart 패키지입니다. 입력, 검증 규칙, 오류 메시지를 처리하기 위한 일관된 구조를 제공함으로써 폼 상태 관리를 간소화합니다. 단순성과 재사용성을 고려하여 설계되었으며, 최소한의 봐일러플레이트 코드로 폼을 만들 수 있도록 하면서도 플랫폼 간 타입 안전성과 확장성을 유지합니다. Flutter 애플리케이션에 원활하게 통합되며, Android, iOS, Web, macOS, Windows, Linux 등 주요 모든 플랫폼을 지원합니다.
A unified form representation in Dart.
Formz aims to simplify form representation and validation in a generic way.
Create a FormzInput
import'package:formz/formz.dart';
// Define input validation errorsenumNameInputError { empty }
// Extend FormzInput and provide the input type and error type.classNameInputextendsFormzInput<String, NameInputError> {
// Call super.pure to represent an unmodified form input.constNameInput.pure() : super.pure('');
// Call super.dirty to represent a modified form input.constNameInput.dirty({String value = ''}) : super.dirty(value);
// Override validator to handle validating a given input value.@overrideNameInputError? validator(String value) {
return value.isEmpty ? NameInputError.empty : null;
}
}
For cases where the validator method has an expensive implementation, consider using the FormzInputErrorCacheMixin mixin to cache the error result and improve performance.