super_validation 0.0.5 copy "super_validation: ^0.0.5" to clipboard
super_validation: ^0.0.5 copied to clipboard

outdated

Validation For bloc

Package to controll TextFormField from bloc

Usage #

In test_bloc.dart

final SuperValidation validation = SuperValidation((value) {
    if (value == null || value.isEmpty) {
      return 'Please enter some text';
    }
    return null;
});

In test_page.dart

TextFieldSuperValidation(
    superValidation: context.read<TestBloc>().validation,
    autovalidateMode: AutovalidateMode.onUserInteraction,
);

Also u can enforse set Validation text with

validation.validate('Validation Text');

And set text of textField

validation.text = event.text;

And builder for buttons

SuperValidationBuilder(
    superValidation: context.read<TestBloc>().validation,
    builder: (context, validation, isValid) {
        return TextButton(
            onPressed: isValid
                ? () {
                    print('Test');
                    }
                 null,
            child: Text('Test'));
        });

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,
    ],
)

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,
    },
)

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');
});

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();
  }
}
1
likes
0
pub points
29%
popularity

Publisher

unverified uploader

Validation For bloc

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

async, equatable, flutter, meta

More

Packages that depend on super_validation