Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
f74cd917
Commit
f74cd917
authored
Oct 19, 2017
by
Sarah Zakarias
Committed by
GitHub
Oct 19, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update TextStyle doc and remove package field (#12577)
parent
e4f53c3a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
13 deletions
+25
-13
text_style.dart
packages/flutter/lib/src/painting/text_style.dart
+25
-11
text_style_test.dart
packages/flutter/test/painting/text_style_test.dart
+0
-2
No files found.
packages/flutter/lib/src/painting/text_style.dart
View file @
f74cd917
...
@@ -168,11 +168,14 @@ import 'basic_types.dart';
...
@@ -168,11 +168,14 @@ import 'basic_types.dart';
/// const TextStyle(fontFamily: 'Raleway', package: 'my_package')
/// const TextStyle(fontFamily: 'Raleway', package: 'my_package')
/// ```
/// ```
///
///
/// This is also how the package itself should create the style.
/// If the package internally uses the font it defines, it should still specify
/// the `package` argument when creating the text style as in the example above.
///
///
/// A package can also provide font files in its `lib/` folder which will not
/// A package can also provide font files without declaring a font in its
/// automatically be included in the app. Instead the app can use these
/// `pubspec.yaml`. These files should then be in the `lib/` folder of the
/// selectively when declaring a font. Suppose a package named `my_package` has:
/// package. The font files will not automatically be bundled in the app, instead
/// the app can use these selectively when declaring a font. Suppose a package
/// named `my_package` has:
///
///
/// ```
/// ```
/// lib/fonts/Raleway-Medium.ttf
/// lib/fonts/Raleway-Medium.ttf
...
@@ -192,6 +195,13 @@ import 'basic_types.dart';
...
@@ -192,6 +195,13 @@ import 'basic_types.dart';
///
///
/// The `lib/` is implied, so it should not be included in the asset path.
/// The `lib/` is implied, so it should not be included in the asset path.
///
///
/// In this case, since the app locally defines the font, the TextStyle is
/// created without the `package` argument:
///
///```dart
/// const TextStyle(fontFamily: 'Raleway')
/// ```
///
/// See also:
/// See also:
///
///
/// * [Text], the widget for showing text in a single style.
/// * [Text], the widget for showing text in a single style.
...
@@ -203,10 +213,13 @@ import 'basic_types.dart';
...
@@ -203,10 +213,13 @@ import 'basic_types.dart';
@immutable
@immutable
class
TextStyle
extends
Diagnosticable
{
class
TextStyle
extends
Diagnosticable
{
/// Creates a text style.
/// Creates a text style.
///
/// The `package` argument must be non-null if the font family is defined in a
/// package. It is combined with the `fontFamily` argument to set the
/// [fontFamily] property.
const
TextStyle
({
const
TextStyle
({
this
.
inherit
:
true
,
this
.
inherit
:
true
,
this
.
color
,
this
.
color
,
String
fontFamily
,
this
.
fontSize
,
this
.
fontSize
,
this
.
fontWeight
,
this
.
fontWeight
,
this
.
fontStyle
,
this
.
fontStyle
,
...
@@ -217,7 +230,8 @@ class TextStyle extends Diagnosticable {
...
@@ -217,7 +230,8 @@ class TextStyle extends Diagnosticable {
this
.
decoration
,
this
.
decoration
,
this
.
decorationColor
,
this
.
decorationColor
,
this
.
decorationStyle
,
this
.
decorationStyle
,
this
.
package
,
String
fontFamily
,
String
package
,
})
:
fontFamily
=
package
==
null
?
fontFamily
:
'packages/
$package
/
$fontFamily
'
,
})
:
fontFamily
=
package
==
null
?
fontFamily
:
'packages/
$package
/
$fontFamily
'
,
assert
(
inherit
!=
null
);
assert
(
inherit
!=
null
);
...
@@ -233,13 +247,13 @@ class TextStyle extends Diagnosticable {
...
@@ -233,13 +247,13 @@ class TextStyle extends Diagnosticable {
/// The color to use when painting the text.
/// The color to use when painting the text.
final
Color
color
;
final
Color
color
;
/// The name of the font to use when painting the text (e.g., Roboto).
/// The name of the font to use when painting the text (e.g., Roboto). If the
/// font is defined in a package, this will be prefixed with
/// 'packages/package_name/' (e.g. 'packages/cool_fonts/Roboto'). The
/// prefixing is done by the constructor when the `package` argument is
/// provided.
final
String
fontFamily
;
final
String
fontFamily
;
/// The name of the package from which the font is included. See the
/// documentation for the [TextStyle] class itself for details.
final
String
package
;
/// The size of glyphs (in logical pixels) to use when painting the text.
/// The size of glyphs (in logical pixels) to use when painting the text.
///
///
/// During painting, the [fontSize] is multiplied by the current
/// During painting, the [fontSize] is multiplied by the current
...
...
packages/flutter/test/painting/text_style_test.dart
View file @
f74cd917
...
@@ -136,12 +136,10 @@ void main() {
...
@@ -136,12 +136,10 @@ void main() {
test
(
'TextStyle using package font'
,
()
{
test
(
'TextStyle using package font'
,
()
{
final
TextStyle
s6
=
const
TextStyle
(
fontFamily:
'test'
);
final
TextStyle
s6
=
const
TextStyle
(
fontFamily:
'test'
);
expect
(
s6
.
fontFamily
,
'test'
);
expect
(
s6
.
fontFamily
,
'test'
);
expect
(
s6
.
package
,
isNull
);
expect
(
s6
.
getTextStyle
().
toString
(),
'TextStyle(color: unspecified, decoration: unspecified, decorationColor: unspecified, decorationStyle: unspecified, fontWeight: unspecified, fontStyle: unspecified, textBaseline: unspecified, fontFamily: test, fontSize: unspecified, letterSpacing: unspecified, wordSpacing: unspecified, height: unspecified)'
);
expect
(
s6
.
getTextStyle
().
toString
(),
'TextStyle(color: unspecified, decoration: unspecified, decorationColor: unspecified, decorationStyle: unspecified, fontWeight: unspecified, fontStyle: unspecified, textBaseline: unspecified, fontFamily: test, fontSize: unspecified, letterSpacing: unspecified, wordSpacing: unspecified, height: unspecified)'
);
final
TextStyle
s7
=
const
TextStyle
(
fontFamily:
'test'
,
package:
'p'
);
final
TextStyle
s7
=
const
TextStyle
(
fontFamily:
'test'
,
package:
'p'
);
expect
(
s7
.
fontFamily
,
'packages/p/test'
);
expect
(
s7
.
fontFamily
,
'packages/p/test'
);
expect
(
s7
.
package
,
'p'
);
expect
(
s7
.
getTextStyle
().
toString
(),
'TextStyle(color: unspecified, decoration: unspecified, decorationColor: unspecified, decorationStyle: unspecified, fontWeight: unspecified, fontStyle: unspecified, textBaseline: unspecified, fontFamily: packages/p/test, fontSize: unspecified, letterSpacing: unspecified, wordSpacing: unspecified, height: unspecified)'
);
expect
(
s7
.
getTextStyle
().
toString
(),
'TextStyle(color: unspecified, decoration: unspecified, decorationColor: unspecified, decorationStyle: unspecified, fontWeight: unspecified, fontStyle: unspecified, textBaseline: unspecified, fontFamily: packages/p/test, fontSize: unspecified, letterSpacing: unspecified, wordSpacing: unspecified, height: unspecified)'
);
});
});
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment