copyWith abstract method

Locale copyWith({
  1. String? language,
  2. String? country,
  3. String? variant,
})

Copy this locale with optional replacements.

This method creates a new Locale instance based on the current one, allowing you to override specific components while keeping others unchanged.

Parameters:

  • language: New language code (optional)
  • country: New country code (optional)
  • variant: New variant (optional)

Example:

final original = Locale('en', 'US', 'POSIX');

// Change only the country
final modified1 = original.copyWith(country: 'CA');
print(modified1.getLanguageTag()); // Output: "en-CA-POSIX"

// Change language and remove variant
final modified2 = original.copyWith(language: 'fr', variant: null);
print(modified2.getLanguageTag()); // Output: "fr-US"

Implementation

Locale copyWith({String? language, String? country, String? variant});