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
25164e10
Commit
25164e10
authored
Apr 20, 2016
by
Hans Muller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make IconButton gesture targets as big as possible (#3423)
* Make IconButtons as big as possible
parent
1b9476c4
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
233 additions
and
8 deletions
+233
-8
buttons_demo.dart
examples/material_gallery/lib/demo/buttons_demo.dart
+2
-0
icon_button.dart
packages/flutter/lib/src/material/icon_button.dart
+21
-8
scaffold.dart
packages/flutter/lib/src/material/scaffold.dart
+2
-0
proxy_box.dart
packages/flutter/lib/src/rendering/proxy_box.dart
+95
-0
basic.dart
packages/flutter/lib/src/widgets/basic.dart
+41
-0
limited_box_test.dart
packages/flutter/test/rendering/limited_box_test.dart
+72
-0
No files found.
examples/material_gallery/lib/demo/buttons_demo.dart
View file @
25164e10
...
...
@@ -174,6 +174,8 @@ class _ButtonsDemoState extends State<ButtonsDemo> {
icon:
Icons
.
thumb_up
)
]
.
map
((
Widget
button
)
=>
new
SizedBox
(
width:
64.0
,
height:
64.0
,
child:
button
))
.
toList
()
)
);
}
...
...
packages/flutter/lib/src/material/icon_button.dart
View file @
25164e10
...
...
@@ -38,6 +38,8 @@ class IconButton extends StatelessWidget {
const
IconButton
({
Key
key
,
this
.
size
:
24.0
,
this
.
padding
:
const
EdgeInsets
.
all
(
8.0
),
this
.
alignment
:
FractionalOffset
.
center
,
this
.
icon
,
this
.
color
,
this
.
disabledColor
,
...
...
@@ -46,11 +48,15 @@ class IconButton extends StatelessWidget {
})
:
super
(
key:
key
);
/// The size of the icon inside the button.
///
/// The button itself will be larger than the icon by 8.0 logical pixels in
/// each direction.
final
double
size
;
/// The padding around the button's icon. The entire padded icon will react
/// to input gestures.
final
EdgeInsets
padding
;
/// Defines how the icon is positioned within the IconButton.
final
FractionalOffset
alignment
;
/// The icon to display inside the button.
final
IconData
icon
;
...
...
@@ -90,12 +96,19 @@ class IconButton extends StatelessWidget {
else
currentColor
=
disabledColor
??
Theme
.
of
(
context
).
disabledColor
;
Widget
result
=
new
Padding
(
padding:
const
EdgeInsets
.
all
(
8.0
),
padding:
padding
,
child:
new
LimitedBox
(
maxWidth:
size
,
maxHeight:
size
,
child:
new
Align
(
alignment:
alignment
,
child:
new
Icon
(
size:
size
,
icon:
icon
,
color:
currentColor
)
)
)
);
if
(
tooltip
!=
null
)
{
result
=
new
Tooltip
(
...
...
packages/flutter/lib/src/material/scaffold.dart
View file @
25164e10
...
...
@@ -460,6 +460,7 @@ class ScaffoldState extends State<Scaffold> {
if
(
config
.
drawer
!=
null
)
{
leading
=
new
IconButton
(
icon:
Icons
.
menu
,
alignment:
FractionalOffset
.
centerLeft
,
onPressed:
openDrawer
,
tooltip:
'Open navigation menu'
// TODO(ianh): Figure out how to localize this string
);
...
...
@@ -468,6 +469,7 @@ class ScaffoldState extends State<Scaffold> {
if
(
_shouldShowBackArrow
)
{
leading
=
new
IconButton
(
icon:
Icons
.
arrow_back
,
alignment:
FractionalOffset
.
centerLeft
,
onPressed:
()
=>
Navigator
.
pop
(
context
),
tooltip:
'Back'
// TODO(ianh): Figure out how to localize this string
);
...
...
packages/flutter/lib/src/rendering/proxy_box.dart
View file @
25164e10
...
...
@@ -248,6 +248,101 @@ class RenderConstrainedBox extends RenderProxyBox {
}
}
/// Constrains the child's maxWidth and maxHeight if they're otherwise
/// unconstrained.
class
RenderLimitedBox
extends
RenderProxyBox
{
RenderLimitedBox
({
RenderBox
child
,
double
maxWidth:
double
.
INFINITY
,
double
maxHeight:
double
.
INFINITY
})
:
_maxWidth
=
maxWidth
,
_maxHeight
=
maxHeight
,
super
(
child
)
{
assert
(
maxWidth
!=
null
&&
maxWidth
>=
0.0
);
assert
(
maxHeight
!=
null
&&
maxHeight
>=
0.0
);
}
/// The value to use for maxWidth if the incoming maxWidth constraint is infinite.
double
get
maxWidth
=>
_maxWidth
;
double
_maxWidth
;
void
set
maxWidth
(
double
value
)
{
assert
(
value
!=
null
&&
value
>=
0.0
);
if
(
_maxWidth
==
value
)
return
;
_maxWidth
=
value
;
markNeedsLayout
();
}
/// The value to use for maxHeight if the incoming maxHeight constraint is infinite.
double
get
maxHeight
=>
_maxHeight
;
double
_maxHeight
;
void
set
maxHeight
(
double
value
)
{
assert
(
value
!=
null
&&
value
>=
0.0
);
if
(
_maxHeight
==
value
)
return
;
_maxHeight
=
value
;
markNeedsLayout
();
}
BoxConstraints
_limitConstraints
(
BoxConstraints
constraints
)
{
return
new
BoxConstraints
(
minWidth:
constraints
.
minWidth
,
maxWidth:
constraints
.
hasBoundedWidth
?
constraints
.
maxWidth
:
constraints
.
constrainWidth
(
maxWidth
),
minHeight:
constraints
.
minHeight
,
maxHeight:
constraints
.
hasBoundedHeight
?
constraints
.
maxHeight
:
constraints
.
constrainHeight
(
maxHeight
)
);
}
@override
double
getMinIntrinsicWidth
(
BoxConstraints
constraints
)
{
assert
(
constraints
.
debugAssertIsValid
());
if
(
child
!=
null
)
return
child
.
getMinIntrinsicWidth
(
_limitConstraints
(
constraints
));
return
_limitConstraints
(
constraints
).
constrainWidth
(
0.0
);
}
@override
double
getMaxIntrinsicWidth
(
BoxConstraints
constraints
)
{
assert
(
constraints
.
debugAssertIsValid
());
if
(
child
!=
null
)
return
child
.
getMaxIntrinsicWidth
(
_limitConstraints
(
constraints
));
return
_limitConstraints
(
constraints
).
constrainWidth
(
0.0
);
}
@override
double
getMinIntrinsicHeight
(
BoxConstraints
constraints
)
{
assert
(
constraints
.
debugAssertIsValid
());
if
(
child
!=
null
)
return
child
.
getMinIntrinsicHeight
(
_limitConstraints
(
constraints
));
return
_limitConstraints
(
constraints
).
constrainHeight
(
0.0
);
}
@override
double
getMaxIntrinsicHeight
(
BoxConstraints
constraints
)
{
assert
(
constraints
.
debugAssertIsValid
());
if
(
child
!=
null
)
return
child
.
getMaxIntrinsicHeight
(
_limitConstraints
(
constraints
));
return
_limitConstraints
(
constraints
).
constrainHeight
(
0.0
);
}
@override
void
performLayout
()
{
if
(
child
!=
null
)
{
child
.
layout
(
_limitConstraints
(
constraints
),
parentUsesSize:
true
);
size
=
constraints
.
constrain
(
child
.
size
);
}
else
{
size
=
_limitConstraints
(
constraints
).
constrain
(
Size
.
zero
);
}
}
@override
void
debugFillDescription
(
List
<
String
>
description
)
{
super
.
debugFillDescription
(
description
);
if
(
maxWidth
!=
double
.
INFINITY
)
description
.
add
(
'maxWidth:
$maxWidth
'
);
if
(
maxHeight
!=
double
.
INFINITY
)
description
.
add
(
'maxHeight:
$maxHeight
'
);
}
}
/// Attempts to size the child to a specific aspect ratio.
///
/// The render object first tries the largest width permited by the layout
...
...
packages/flutter/lib/src/widgets/basic.dart
View file @
25164e10
...
...
@@ -724,6 +724,47 @@ class FractionallySizedBox extends SingleChildRenderObjectWidget {
}
}
/// A box that limits its size only when it's unconstrained.
///
/// If this widget's maximum width is unconstrained then its child's width is
/// limited to maxWidth. Similarly, if this widget's maximum height is unconstrained
/// then its child's height is limited to to maxHeight.
class
LimitedBox
extends
SingleChildRenderObjectWidget
{
LimitedBox
({
Key
key
,
this
.
maxWidth
:
double
.
INFINITY
,
this
.
maxHeight
:
double
.
INFINITY
,
Widget
child
})
:
super
(
key:
key
,
child:
child
)
{
assert
(
maxWidth
!=
null
&&
maxWidth
>=
0.0
);
assert
(
maxHeight
!=
null
&&
maxHeight
>=
0.0
);
}
/// The maximum width limit to apply in the absence of a maxWidth constraint.
final
double
maxWidth
;
/// The maximum height limit to apply in the absence of a maxHeight constraint.
final
double
maxHeight
;
@override
RenderLimitedBox
createRenderObject
(
BuildContext
context
)
=>
new
RenderLimitedBox
(
maxWidth:
maxWidth
,
maxHeight:
maxHeight
);
@override
void
updateRenderObject
(
BuildContext
context
,
RenderLimitedBox
renderObject
)
{
renderObject
..
maxWidth
=
maxWidth
..
maxHeight
=
maxHeight
;
}
@override
void
debugFillDescription
(
List
<
String
>
description
)
{
super
.
debugFillDescription
(
description
);
if
(
maxWidth
!=
double
.
INFINITY
)
description
.
add
(
'maxWidth:
$maxWidth
'
);
if
(
maxHeight
!=
double
.
INFINITY
)
description
.
add
(
'maxHeight:
$maxHeight
'
);
}
}
/// A render object that imposes different constraints on its child than it gets
/// from its parent, possibly allowing the child to overflow the parent.
///
...
...
packages/flutter/test/rendering/limited_box_test.dart
0 → 100644
View file @
25164e10
// Copyright 2016 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/material.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:test/test.dart'
;
import
'rendering_tester.dart'
;
void
main
(
)
{
test
(
'parent max size is unconstrained'
,
()
{
RenderBox
child
=
new
RenderConstrainedBox
(
additionalConstraints:
new
BoxConstraints
.
tightFor
(
width:
300.0
,
height:
400.0
)
);
RenderBox
parent
=
new
RenderConstrainedOverflowBox
(
minWidth:
0.0
,
maxWidth:
double
.
INFINITY
,
minHeight:
0.0
,
maxHeight:
double
.
INFINITY
,
child:
new
RenderLimitedBox
(
maxWidth:
100.0
,
maxHeight:
200.0
,
child:
child
)
);
layout
(
parent
);
expect
(
child
.
size
.
width
,
100.0
);
expect
(
child
.
size
.
height
,
200.0
);
});
test
(
'parent maxWidth is unconstrained'
,
()
{
RenderBox
child
=
new
RenderConstrainedBox
(
additionalConstraints:
new
BoxConstraints
.
tightFor
(
width:
300.0
,
height:
400.0
)
);
RenderBox
parent
=
new
RenderConstrainedOverflowBox
(
minWidth:
0.0
,
maxWidth:
double
.
INFINITY
,
minHeight:
500.0
,
maxHeight:
500.0
,
child:
new
RenderLimitedBox
(
maxWidth:
100.0
,
maxHeight:
200.0
,
child:
child
)
);
layout
(
parent
);
expect
(
child
.
size
.
width
,
100.0
);
expect
(
child
.
size
.
height
,
500.0
);
});
test
(
'parent maxHeight is unconstrained'
,
()
{
RenderBox
child
=
new
RenderConstrainedBox
(
additionalConstraints:
new
BoxConstraints
.
tightFor
(
width:
300.0
,
height:
400.0
)
);
RenderBox
parent
=
new
RenderConstrainedOverflowBox
(
minWidth:
500.0
,
maxWidth:
500.0
,
minHeight:
0.0
,
maxHeight:
double
.
INFINITY
,
child:
new
RenderLimitedBox
(
maxWidth:
100.0
,
maxHeight:
200.0
,
child:
child
)
);
layout
(
parent
);
expect
(
child
.
size
.
width
,
500.0
);
expect
(
child
.
size
.
height
,
200.0
);
});
}
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