LCOV - code coverage report
Current view: top level - validators - mobile_phone_validator.dart (source / functions) Hit Total Coverage
Test: Folly Fields Lines: 14 15 93.3 %
Date: 2023-04-01 18:13:35 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:flutter/services.dart';
       2             : import 'package:folly_fields/util/mask_text_input_formatter.dart';
       3             : import 'package:folly_fields/validators/abstract_validator.dart';
       4             : 
       5             : ///
       6             : ///
       7             : ///
       8             : class MobilePhoneValidator extends AbstractValidator<String> {
       9             :   ///
      10             :   ///
      11             :   ///
      12           1 :   MobilePhoneValidator()
      13           1 :       : super(
      14           1 :           <TextInputFormatter>[
      15           1 :             MaskTextInputFormatter(
      16             :               mask: '(##) #####-####',
      17             :             ),
      18             :           ],
      19             :         );
      20             : 
      21             :   ///
      22             :   ///
      23             :   ///
      24           1 :   @override
      25           2 :   String format(String value) => strip(value).replaceAllMapped(
      26           1 :         RegExp(r'^(\d{2})(\d{5})(\d{4})$'),
      27           5 :         (Match m) => '(${m[1]}) ${m[2]}-${m[3]}',
      28             :       );
      29             : 
      30             :   ///
      31             :   ///
      32             :   ///
      33           0 :   @override
      34             :   TextInputType get keyboard => TextInputType.number;
      35             : 
      36             :   ///
      37             :   ///
      38             :   ///
      39           1 :   @override
      40             :   bool isValid(String value) {
      41           1 :     value = strip(value);
      42             : 
      43             :     /// phone must be defined
      44           1 :     if (value.isEmpty) {
      45             :       return false;
      46             :     }
      47             : 
      48           2 :     if (value.length != 11) {
      49             :       return false;
      50             :     }
      51             : 
      52             :     /// Não existe DDD com zero.
      53           4 :     if (value[0] == '0' || value[1] == '0') {
      54             :       return false;
      55             :     }
      56             : 
      57             :     /// Telefones celulares sempre iniciam com 9.
      58           2 :     return value[2] == '9';
      59             :   }
      60             : }

Generated by: LCOV version 1.14