-
Notifications
You must be signed in to change notification settings - Fork 28.7k
Platform-specific typography #6634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
const Typography._(this.black, this.white); | ||
|
||
/// Returns the default typography for the specified platform. | ||
static Typography forPlatform(TargetPlatform platform) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts on static forPlatform
vs a factory ctor with required TargetPlatform
? The only precedent I could find for a sort-of similar platform-specific ctor was the scroll behaviour delegate, but that's a type that actually gets used as a delegate as opposed to this case, which is just a util lookup.
Another option would be to just add black/white getters that take a platform.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I understand what you're asking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically, anyone have a preference for factory Typography({@required TargetPlatform platform})
vs the code in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes. I think I prefer the constructor.
Also, constructor before fields please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(the rule is "code should be in the order it's run", to make it easier to read. The constructors are run before you do anything with fields, hence they go first.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
7dd9d08
to
41c4b98
Compare
Rebased this on top of #6640 to get the tests happy. |
@@ -358,6 +356,9 @@ class CardCollectionState extends State<CardCollection> { | |||
if (_dismissDirection == DismissDirection.endToStart) | |||
rightArrowIcon = new Opacity(opacity: 0.1, child: rightArrowIcon); | |||
|
|||
ThemeData theme = Theme.of(context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these can be final
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -41,6 +41,7 @@ class _HardwareKeyDemoState extends State<RawKeyboardDemo> { | |||
|
|||
@override | |||
Widget build(BuildContext context) { | |||
TextTheme textTheme = Theme.of(context).textTheme; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these can be final
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -77,6 +78,32 @@ class TextTheme { | |||
caption = const TextStyle(fontFamily: 'Roboto', inherit: false, fontSize: 12.0, fontWeight: FontWeight.w400, color: Colors.white70, textBaseline: TextBaseline.alphabetic), | |||
button = const TextStyle(fontFamily: 'Roboto', inherit: false, fontSize: 14.0, fontWeight: FontWeight.w500, color: Colors.white, textBaseline: TextBaseline.alphabetic); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename _black and _white as well.
Maybe blackMountainView and blackCupertino etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it. Done.
23cd372
to
9685ce7
Compare
Comments addressed and re-squashed. PTAL. |
const Typography._(this.black, this.white); | ||
|
||
/// Creates the default typography for the specified platform. | ||
factory Typography({@required TargetPlatform platform}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style nit: spaces around the arguments please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
switch (platform) { | ||
case TargetPlatform.android: | ||
case TargetPlatform.fuchsia: | ||
typography = const Typography._( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can just return here rather than setting a variable then returning it.
that also lets you remove the break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
break; | ||
} | ||
assert(typography != null); | ||
return typography; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then you'd just return null here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
/// Creates the default typography for the specified platform. | ||
factory Typography({@required TargetPlatform platform}) { | ||
Typography typography; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert platform != null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
/// material design. The black text theme, which uses dark glyphs, is used on | ||
/// light backgrounds in light themes. The white text theme, which uses light | ||
/// glyphs, is used in dark themes and on dark backgrounds in in light themes. | ||
/// [black] and [white] define the two text themes used in material design. The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sentences should start with a capital letter. To make that work here, you can write it as something like The [black] and [white] properties provide...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-worded.
Ideally this would have some sort of test. LGTM. |
0b6c035
to
227aa6d
Compare
Added a minimal test to ensure that typography is defined for all target platforms. Not a ton more we can test without getting into testing constants territory. Maybe just a test that iOS does its own thing? |
074300d
to
43d7c33
Compare
Added tests that ThemeData defaults to platform-specific font family and that ensure that we select the appropriate font family according to Apple's typography guidelines. |
43d7c33
to
b805a6a
Compare
On Android and Fuchsia, default to Roboto. On iOS, use San Francisco.
b805a6a
to
4875cda
Compare
Fixes #4956 |
No description provided.