11import 'package:deep_pick/src/pick.dart' ;
22
33extension StringPick on RequiredPick {
4+ /// Returns the picked [value] as String
5+ ///
6+ /// {@template Pick.asString}
7+ /// Parses the picked value as String. If the value is not already a [String]
8+ /// its [Object.toString()] will be called. This means that this method works
9+ /// for [int] , [double] and any other [Object] which isn't a collection of
10+ /// values such as a [List] or [Map]
11+ /// {@endtemplate}
412 String asString () {
513 if (value is String ) {
614 return value as String ;
@@ -17,19 +25,23 @@ extension StringPick on RequiredPick {
1725}
1826
1927extension NullableStringPick on Pick {
28+ // This deprecation is used to promote the `.required()` in auto-completion.
29+ // Therefore it is not intended to be ever removed
2030 @Deprecated (
21- 'By default values are optional and can only be converted when a fallback is provided '
22- 'i.e. .asStringOrNull() which falls back to `null`. '
23- 'Use .required().asString() in cases the value is mandatory. '
24- "It will crash when the value couldn't be picked." )
31+ 'Use .required().asString() or .asRequiredString() when you require the value to be non-null. '
32+ 'Use .asStringOrNull() when you expect the value to be nullable' )
2533 String asString () {
2634 if (value == null ) {
2735 throw PickException (
28- 'value at location ${location ()} is null and not an instance of String' );
36+ 'value at location ${location ()} is null and not a String. '
37+ 'Use asStringOrNull() when null is a valid value (String?)' );
2938 }
3039 return required ().asString ();
3140 }
3241
42+ /// Returns the picked [value] as [String] or returns `null` when the picked value isn't available
43+ ///
44+ /// {@macro Pick.asString}
3345 String ? asStringOrNull () {
3446 if (value == null ) return null ;
3547 try {
0 commit comments