Skip to content

Some M3 templates generate Theme.of for multiple properties. #117933

@TahaTesser

Description

@TahaTesser

It has been appointed to me that some generated templates use Theme.of (Theme lookup) multiple times in the same class

For instance:

@override
Color? get backgroundColor => Theme.of(context).colorScheme.surface;
@override
Color? get surfaceTintColor => Theme.of(context).colorScheme.surfaceTint;
@override
Color? get shadowColor => Colors.transparent;
@override
Color? get indicatorColor => Theme.of(context).colorScheme.secondaryContainer;

@override
Color? get color => Theme.of(context).colorScheme.surface;
@override
Color? get shadowColor => Theme.of(context).colorScheme.shadow;
@override
Color? get surfaceTintColor => Theme.of(context).colorScheme.surfaceTint;

These should be refactored to use variables.

final BuildContext context;
late final ColorScheme _colors = Theme.of(context).colorScheme;
late final TextTheme _textTheme = Theme.of(context).textTheme;

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listc: contributor-productivityTeam-specific productivity, code health, technical debt.c: tech-debtTechnical debt, code quality, testing, etc.f: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions