Skip to content

Refactor: Create BuildContext extension for Theme to reduce boilerplate #532

Description

@ZhuchkaTriplesix

Description

There are over 170 instances of Theme.of(context).colorScheme or Theme.of(context) scattered throughout the UI layer.

Why is this a problem?

Constantly repeating Theme.of(context) leads to visual noise and boilerplate in the build methods, making widget code harder to read.

Proposed Solution

Create a centralized BuildContext extension to streamline this framework boilerplate.

Implementation:

extension BuildContextThemeExt on BuildContext {
  ThemeData get theme => Theme.of(this);
  ColorScheme get colors => Theme.of(this).colorScheme;
}

This allows reducing Theme.of(context).colorScheme.primary down to a much cleaner context.colors.primary globally.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions