toSlug property

String get toSlug

URL-safe slug: lowercased, spaces→hyphens, non-alphanumeric stripped. 'Hello World! 2024''hello-world-2024'

Implementation

String get toSlug =>
    toLowerCase()
        .replaceAll(RegExp(r'\s+'), '-')
        .replaceAll(RegExp(r'[^a-z0-9\-]'), '')
        .replaceAll(RegExp(r'-+'), '-')
        .trim();