Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ class AppHome extends StatelessWidget {
numericCharCount: 3,
specialCharCount: 1,
normalCharCount: 3,
width: 400,
height: 200,
onSuccess: () {
print("MATCHED");
ScaffoldMessenger.of(context).showSnackBar(new SnackBar(
Expand Down
13 changes: 8 additions & 5 deletions lib/Components/ValidationBarWidget.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import 'package:flutter/material.dart';
import 'package:flutter_pw_validator/Utilities/SizeConfig.dart';

/// ValidationBarWidget that represent style of each one of them and shows under the TextField
class ValidationBarComponent extends StatelessWidget {
final Color color;
final double? thickness;

ValidationBarComponent({required this.color});
ValidationBarComponent({
required this.color,
this.thickness
});

@override
Widget build(BuildContext context) {
return Expanded(
child: new Container(
/// We Can set, width: double.maxFinite,
margin: EdgeInsets.symmetric(horizontal: SizeConfig.width! * 0.005),
height: SizeConfig.width! * 0.015,
margin: EdgeInsets.symmetric(horizontal: 2),
height: thickness ?? 4,
decoration: new BoxDecoration(
color: color,
borderRadius: BorderRadius.all(Radius.circular(SizeConfig.width!))),
borderRadius: BorderRadius.all(Radius.circular(100))),
),
);
}
Expand Down
42 changes: 24 additions & 18 deletions lib/Components/ValidationTextWidget.dart
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
import 'package:flutter/material.dart';
import 'package:flutter_pw_validator/Utilities/SizeConfig.dart';

/// ValidationTextWidget that represent style of each one of them and shows as list of condition that you want to the app user
class ValidationTextWidget extends StatelessWidget {
final Color color;
final bool? success;
final Color defaultColor;
final Color successColor;
final Color failureColor;
final String text;
final int? value;
final TextStyle? textStyle;

ValidationTextWidget(
{required this.color, required this.text, required this.value});
ValidationTextWidget({
required this.success,
required this.text,
required this.value,
required this.defaultColor,
required this.successColor,
required this.failureColor,
this.textStyle
});

@override
Widget build(BuildContext context) {
return new Row(
Color color = success == null ? defaultColor : success! ? successColor : failureColor;
return Row(
children: [
new Container(
width: SizeConfig.width! * 0.03,
height: SizeConfig.width! * 0.03,
child: new CircleAvatar(
backgroundColor: color,
),
Icon(
success == null || success! ? Icons.check : Icons.close,
size: 20,
color: color,
),
Padding(
padding: EdgeInsets.only(left: SizeConfig.width! * 0.03),
child: new Text(
text.replaceFirst("-", value.toString()),
style:
new TextStyle(fontSize: SizeConfig.width! * 0.04, color: color),
),
const SizedBox(width: 10),
Text(
text.replaceFirst("-", value.toString()),
style: (textStyle ?? Theme.of(context).textTheme.bodyMedium)?.copyWith(color: color)
)
],
);
Expand Down
7 changes: 0 additions & 7 deletions lib/Utilities/SizeConfig.dart

This file was deleted.

69 changes: 35 additions & 34 deletions lib/flutter_pw_validator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ library flutter_pw_validator;
import 'package:flutter/material.dart';
import 'package:flutter_pw_validator/Utilities/ConditionsHelper.dart';
import 'package:flutter_pw_validator/Utilities/Validator.dart';

import 'Components/ValidationBarWidget.dart';
import 'Components/ValidationTextWidget.dart';
import 'Resource/MyColors.dart';
import 'Resource/Strings.dart';
import 'Utilities/SizeConfig.dart';

class FlutterPwValidator extends StatefulWidget {
final int minLength,
Expand All @@ -18,16 +16,19 @@ class FlutterPwValidator extends StatefulWidget {
numericCharCount,
specialCharCount;
final Color defaultColor, successColor, failureColor;
final double width, height;
final Function onSuccess;
final Function? onFail;
final TextEditingController controller;
final FlutterPwValidatorStrings? strings;
final TextStyle? textStyle;
final EdgeInsets? padding;
final double? validationBarThickness;
final bool showValidationBar;
final bool showValidationText;
final Key? key;

FlutterPwValidator(
{required this.width,
required this.height,
{
required this.minLength,
required this.onSuccess,
required this.controller,
Expand All @@ -41,11 +42,13 @@ class FlutterPwValidator extends StatefulWidget {
this.failureColor = MyColors.red,
this.strings,
this.onFail,
this.key}) {
//Initial entered size for global use
SizeConfig.width = width;
SizeConfig.height = height;
}
this.textStyle,
this.padding,
this.validationBarThickness,
this.showValidationBar = true,
this.showValidationText = true,
this.key
});

@override
State<StatefulWidget> createState() => new FlutterPwValidatorState();
Expand Down Expand Up @@ -164,35 +167,32 @@ class FlutterPwValidatorState extends State<FlutterPwValidator> {

@override
Widget build(BuildContext context) {
return new Container(
width: SizeConfig.width,
height: widget.height,
child: new Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
new Flexible(
flex: 3,
child: new Row(
return SizedBox(
width: MediaQuery.of(context).size.width,
child: Padding(
padding: widget.padding ?? EdgeInsets.zero,
child: Column(
children: [
if(widget.showValidationBar || widget.showValidationText) const SizedBox(height: 2),
if(widget.showValidationBar) Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Iterate through the conditions map values to check if there is any true values then create green ValidationBarComponent.
for (bool value in _conditionsHelper.getter()!.values)
if (value == true)
new ValidationBarComponent(color: widget.successColor),
ValidationBarComponent(color: widget.successColor, thickness: widget.validationBarThickness),

// Iterate through the conditions map values to check if there is any false values then create red ValidationBarComponent.
for (bool value in _conditionsHelper.getter()!.values)
if (value == false)
new ValidationBarComponent(color: widget.defaultColor)
ValidationBarComponent(color: widget.defaultColor)
],
),
),
new Flexible(
flex: 7,
child: new Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,

if(widget.showValidationBar && widget.showValidationText) const SizedBox(height: 10),
if(widget.showValidationText) Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Column(
//Iterate through the condition map entries and generate new ValidationTextWidget for each item in Green or Red Color
children: _conditionsHelper.getter()!.entries.map((entry) {
int? value;
Expand All @@ -209,17 +209,18 @@ class FlutterPwValidatorState extends State<FlutterPwValidator> {
if (entry.key == widget.translatedStrings.specialCharacters)
value = widget.specialCharCount;
return new ValidationTextWidget(
color: _isFirstRun
? widget.defaultColor
: entry.value
? widget.successColor
: widget.failureColor,
success: _isFirstRun ? null : entry.value,
defaultColor: widget.defaultColor,
successColor: widget.successColor,
failureColor: widget.failureColor,
text: entry.key,
textStyle: widget.textStyle,
value: value,
);
}).toList()),
)
],
)
],
),
),
);
}
Expand Down
Loading