Line data Source code
1 : import 'package:folly_fields/util/decimal.dart';
2 :
3 : ///
4 : ///
5 : ///
6 : class FollyValidators {
7 : ///
8 : ///
9 : ///
10 1 : static String? decimalGTEZero(
11 : Decimal? decimal, {
12 : String msg = 'O valor deve ser igual ou maior que zero.',
13 : }) =>
14 2 : decimal != null && decimal.doubleValue >= 0 ? null : msg;
15 :
16 : ///
17 : ///
18 : ///
19 1 : static String? decimalGTZero(
20 : Decimal? decimal, {
21 : String msg = 'O valor deve ser maior que zero.',
22 : }) =>
23 2 : decimal != null && decimal.doubleValue > 0 ? null : msg;
24 :
25 : ///
26 : ///
27 : ///
28 1 : static String? decimalLTZero(
29 : Decimal? decimal, {
30 : String msg = 'O valor deve ser menor que zero.',
31 : }) =>
32 2 : decimal != null && decimal.doubleValue < 0 ? null : msg;
33 :
34 : ///
35 : ///
36 : ///
37 1 : static String? decimalLTEZero(
38 : Decimal? decimal, {
39 : String msg = 'O valor deve ser igual ou menor que zero.',
40 : }) =>
41 2 : decimal != null && decimal.doubleValue <= 0 ? null : msg;
42 :
43 : ///
44 : ///
45 : ///
46 1 : static String? stringNotEmpty(
47 : String? string, {
48 : String msg = 'O campo não pode ser vazio.',
49 : }) =>
50 1 : string != null && string.isNotEmpty ? null : msg;
51 :
52 : ///
53 : ///
54 : ///
55 1 : static String? stringNotBlank(
56 : String? string, {
57 : String msg = 'O campo deve ser preenchido.',
58 : }) =>
59 2 : string != null && string.trim().isNotEmpty ? null : msg;
60 :
61 : ///
62 : ///
63 : ///
64 1 : static String? stringNullNotEmpty(
65 : String? string, {
66 : String msg = 'Informe um valor ou deixe vazio.',
67 : }) =>
68 1 : string == null || string.isNotEmpty ? null : msg;
69 :
70 : ///
71 : ///
72 : ///
73 1 : static String? stringNullNotBlank(
74 : String? string, {
75 : String msg = 'Informe um valor ou deixe em branco.',
76 : }) =>
77 2 : string == null || string.trim().isNotEmpty ? null : msg;
78 :
79 : ///
80 : ///
81 : ///
82 1 : static String? notNull(
83 : dynamic value, {
84 : String msg = 'O campo não pode ser nulo.',
85 : }) =>
86 : value == null ? msg : null;
87 :
88 : ///
89 : ///
90 : ///
91 1 : static String? notEmpty(
92 : dynamic value, {
93 : String msg = 'O campo não pode ser vazio.',
94 : }) {
95 : if (value == null) {
96 : return msg;
97 1 : } else if (value is Iterable) {
98 1 : if (value.isEmpty) {
99 : return msg;
100 : }
101 1 : } else if (value is Map) {
102 1 : if (value.isEmpty) {
103 : return msg;
104 : }
105 : } else {
106 2 : return value.toString().isEmpty ? msg : null;
107 : }
108 :
109 : return null;
110 : }
111 :
112 : ///
113 : ///
114 : ///
115 1 : static String? notBlank(
116 : dynamic value, {
117 : String msg = 'O campo deve ser preenchido.',
118 : }) {
119 : if (value == null) {
120 : return msg;
121 1 : } else if (value is Iterable) {
122 1 : if (value.isEmpty) {
123 : return msg;
124 : }
125 2 : if (value.length == 1) {
126 5 : if (value.first == null || value.first.toString().trim().isEmpty) {
127 : return msg;
128 : }
129 : }
130 1 : } else if (value is Map) {
131 1 : if (value.isEmpty) {
132 : return msg;
133 : }
134 2 : if (value.length == 1) {
135 2 : if (value.keys.first == null ||
136 5 : value.keys.first.toString().trim().isEmpty) {
137 : return msg;
138 : }
139 : }
140 : } else {
141 3 : return value.toString().trim().isEmpty ? msg : null;
142 : }
143 :
144 : return null;
145 : }
146 :
147 : ///
148 : ///
149 : ///
150 1 : static String? intGTEZero(
151 : int? value, {
152 : String msg = 'O valor deve ser igual ou maior que zero.',
153 : }) =>
154 2 : (value ?? -1) >= 0 ? null : msg;
155 :
156 : ///
157 : ///
158 : ///
159 1 : static String? intGTZero(
160 : int? value, {
161 : String msg = 'O valor deve ser maior que zero.',
162 : }) =>
163 2 : (value ?? -1) > 0 ? null : msg;
164 :
165 : ///
166 : ///
167 : ///
168 1 : static String? intLTZero(
169 : int? value, {
170 : String msg = 'O valor deve ser menor que zero.',
171 : }) =>
172 1 : (value ?? 1) < 0 ? null : msg;
173 :
174 : ///
175 : ///
176 : ///
177 1 : static String? intLTEZero(
178 : int? value, {
179 : String msg = 'O valor deve ser igual ou menor que zero.',
180 : }) =>
181 1 : (value ?? 1) <= 0 ? null : msg;
182 :
183 : ///
184 : ///
185 : ///
186 1 : static String? intNullGTEZero(
187 : int? value, {
188 : String msg = 'O valor deve ser nulo, igual ou maior que zero.',
189 : }) =>
190 1 : (value == null || value >= 0) ? null : msg;
191 :
192 : ///
193 : ///
194 : ///
195 1 : static String? intNullGTZero(
196 : int? value, {
197 : String msg = 'O valor deve ser nulo ou maior que zero.',
198 : }) =>
199 1 : (value == null || value > 0) ? null : msg;
200 :
201 : ///
202 : ///
203 : ///
204 1 : static String? intNullLTZero(
205 : int? value, {
206 : String msg = 'O valor deve ser nulo ou menor que zero.',
207 : }) =>
208 1 : (value == null || value < 0) ? null : msg;
209 :
210 : ///
211 : ///
212 : ///
213 1 : static String? intNullLTEZero(
214 : int? value, {
215 : String msg = 'O valor deve ser nulo, igual ou menor que zero.',
216 : }) =>
217 1 : (value == null || value <= 0) ? null : msg;
218 : }
|