super_validation

Creator: coderz1093

Last updated:

0 purchases

super_validation Image
super_validation Images

Languages

Categories

Add to Cart

Description:

super validation

Package to controll TextFormField from bloc
Usage #
In test_bloc.dart
final SuperValidation validation = SuperValidation(validationFunc: (value) {
if (value == null || value.isEmpty) {
return 'Please enter some text';
}
return null;
});
copied to clipboard
for int or num
final SuperValidationInt intValidation = SuperValidationInt.minMax(
min: 0,
max: 10,
minMessage: 'Min 0',
maxMessage: 'Max 10',
);
final SuperValidationNum numValidation = SuperValidationNum.minMax(
min: 0,
max: 10,
minMessage: 'Min 0',
maxMessage: 'Max 10',
);
copied to clipboard
for enum
enum TestEnum { one, two, three }
final SuperValidationEnum<TestEnum> enumValidation = SuperValidationEnum()
..validation = 'Выберите один из пунктов';

//in test_page.dart
DropDownEnumField<TestEnum>(
superValidation: context.read<TestBloc>().enumValidation,
items: TestEnumM.mapName,
autovalidateMode: AutovalidateMode.always,
),
copied to clipboard
In test_page.dart
TextFieldSuperValidation(
superValidation: context.read<TestBloc>().validation,
autovalidateMode: AutovalidateMode.onUserInteraction,
);
copied to clipboard
If u want set custom icon or suffix to error decoration
TextFieldSuperValidationWithIcon(
superValidation: superValidation,
errorIcon: Icon(Icons.error, color: Colors.red, size: 20),
errorSuffix: Icon(Icons.error, color: Colors.red, size: 20),
);
copied to clipboard
Also u can enforse set Validation text with
validation.validate('Validation Text');
copied to clipboard
And set text of textField
validation.text = event.text;
copied to clipboard
And builder for buttons
SuperValidationBuilder(
superValidation: context.read<TestBloc>().validation,
builder: (context, validation, isValid) {
return TextButton(
onPressed: isValid
? () {
print('Test');
}
null,
child: Text('Test'));
});
copied to clipboard
Also u can use SuperValidationSimpleMultyBuilder for multy validation button
SuperValidationSimpleMultyBuilder(
builder: (context, isValid) {
return ElevatedButton(
onPressed: isValid
? () {
print('onPressed');
}
: null,
child: Text('Validate'),
);
},
superValidation: [
context.read<TestBloc>().numberValidation,
context.read<TestBloc>().stringValidation,
],
)
copied to clipboard
And SuperValidationMultyBuilder for multy validation button with custom validation text
SuperValidationMultyBuilder(
builder: (context, validation, isValid) {
return Text(
validation.isEmpty ? 'Valid' : validation.toString(),
style: TextStyle(
color: isValid ? Colors.green : Colors.red,
),
);
},
superValidation: {
'string': context.read<TestBloc>().stringValidation,
'number': context.read<TestBloc>().numberValidation,
},
)
copied to clipboard
If u need Custom logic for example in bloc use SuperValidationStream
final SuperValidationStream<String> superValidationStream =
SuperValidationStream<String>(
superValidationMap: {
'string': context.read<TestBloc>().stringValidation,
'number': context.read<TestBloc>().numberValidation,
},
);
superValidationStream.streamValidation.listen((event) {
print('Validations: $event');
});
copied to clipboard
Custom Validation Example
class SuperValidationFile extends SuperValidationA {
SuperValidationFile() {
validate();
}
void validate() {
if (files.length != 2) {
validation = 'You need to add 2 files';
} else {
validation = null;
}
}

final StreamController<String?> _streamController =
StreamController.broadcast();
@override
Stream<bool> get streamIsValid =>
_streamController.stream.map((event) => event == null);

@override
Stream<String?> get streamValidation => _streamController.stream;
String? _validation;
@override
String? get validation => _validation;
set validation(String? value) {
_validation = value;
_streamController.add(value);
}

List<FileManaged> _files = [];
List<FileManaged> get files => [..._files];
void addFile(FileManaged file) {
_files.add(file);
validate();
}

void removeFile(FileManaged file) {
_files.remove(file);
validate();
}
}
copied to clipboard
SuperValidationEnumBuilder - stream builder for enum(could be any thing)
SuperValidationEnumBuilder<String>(
superValidation: superValidation,
builder: (context, value) {
return ListView(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
children: values
.map((e) => CheckboxListTile(
title: Text(e),
value: value == e,
onChanged: (value) {
if (value == true) {
superValidation.value = e;
}
},
))
.toList(),
);
});
copied to clipboard
SuperValidationTextFieldListener - stream builder enum for textfield
SuperValidationTextFieldListener<String>(
transformer: (val) => val,
readOnly: true,
superValidation:
context.read<TestBloc>().stringEnumValidation),
copied to clipboard
transformer - convert enum to string
superValidation - SuperValidationEnum

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.