• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

juancastillo0 / json_form / 11535823100

26 Oct 2024 11:42PM UTC coverage: 80.642% (+6.3%) from 74.365%
11535823100

Pull #6

github

web-flow
Merge 71c636276 into 419da37b9
Pull Request #6: Form value in controller recursive

537 of 640 new or added lines in 27 files covered. (83.91%)

26 existing lines in 6 files now uncovered.

1658 of 2056 relevant lines covered (80.64%)

1.3 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lib/src/utils/date_text_input_json_formatter.dart
1
import 'dart:developer';
2

3
import 'package:flutter/services.dart';
4

5
const String dateFormatString = 'yyyy-MM-dd';
6
const String dateTimeFormatString = 'yyyy-MM-dd HH:mm:ss';
7

8
class DateTextInputJsonFormatter extends TextInputFormatter {
9
  @override
×
10
  TextEditingValue formatEditUpdate(
11
    TextEditingValue oldValue,
12
    TextEditingValue newValue,
13
  ) {
14
    if (oldValue.text.length >= newValue.text.length) {
×
15
      return newValue;
16
    }
17

18
    if (newValue.text.length > 10) {
×
19
      return oldValue;
20
    }
21

22
    final dateText = _addSeparators(newValue.text, '-');
×
23

24
    if (dateText.length == 1) {
×
25
      if (!RegExp(r'([0-3])$').hasMatch(dateText)) {
×
26
        return oldValue;
27
      }
28
    }
29
    if (dateText.length == 2) {
×
30
      log(dateText[1]);
×
31
      if (!RegExp(r'(0[1-9]|1[0-9]|2[0-9]|3[0-1])$').hasMatch(dateText)) {
×
32
        return oldValue;
33
      }
34
    }
35

36
    if (dateText.length == 4) {
×
37
      if (!RegExp(r'(0[1-9]|1[0-9]|2[0-9]|3[0-1])-([0-1])$')
×
38
          .hasMatch(dateText)) {
×
39
        return oldValue;
40
      }
41
    }
42

43
    if (dateText.length == 5) {
×
44
      if (!RegExp(r'(0[1-9]|1[0-9]|2[0-9]|3[0-1])-(0[1-9]|1[0-2])$')
×
45
          .hasMatch(dateText)) {
×
46
        return oldValue;
47
      }
48
    }
49
    if (dateText.length == 7) {
×
50
      if (!RegExp(r'(0[1-9]|1[0-9]|2[0-9]|3[0-1])-(0[1-9]|1[0-2])-([1-2])$')
×
51
          .hasMatch(dateText)) {
×
52
        return oldValue;
53
      }
54
    }
55

56
    if (dateText.length == 8) {
×
57
      if (!RegExp(
×
58
        r'(0[1-9]|1[0-9]|2[0-9]|3[0-1])-(0[1-9]|1[0-2])-(1[9]|2[0|9])$',
59
      ).hasMatch(dateText)) {
×
60
        return oldValue;
61
      }
62
    }
63

64
    if (dateText.length == 9) {
×
65
      if (!RegExp(
×
66
        r'(0[1-9]|1[0-9]|2[0-9]|3[0-1])-(0[1-9]|1[0-2])-(19[89]|20[0-3])$',
67
      ).hasMatch(dateText)) {
×
68
        return oldValue;
69
      }
70
    }
71

72
    if (dateText.length == 10) {
×
73
      if (!RegExp(
×
74
        r'(0[1-9]|1[0-9]|2[0-9]|3[0-1])-(0[1-9]|1[0-2])-(19[89][0-9]|20[0-3][0-9])$',
75
      ).hasMatch(dateText)) {
×
76
        return oldValue;
77
      }
78
    }
79

80
    return newValue.copyWith(
×
81
      text: dateText,
82
      selection: updateCursorPosition(dateText),
×
83
    );
84
  }
85

86
  String _addSeparators(String value, String separator) {
×
NEW
87
    final v = value.replaceAll('-', '');
×
NEW
88
    final newString = StringBuffer();
×
NEW
89
    for (int i = 0; i < v.length; i++) {
×
NEW
90
      newString.write(v[i]);
×
91
      if (i == 1) {
×
NEW
92
        newString.write(separator);
×
93
      }
94
      if (i == 3) {
×
NEW
95
        newString.write(separator);
×
96
      }
97
    }
NEW
98
    return newString.toString();
×
99
  }
100

101
  TextSelection updateCursorPosition(String text) {
×
102
    return TextSelection.fromPosition(TextPosition(offset: text.length));
×
103
  }
104
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc