New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/extensions #7
Conversation
extension StringExtension on String { | ||
String trimFirst() => isEmpty ? this : substring(1); | ||
|
||
String firstToUpper() => _safeSubstring(toUpper: true); | ||
String firstToLower() => _safeSubstring(toUpper: false); | ||
|
||
String firstToUpperUnsafe() => this[0].toUpperCase() + substring(1); | ||
String firstToLowerUnsafe() => this[0].toLowerCase() + substring(1); | ||
|
||
String get firstAsUpper => this[0].toUpperCase(); | ||
String get firstAsLower => this[0].toLowerCase(); | ||
|
||
bool _canRunSubstring(String val) => val.length > 1; | ||
String _safeSubstring({required bool toUpper}) { | ||
late final first = toUpper ? firstAsUpper : firstAsLower; | ||
if (isEmpty) return this; | ||
if (!_canRunSubstring(this)) return first; | ||
return first + substring(1); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Można to znacząco skrócić:
extension StringExtension on String {
String firstToUpper() => length > 0 ? '$firstAsUpper${substring(1)}' : '';
String firstToLower() => length > 0 ? '$firstAsLower${substring(1)}' : '';
String trimFirst() => isEmpty ? this : substring(1);
String get firstAsUpper => this[0].toUpperCase();
String get firstAsLower => this[0].toLowerCase();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String firstToUpper() => length > 0 ? '$firstAsUpper${substring(1)}' : '';
W przypadku gdy coś ma length 1 (np.: "a") to wyrzuci RangeError (jest uwzględniony ten przypadek w testach)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wygląda na to że example nie chce się poprawnie skompilować po wygenerowaniu kodu - w wygenerowanym kodzie mamy
|
Fixed test for generated class name. Now it will correctly trim first 2 special symbols -> |
Add extensions to access theme/theme properties to ThemeData / BuildContext
ThemeGetter.onBuildContextProps is selected as a default option, this is a subject to change. Also we may allow to generate few of these at once.
Generated extensions examples: