A comprehensive Flutter/Dart package that brings Laravel's powerful string manipulation methods to your Flutter applications. With 100+ methods for string transformation, validation, extraction, and manipulation!
- π― 100+ String Methods - Complete implementation of Laravel 12.x Str helper
- π Two APIs - Use static methods or fluent chainable API
- πͺ Type Safe - Full Dart type safety with null safety support
- π¦ Zero Configuration - Works out of the box
- π§ͺ Well Tested - Comprehensive test coverage
- π Well Documented - Every method is documented with examples
Add this to your package's pubspec.yaml file:
dependencies:
flutter_strings: ^1.0.0Then run:
flutter pub getimport 'package:flutter_strings/flutter_strings.dart';
void main() {
// Static API
final slug = Str.slug('Laravel 5 Framework');
print(slug); // 'laravel-5-framework'
// Fluent API (method chaining)
final result = 'hello world'
.str
.title()
.append('!')
.toString();
print(result); // 'Hello World!'
}// Convert to different cases
Str.camel('foo_bar'); // 'fooBar'
Str.snake('fooBar'); // 'foo_bar'
Str.kebab('fooBar'); // 'foo-bar'
Str.studly('foo_bar'); // 'FooBar'
Str.title('a nice title'); // 'A Nice Title'
// Using fluent API
'foo_bar'.str.camel().toString(); // 'fooBar'
'fooBar'.str.snake().toString(); // 'foo_bar'// Extract parts of strings
Str.after('App\\Http\\Controllers\\Controller', '\\');
// 'Http\\Controllers\\Controller'
Str.afterLast('App\\Http\\Controllers\\Controller', '\\');
// 'Controller'
Str.before('This is my name', 'my name');
// 'This is '
Str.between('This is my name', 'This', 'name');
// ' is my '// Check string properties
Str.isJson('{"name":"John"}'); // true
Str.isUuid('a0a2a2d2-0b87-4a18-83f2-2529882be2de'); // true
Str.isUrl('https://flutter.dev'); // true
Str.contains('Hello World', 'World'); // true
Str.startsWith('Hello World', 'Hello'); // true// Limit string length
Str.limit('The quick brown fox jumps over the lazy dog', 20);
// 'The quick brown fox...'
// Mask sensitive data
Str.mask('taylor@example.com', '*', 3);
// 'tay****************'
// Generate URL-friendly slugs
Str.slug('Laravel 5 Framework');
// 'laravel-5-framework'
// Pad strings
Str.padLeft('James', 10, '-'); // '-----James'
Str.padRight('James', 10, '-'); // 'James-----'final email = 'user@example.com';
// Mask email for privacy
final masked = Str.mask(email, '*', 4, 7);
print(masked); // 'user*******com'
// Extract domain
final domain = Str.after(email, '@');
print(domain); // 'example.com'
// Using fluent API
final processed = email
.str
.before('@')
.ucfirst()
.append(' User')
.toString();
print(processed); // 'User User'final title = 'How to Build Amazing Flutter Apps';
// Create SEO-friendly URL slug
final slug = Str.slug(title);
print(slug); // 'how-to-build-amazing-flutter-apps'
final url = 'https://myblog.com/posts/${slug}';
print(url);
// 'https://myblog.com/posts/how-to-build-amazing-flutter-apps'final rawText = ' hello_world ';
// Clean and format text
final formatted = rawText
.str
.squish() // Remove extra whitespace
.headline() // Convert to headline case
.wrap('"') // Wrap with quotes
.toString();
print(formatted); // '"Hello World"'camel(),snake(),kebab(),studly(),title(),lower(),upper(),ucfirst(),lcfirst(),headline()
after(),afterLast(),before(),beforeLast(),between(),betweenFirst(),charAt(),excerpt(),limit(),substr(),take(),words()
contains(),containsAll(),doesntContain(),startsWith(),endsWith(),is(),isAscii(),isJson(),isUrl(),isUuid(),isUlid(),isEmpty(),isNotEmpty()
append(),prepend(),finish(),start(),chopStart(),chopEnd(),mask(),padLeft(),padRight(),padBoth(),remove(),repeat(),replace(),replaceFirst(),replaceLast(),reverse(),slug(),squish(),stripTags(),swap(),trim(),ltrim(),rtrim(),wrap(),unwrap()
plural(),singular()
toBase64(),fromBase64(),hash(),toHtmlString(),toUri()
length(),position(),random(),split(),wordCount(),match(),matchAll()
when(),whenContains(),whenEmpty(),whenNotEmpty(),whenStartsWith(),whenEndsWith(), and many more...
final result = 'taylor_otwell'
.str
.replace('_', ' ')
.title()
.append(' - Creator of Laravel')
.toString();
print(result); // 'Taylor Otwell - Creator of Laravel'final text = 'user@example.com';
final result = text
.str
.whenContains('@', (s) => 'Email: $s')
.whenIsUrl((s) => 'URL: $s')
.whenEmpty((s) => 'Empty string')
.toString();
print(result); // 'Email: user@example.com'For detailed API documentation, visit pub.dev documentation.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by Laravel's Str Helper
- Built for the Flutter community
If you like this package, please give it a β on pub.dev!