@@ -94,6 +94,68 @@ final class bool {
9494 //ignore: const_factory
9595 external const factory bool .hasEnvironment (String name);
9696
97+ /// Parses [source] as an, optionally case-insensitive, boolean literal.
98+ ///
99+ /// If [caseSensitive] is `true` , which is the default,
100+ /// the only accepted inputs are the strings `"true"` and `"false"` ,
101+ /// which returns the results `true` and `false` respectively.
102+ ///
103+ /// If [caseSensitive] is `false` , any combination of upper and lower case
104+ /// ASCII letters in the words `"true"` and `"false"` are accepted,
105+ /// as if the input was first lower-cased.
106+ ///
107+ /// Throws a [FormatException] if the [source] string does not contain
108+ /// a valid boolean literal.
109+ ///
110+ /// Rather than throwing and immediately catching the [FormatException] ,
111+ /// instead use [tryParse] to handle a potential parsing error.
112+ ///
113+ /// Example:
114+ /// ```dart
115+ /// print(bool.tryParse('true')); // true
116+ /// print(bool.tryParse('false')); // false
117+ /// print(bool.tryParse('TRUE')); // throws FormatException
118+ /// print(bool.tryParse('TRUE', caseSensitive: false)); // true
119+ /// print(bool.tryParse('FALSE', caseSensitive: false)); // false
120+ /// print(bool.tryParse('NO')); // throws FormatException
121+ /// print(bool.tryParse('YES')); // throws FormatException
122+ /// print(bool.tryParse('0')); // throws FormatException
123+ /// print(bool.tryParse('1')); // throws FormatException
124+ /// ```
125+ @Since ("3.0" )
126+ external static bool parse (String source, {bool caseSensitive = true });
127+
128+ /// Parses [source] as an, optionally case-insensitive, boolean literal.
129+ ///
130+ /// If [caseSensitive] is `true` , which is the default,
131+ /// the only accepted inputs are the strings `"true"` and `"false"` ,
132+ /// which returns the results `true` and `false` respectively.
133+ ///
134+ /// If [caseSensitive] is `false` , any combination of upper and lower case
135+ /// ASCII letters in the words `"true"` and `"false"` are accepted,
136+ /// as if the input was first lower-cased.
137+ ///
138+ /// Returns `null` if the [source] string does not contain a valid
139+ /// boolean literal.
140+ ///
141+ /// If the input can be assumed to be valid, use [bool.parse] to avoid
142+ /// having to deal with a possible `null` result.
143+ ///
144+ /// Example:
145+ /// ```dart
146+ /// print(bool.tryParse('true')); // true
147+ /// print(bool.tryParse('false')); // false
148+ /// print(bool.tryParse('TRUE')); // null
149+ /// print(bool.tryParse('TRUE', caseSensitive: false)); // true
150+ /// print(bool.tryParse('FALSE', caseSensitive: false)); // false
151+ /// print(bool.tryParse('NO')); // null
152+ /// print(bool.tryParse('YES')); // null
153+ /// print(bool.tryParse('0')); // null
154+ /// print(bool.tryParse('1')); // null
155+ /// ```
156+ @Since ("3.0" )
157+ external static bool ? tryParse (String source, {bool caseSensitive = true });
158+
97159 external int get hashCode;
98160
99161 /// The logical conjunction ("and") of this and [other] .
0 commit comments