一键导入
contributing-brasil-fields
How to maintain, fix bugs, or add new features (e.g. formatters, validators) to the open-source `brasil_fields` package repository.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
How to maintain, fix bugs, or add new features (e.g. formatters, validators) to the open-source `brasil_fields` package repository.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | contributing_brasil_fields |
| description | How to maintain, fix bugs, or add new features (e.g. formatters, validators) to the open-source `brasil_fields` package repository. |
brasil_fields PackageThe brasil_fields repository is structured to provide Brazilian standard data formats, validators, and generators to the Flutter ecosystem. When you are asked to maintain this package, fix a bug, or add a new format, you should follow these guidelines.
Understand where code lives before making modifications:
lib/src/formatters/): All classes that extend TextInputFormatter (to modify user input in real-time) belong here.lib/src/validators/): Classes that validate data (e.g., verifying CPF checksums). Note: This differs from the static methods in UtilBrasilFields.lib/src/modelos/): Static data collections (lists and maps) like States (Estados), Months (Meses), and Regions (Regioes).lib/src/util/): Static utility classes like UtilBrasilFields (for generating/formatting strings programmatically) and UtilData (for dates).lib/brasil_fields.dart): This is the entry point of the package. Any new formatter, validator, model, or utility created in src/ must be exported here.If requested to add a new document or currency formatter:
lib/src/formatters/ (e.g. meu_novo_formatter.dart).extend TextInputFormatter and override formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue).oldValue.text.length > newValue.text.length), and pasting long strings.FilteringTextInputFormatter.digitsOnly along with it. If it accepts letters, it is alphanumeric and requires special handling.export 'src/formatters/meu_novo_formatter.dart'; inside lib/brasil_fields.dart.The brasil_fields package maintains high test coverage (enforced by Codecov). You must write tests for any new code or bug fixes.
test/ directory, mimicking the structure of lib/ (e.g. test/src/formatters/meu_novo_formatter_test.dart).formatEditUpdate method. Verify both the newValue.text string and the newValue.selection.baseOffset (cursor position).import 'package:flutter_test/flutter_test.dart';
import 'package:brasil_fields/brasil_fields.dart';
void main() {
test('MeuNovoFormatter deve formatar corretamente', () {
final formatter = MeuNovoFormatter();
const oldValue = TextEditingValue(text: '');
const newValue = TextEditingValue(
text: '12', selection: TextSelection.collapsed(offset: 2));
final result = formatter.formatEditUpdate(oldValue, newValue);
expect(result.text, '1.2'); // Ensure custom format logic is applied
expect(result.selection.baseOffset, 3); // Ensure cursor moved
});
}
analysis_options.yaml.flutter_lints rules correctly.///) explaining its purpose and return value, specifically if updating UtilBrasilFields or adding a new formatter.