Skip to content

String resources in Flutter App #2692

Open
@CloudyPadmal

Description

@CloudyPadmal

Fetching string resources from a centralized constant file offers many advantages.

  • Easy maintenance as all strings are stored in one place, making it easier to edit or update them without searching through multiple files.
  • Improved localization support to transition to internationalization (i18n) using tools like the intl package in Flutter.
  • Better organization separating UI strings from logic and other constants improves code readability and maintainability.
  • Consistency helps avoid typos and ensures consistency across the UI.

However, I’m not sure the current approach in the codebase fully aligns with these benefits.

Currently, strings are defined mixed with unrelated constants (such as numerical values).

I recommend wrapping them in a dedicated class.

class Strings {
  static const appName = 'PSLab';
  static const saveSuccessMessage = 'Saved successfully!';
  static const saveFailureMessage = 'Save failed. Please try again.';
}

Then in the UI

Text(Strings.saveSuccessMessage)

This pattern is both scalable and prepares the codebase for future i18n with minimal refactoring.

Also, the string resources are distinct from other variable names (with the Strings. prefix).

What are your thoughts, @AsCress @marcnause ?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions