Skip to content

refactor context to be implicit-downcast safe#31622

Merged
jonahwilliams merged 1 commit intoflutter:masterfrom
jonahwilliams:fix_context_casts
Apr 25, 2019
Merged

refactor context to be implicit-downcast safe#31622
jonahwilliams merged 1 commit intoflutter:masterfrom
jonahwilliams:fix_context_casts

Conversation

@jonahwilliams
Copy link
Contributor

@jonahwilliams jonahwilliams commented Apr 25, 2019

Description

Deprecate Context.operator[] and replace it with Context.get<T>() which uses the generic to look up the token. This allows us to use the T to perform an as cast to remove all context related implicit downcasts.

Old method is marked as deprecated to make it easier to migrate g3 usages of tool context.

Replaces #31031

Related Issues

#13815

Copy link
Member

@zanderso zanderso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@jonahwilliams jonahwilliams merged commit 0acd3e6 into flutter:master Apr 25, 2019
@jonahwilliams jonahwilliams deleted the fix_context_casts branch April 25, 2019 22:51
if (value == null && _parent != null) {
value = _parent.get<T>();
}
return _unboxNull(value ?? _generateIfNecessary(T, _fallbacks)) as T;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can avoid the as here by saying:

T result = _unboxNull(value ?? _generateIfNecessary(T, _fallbacks));
return result;

(you can do the same above in AppContext get context)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants