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
3b4a882b
Unverified
Commit
3b4a882b
authored
Mar 08, 2023
by
Bruno Leroux
Committed by
GitHub
Mar 08, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add one DefaultTextStyle example (#122182)
Add one DefaultTextStyle example
parent
b9e925ab
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
0 deletions
+80
-0
text.0.dart
examples/api/lib/widgets/text/text.0.dart
+46
-0
text.0_test.dart
examples/api/test/widgets/text/text.0_test.dart
+26
-0
text.dart
packages/flutter/lib/src/widgets/text.dart
+8
-0
No files found.
examples/api/lib/widgets/text/text.0.dart
0 → 100644
View file @
3b4a882b
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [DefaultTextStyle].
import
'package:flutter/material.dart'
;
void
main
(
)
=>
runApp
(
const
DefaultTextStyleApp
());
class
DefaultTextStyleApp
extends
StatelessWidget
{
const
DefaultTextStyleApp
({
super
.
key
});
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
theme:
ThemeData
(
useMaterial3:
true
,
brightness:
Brightness
.
light
,
colorSchemeSeed:
Colors
.
purple
,
),
home:
const
DefaultTextStyleExample
(),
);
}
}
class
DefaultTextStyleExample
extends
StatelessWidget
{
const
DefaultTextStyleExample
({
super
.
key
});
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
'DefaultTextStyle.merge Sample'
)),
// Inherit MaterialApp text theme and override font size and font weight.
body:
DefaultTextStyle
.
merge
(
style:
const
TextStyle
(
fontSize:
24
,
fontWeight:
FontWeight
.
bold
,
),
child:
const
Center
(
child:
Text
(
'Flutter'
),
),
),
);
}
}
examples/api/test/widgets/text/text.0_test.dart
0 → 100644
View file @
3b4a882b
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter/material.dart'
;
import
'package:flutter_api_samples/widgets/text/text.0.dart'
as
example
;
import
'package:flutter_test/flutter_test.dart'
;
void
main
(
)
{
testWidgets
(
'WidgetsApp test'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
example
.
DefaultTextStyleApp
(),
);
expect
(
find
.
text
(
'Flutter'
),
findsOneWidget
);
final
RichText
text
=
tester
.
firstWidget
(
find
.
byType
(
RichText
));
expect
(
text
.
text
.
style
!.
fontSize
,
24
);
expect
(
text
.
text
.
style
!.
fontWeight
,
FontWeight
.
bold
);
// Because this example uses Material 3 and a light brightness, the text color
// should be the color scheme `onSurface` color.
final
Color
textColor
=
ColorScheme
.
fromSeed
(
seedColor:
Colors
.
purple
).
onSurface
;
expect
(
text
.
text
.
style
!.
color
,
textColor
);
});
}
packages/flutter/lib/src/widgets/text.dart
View file @
3b4a882b
...
...
@@ -20,6 +20,14 @@ import 'selection_container.dart';
/// The text style to apply to descendant [Text] widgets which don't have an
/// explicit style.
///
/// {@tool dartpad}
/// This example shows how to use [DefaultTextStyle.merge] to create a default
/// text style that inherits styling information from the current default text
/// style and overrides some properties.
///
/// ** See code in examples/api/lib/widgets/text/text.0.dart **
/// {@end-tool}
///
/// See also:
///
/// * [AnimatedDefaultTextStyle], which animates changes in the text style
...
...
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