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
fea56130
Unverified
Commit
fea56130
authored
Oct 28, 2023
by
Kostia Sokolovskyi
Committed by
GitHub
Oct 28, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
TextPainter should dispatch creation and disposal events. (#137416)
parent
14f95576
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
80 additions
and
25 deletions
+80
-25
snack_bar.dart
packages/flutter/lib/src/material/snack_bar.dart
+1
-0
switch.dart
packages/flutter/lib/src/material/switch.dart
+7
-6
flutter_logo.dart
packages/flutter/lib/src/painting/flutter_logo.dart
+6
-1
text_painter.dart
packages/flutter/lib/src/painting/text_painter.dart
+18
-1
proxy_box.dart
packages/flutter/lib/src/rendering/proxy_box.dart
+6
-0
banner.dart
packages/flutter/lib/src/widgets/banner.dart
+34
-17
text_painter_test.dart
packages/flutter/test/painting/text_painter_test.dart
+8
-0
No files found.
packages/flutter/lib/src/material/snack_bar.dart
View file @
fea56130
...
@@ -664,6 +664,7 @@ class _SnackBarState extends State<SnackBar> {
...
@@ -664,6 +664,7 @@ class _SnackBarState extends State<SnackBar> {
final
double
actionAndIconWidth
=
actionTextPainter
.
size
.
width
+
final
double
actionAndIconWidth
=
actionTextPainter
.
size
.
width
+
(
widget
.
action
!=
null
?
actionHorizontalMargin
:
0
)
+
(
widget
.
action
!=
null
?
actionHorizontalMargin
:
0
)
+
(
showCloseIcon
?
(
iconButton
?.
iconSize
??
0
+
iconHorizontalMargin
)
:
0
);
(
showCloseIcon
?
(
iconButton
?.
iconSize
??
0
+
iconHorizontalMargin
)
:
0
);
actionTextPainter
.
dispose
();
final
EdgeInsets
margin
=
widget
.
margin
?.
resolve
(
TextDirection
.
ltr
)
??
snackBarTheme
.
insetPadding
??
defaults
.
insetPadding
!;
final
EdgeInsets
margin
=
widget
.
margin
?.
resolve
(
TextDirection
.
ltr
)
??
snackBarTheme
.
insetPadding
??
defaults
.
insetPadding
!;
...
...
packages/flutter/lib/src/material/switch.dart
View file @
fea56130
...
@@ -1309,6 +1309,7 @@ class _SwitchPainter extends ToggleablePainter {
...
@@ -1309,6 +1309,7 @@ class _SwitchPainter extends ToggleablePainter {
notifyListeners
();
notifyListeners
();
}
}
final
TextPainter
_textPainter
=
TextPainter
();
Color
?
_cachedThumbColor
;
Color
?
_cachedThumbColor
;
ImageProvider
?
_cachedThumbImage
;
ImageProvider
?
_cachedThumbImage
;
ImageErrorListener
?
_cachedThumbErrorListener
;
ImageErrorListener
?
_cachedThumbErrorListener
;
...
@@ -1594,16 +1595,15 @@ class _SwitchPainter extends ToggleablePainter {
...
@@ -1594,16 +1595,15 @@ class _SwitchPainter extends ToggleablePainter {
shadows:
iconShadows
,
shadows:
iconShadows
,
),
),
);
);
final
TextPainter
textPainter
=
TextPainter
(
_textPainter
textDirection:
textDirection
,
..
textDirection
=
textDirection
text:
textSpan
,
..
text
=
textSpan
;
);
_textPainter
.
layout
();
textPainter
.
layout
();
final
double
additionalHorizontalOffset
=
(
thumbSize
.
width
-
iconSize
)
/
2
;
final
double
additionalHorizontalOffset
=
(
thumbSize
.
width
-
iconSize
)
/
2
;
final
double
additionalVerticalOffset
=
(
thumbSize
.
height
-
iconSize
)
/
2
;
final
double
additionalVerticalOffset
=
(
thumbSize
.
height
-
iconSize
)
/
2
;
final
Offset
offset
=
thumbPaintOffset
+
Offset
(
additionalHorizontalOffset
,
additionalVerticalOffset
);
final
Offset
offset
=
thumbPaintOffset
+
Offset
(
additionalHorizontalOffset
,
additionalVerticalOffset
);
textPainter
.
paint
(
canvas
,
offset
);
_
textPainter
.
paint
(
canvas
,
offset
);
}
}
}
finally
{
}
finally
{
_isPainting
=
false
;
_isPainting
=
false
;
...
@@ -1612,6 +1612,7 @@ class _SwitchPainter extends ToggleablePainter {
...
@@ -1612,6 +1612,7 @@ class _SwitchPainter extends ToggleablePainter {
@override
@override
void
dispose
()
{
void
dispose
()
{
_textPainter
.
dispose
();
_cachedThumbPainter
?.
dispose
();
_cachedThumbPainter
?.
dispose
();
_cachedThumbPainter
=
null
;
_cachedThumbPainter
=
null
;
_cachedThumbColor
=
null
;
_cachedThumbColor
=
null
;
...
...
packages/flutter/lib/src/painting/flutter_logo.dart
View file @
fea56130
...
@@ -215,10 +215,15 @@ class _FlutterLogoPainter extends BoxPainter {
...
@@ -215,10 +215,15 @@ class _FlutterLogoPainter extends BoxPainter {
final
FlutterLogoDecoration
_config
;
final
FlutterLogoDecoration
_config
;
// these are configured assuming a font size of 100.0.
// these are configured assuming a font size of 100.0.
// TODO(dnfield): Figure out how to dispose this https://github.com/flutter/flutter/issues/110601
late
TextPainter
_textPainter
;
late
TextPainter
_textPainter
;
late
Rect
_textBoundingRect
;
late
Rect
_textBoundingRect
;
@override
void
dispose
()
{
_textPainter
.
dispose
();
super
.
dispose
();
}
void
_prepareText
()
{
void
_prepareText
()
{
const
String
kLabel
=
'Flutter'
;
const
String
kLabel
=
'Flutter'
;
_textPainter
=
TextPainter
(
_textPainter
=
TextPainter
(
...
...
packages/flutter/lib/src/painting/text_painter.dart
View file @
fea56130
...
@@ -438,6 +438,8 @@ final class _EmptyLineCaretMetrics implements _CaretMetrics {
...
@@ -438,6 +438,8 @@ final class _EmptyLineCaretMetrics implements _CaretMetrics {
final
double
lineVerticalOffset
;
final
double
lineVerticalOffset
;
}
}
const
String
_flutterPaintingLibrary
=
'package:flutter/painting.dart'
;
/// An object that paints a [TextSpan] tree into a [Canvas].
/// An object that paints a [TextSpan] tree into a [Canvas].
///
///
/// To use a [TextPainter], follow these steps:
/// To use a [TextPainter], follow these steps:
...
@@ -498,7 +500,17 @@ class TextPainter {
...
@@ -498,7 +500,17 @@ class TextPainter {
_locale
=
locale
,
_locale
=
locale
,
_strutStyle
=
strutStyle
,
_strutStyle
=
strutStyle
,
_textWidthBasis
=
textWidthBasis
,
_textWidthBasis
=
textWidthBasis
,
_textHeightBehavior
=
textHeightBehavior
;
_textHeightBehavior
=
textHeightBehavior
{
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if
(
kFlutterMemoryAllocationsEnabled
)
{
MemoryAllocations
.
instance
.
dispatchObjectCreated
(
library
:
_flutterPaintingLibrary
,
className:
'
$TextPainter
'
,
object:
this
,
);
}
}
/// Computes the width of a configured [TextPainter].
/// Computes the width of a configured [TextPainter].
///
///
...
@@ -1598,6 +1610,11 @@ class TextPainter {
...
@@ -1598,6 +1610,11 @@ class TextPainter {
_disposed
=
true
;
_disposed
=
true
;
return
true
;
return
true
;
}());
}());
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if
(
kFlutterMemoryAllocationsEnabled
)
{
MemoryAllocations
.
instance
.
dispatchObjectDisposed
(
object:
this
);
}
_layoutTemplate
?.
dispose
();
_layoutTemplate
?.
dispose
();
_layoutTemplate
=
null
;
_layoutTemplate
=
null
;
_layoutCache
?.
paragraph
.
dispose
();
_layoutCache
?.
paragraph
.
dispose
();
...
...
packages/flutter/lib/src/rendering/proxy_box.dart
View file @
fea56130
...
@@ -2263,6 +2263,12 @@ class RenderDecoratedBox extends RenderProxyBox {
...
@@ -2263,6 +2263,12 @@ class RenderDecoratedBox extends RenderProxyBox {
markNeedsPaint
();
markNeedsPaint
();
}
}
@override
void
dispose
()
{
_painter
?.
dispose
();
super
.
dispose
();
}
@override
@override
bool
hitTestSelf
(
Offset
position
)
{
bool
hitTestSelf
(
Offset
position
)
{
return
_decoration
.
hitTest
(
size
,
position
,
textDirection:
configuration
.
textDirection
);
return
_decoration
.
hitTest
(
size
,
position
,
textDirection:
configuration
.
textDirection
);
...
...
packages/flutter/lib/src/widgets/banner.dart
View file @
fea56130
...
@@ -231,7 +231,7 @@ class BannerPainter extends CustomPainter {
...
@@ -231,7 +231,7 @@ class BannerPainter extends CustomPainter {
///
///
/// * [CheckedModeBanner], which the [WidgetsApp] widget includes by default in
/// * [CheckedModeBanner], which the [WidgetsApp] widget includes by default in
/// debug mode, to show a banner that says "DEBUG".
/// debug mode, to show a banner that says "DEBUG".
class
Banner
extends
State
less
Widget
{
class
Banner
extends
State
ful
Widget
{
/// Creates a banner.
/// Creates a banner.
const
Banner
({
const
Banner
({
super
.
key
,
super
.
key
,
...
@@ -288,31 +288,48 @@ class Banner extends StatelessWidget {
...
@@ -288,31 +288,48 @@ class Banner extends StatelessWidget {
/// The style of the text shown on the banner.
/// The style of the text shown on the banner.
final
TextStyle
textStyle
;
final
TextStyle
textStyle
;
@override
State
<
Banner
>
createState
()
=>
_BannerState
();
}
class
_BannerState
extends
State
<
Banner
>
{
BannerPainter
?
_painter
;
@override
void
dispose
()
{
_painter
?.
dispose
();
super
.
dispose
();
}
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
assert
((
textDirection
!=
null
&&
layoutDirection
!=
null
)
||
debugCheckHasDirectionality
(
context
));
assert
((
widget
.
textDirection
!=
null
&&
widget
.
layoutDirection
!=
null
)
||
debugCheckHasDirectionality
(
context
));
_painter
?.
dispose
();
_painter
=
BannerPainter
(
message:
widget
.
message
,
textDirection:
widget
.
textDirection
??
Directionality
.
of
(
context
),
location:
widget
.
location
,
layoutDirection:
widget
.
layoutDirection
??
Directionality
.
of
(
context
),
color:
widget
.
color
,
textStyle:
widget
.
textStyle
,
);
return
CustomPaint
(
return
CustomPaint
(
foregroundPainter:
BannerPainter
(
foregroundPainter:
_painter
,
message:
message
,
child:
widget
.
child
,
textDirection:
textDirection
??
Directionality
.
of
(
context
),
location:
location
,
layoutDirection:
layoutDirection
??
Directionality
.
of
(
context
),
color:
color
,
textStyle:
textStyle
,
),
child:
child
,
);
);
}
}
@override
@override
void
debugFillProperties
(
DiagnosticPropertiesBuilder
properties
)
{
void
debugFillProperties
(
DiagnosticPropertiesBuilder
properties
)
{
super
.
debugFillProperties
(
properties
);
super
.
debugFillProperties
(
properties
);
properties
.
add
(
StringProperty
(
'message'
,
message
,
showName:
false
));
properties
.
add
(
StringProperty
(
'message'
,
widget
.
message
,
showName:
false
));
properties
.
add
(
EnumProperty
<
TextDirection
>(
'textDirection'
,
textDirection
,
defaultValue:
null
));
properties
.
add
(
EnumProperty
<
TextDirection
>(
'textDirection'
,
widget
.
textDirection
,
defaultValue:
null
));
properties
.
add
(
EnumProperty
<
BannerLocation
>(
'location'
,
location
));
properties
.
add
(
EnumProperty
<
BannerLocation
>(
'location'
,
widget
.
location
));
properties
.
add
(
EnumProperty
<
TextDirection
>(
'layoutDirection'
,
layoutDirection
,
defaultValue:
null
));
properties
.
add
(
EnumProperty
<
TextDirection
>(
'layoutDirection'
,
widget
.
layoutDirection
,
defaultValue:
null
));
properties
.
add
(
ColorProperty
(
'color'
,
color
,
showName:
false
));
properties
.
add
(
ColorProperty
(
'color'
,
widget
.
color
,
showName:
false
));
textStyle
.
debugFillProperties
(
properties
,
prefix:
'text '
);
widget
.
textStyle
.
debugFillProperties
(
properties
,
prefix:
'text '
);
}
}
}
}
...
...
packages/flutter/test/painting/text_painter_test.dart
View file @
fea56130
...
@@ -7,6 +7,7 @@ import 'dart:ui' as ui;
...
@@ -7,6 +7,7 @@ import 'dart:ui' as ui;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'
;
void
_checkCaretOffsetsLtrAt
(
String
text
,
List
<
int
>
boundaries
)
{
void
_checkCaretOffsetsLtrAt
(
String
text
,
List
<
int
>
boundaries
)
{
expect
(
boundaries
.
first
,
0
);
expect
(
boundaries
.
first
,
0
);
...
@@ -1525,6 +1526,13 @@ void main() {
...
@@ -1525,6 +1526,13 @@ void main() {
expect
(
metrics
,
hasLength
(
1
));
expect
(
metrics
,
hasLength
(
1
));
}
}
},
skip:
kIsWeb
&&
!
isCanvasKit
);
// [intended] Browsers seem to always round font/glyph metrics.
},
skip:
kIsWeb
&&
!
isCanvasKit
);
// [intended] Browsers seem to always round font/glyph metrics.
test
(
'TextPainter dispatches memory events'
,
()
async
{
await
expectLater
(
await
memoryEvents
(()
=>
TextPainter
().
dispose
(),
TextPainter
),
areCreateAndDispose
,
);
});
}
}
class
MockCanvas
extends
Fake
implements
Canvas
{
class
MockCanvas
extends
Fake
implements
Canvas
{
...
...
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