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
8c439fd3
Unverified
Commit
8c439fd3
authored
Dec 14, 2018
by
Hans Muller
Committed by
GitHub
Dec 14, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
IntrinsicWidth stepWidth or stepHeight == 0.0 (#25228)
parent
ff97e255
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
5 deletions
+67
-5
proxy_box.dart
packages/flutter/lib/src/rendering/proxy_box.dart
+14
-1
basic.dart
packages/flutter/lib/src/widgets/basic.dart
+23
-4
intrinsic_width_test.dart
packages/flutter/test/widgets/intrinsic_width_test.dart
+30
-0
No files found.
packages/flutter/lib/src/rendering/proxy_box.dart
View file @
8c439fd3
...
...
@@ -541,16 +541,26 @@ class RenderAspectRatio extends RenderProxyBox {
/// depth of the tree.
class
RenderIntrinsicWidth
extends
RenderProxyBox
{
/// Creates a render object that sizes itself to its child's intrinsic width.
///
/// If [stepWidth] is non-null it must be > 0.0. Similarly If [stepHeight] is
/// non-null it must be > 0.0.
RenderIntrinsicWidth
({
double
stepWidth
,
double
stepHeight
,
RenderBox
child
})
:
_stepWidth
=
stepWidth
,
_stepHeight
=
stepHeight
,
super
(
child
);
})
:
assert
(
stepWidth
==
null
||
stepWidth
>
0.0
),
assert
(
stepHeight
==
null
||
stepHeight
>
0.0
),
_stepWidth
=
stepWidth
,
_stepHeight
=
stepHeight
,
super
(
child
);
/// If non-null, force the child's width to be a multiple of this value.
///
/// This value must be null or > 0.0.
double
get
stepWidth
=>
_stepWidth
;
double
_stepWidth
;
set
stepWidth
(
double
value
)
{
assert
(
value
==
null
||
value
>
0.0
);
if
(
value
==
_stepWidth
)
return
;
_stepWidth
=
value
;
...
...
@@ -558,9 +568,12 @@ class RenderIntrinsicWidth extends RenderProxyBox {
}
/// If non-null, force the child's height to be a multiple of this value.
///
/// This value must be null or > 0.0.
double
get
stepHeight
=>
_stepHeight
;
double
_stepHeight
;
set
stepHeight
(
double
value
)
{
assert
(
value
==
null
||
value
>
0.0
);
if
(
value
==
_stepHeight
)
return
;
_stepHeight
=
value
;
...
...
packages/flutter/lib/src/widgets/basic.dart
View file @
8c439fd3
...
...
@@ -2477,24 +2477,43 @@ class IntrinsicWidth extends SingleChildRenderObjectWidget {
///
/// This class is relatively expensive. Avoid using it where possible.
const
IntrinsicWidth
({
Key
key
,
this
.
stepWidth
,
this
.
stepHeight
,
Widget
child
})
:
super
(
key:
key
,
child:
child
);
:
assert
(
stepWidth
==
null
||
stepWidth
>=
0.0
),
assert
(
stepHeight
==
null
||
stepHeight
>=
0.0
),
super
(
key:
key
,
child:
child
);
/// If non-null, force the child's width to be a multiple of this value.
///
/// If null or 0.0 the child's width will be the same as its maximum
/// intrinsic width.
///
/// This value must not be negative.
///
/// See also:
///
/// * [RenderBox.getMaxIntrinsicWidth], which defines a widget's max
/// intrinsic width in general.
final
double
stepWidth
;
/// If non-null, force the child's height to be a multiple of this value.
///
/// If null or 0.0 the child's height will not be constrained.
///
/// This value must not be negative.
final
double
stepHeight
;
double
get
_stepWidth
=>
stepWidth
==
0.0
?
null
:
stepWidth
;
double
get
_stepHeight
=>
stepHeight
==
0.0
?
null
:
stepHeight
;
@override
RenderIntrinsicWidth
createRenderObject
(
BuildContext
context
)
{
return
RenderIntrinsicWidth
(
stepWidth:
stepWidth
,
stepHeight:
stepHeight
);
return
RenderIntrinsicWidth
(
stepWidth:
_stepWidth
,
stepHeight:
_
stepHeight
);
}
@override
void
updateRenderObject
(
BuildContext
context
,
RenderIntrinsicWidth
renderObject
)
{
renderObject
..
stepWidth
=
stepWidth
..
stepHeight
=
stepHeight
;
..
stepWidth
=
_
stepWidth
..
stepHeight
=
_
stepHeight
;
}
}
...
...
packages/flutter/test/widgets/intrinsic_width_test.dart
0 → 100644
View file @
8c439fd3
// Copyright 2018 The Chromium 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_test/flutter_test.dart'
;
import
'package:flutter/widgets.dart'
;
void
main
(
)
{
testWidgets
(
'Intrinsic stepWidth, stepHeight'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/25224
Widget
buildFrame
(
double
stepWidth
,
double
stepHeight
)
{
return
Center
(
child:
IntrinsicWidth
(
stepWidth:
stepWidth
,
stepHeight:
stepHeight
,
child:
const
SizedBox
(
width:
100.0
,
height:
50.0
),
),
);
}
await
tester
.
pumpWidget
(
buildFrame
(
null
,
null
));
expect
(
tester
.
getSize
(
find
.
byType
(
IntrinsicWidth
)),
const
Size
(
100.0
,
50.0
));
await
tester
.
pumpWidget
(
buildFrame
(
0.0
,
0.0
));
expect
(
tester
.
getSize
(
find
.
byType
(
IntrinsicWidth
)),
const
Size
(
100.0
,
50.0
));
expect
(()
{
buildFrame
(-
1.0
,
0.0
);
},
throwsAssertionError
);
expect
(()
{
buildFrame
(
0.0
,
-
1.0
);
},
throwsAssertionError
);
});
}
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