Remove unnecessary closures (#11647)

Some widgets are using closures even if the only values that are
captured are this, context or widget, that can be accessed even from
methods of the State object.
This commit is contained in:
Carlo Bernaschina 2017-08-16 17:11:27 -07:00 committed by GitHub
parent 2e57189aa4
commit 272b0b956d
7 changed files with 45 additions and 25 deletions

View File

@ -179,10 +179,14 @@ class _ModalBottomSheet<T> extends StatefulWidget {
}
class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> {
void _navigatorPop() {
Navigator.pop(context);
}
@override
Widget build(BuildContext context) {
return new GestureDetector(
onTap: () => Navigator.pop(context),
onTap: _navigatorPop,
child: new AnimatedBuilder(
animation: widget.route.animation,
builder: (BuildContext context, Widget child) {

View File

@ -735,6 +735,10 @@ class _DatePickerDialogState extends State<_DatePickerDialog> {
Navigator.pop(context, _selectedDate);
}
void _handleMonthHeaderTap() {
_handleModeChanged(DatePickerMode.year);
}
Widget _buildPicker() {
assert(_mode != null);
switch (_mode) {
@ -746,7 +750,7 @@ class _DatePickerDialogState extends State<_DatePickerDialog> {
firstDate: widget.firstDate,
lastDate: widget.lastDate,
selectableDayPredicate: widget.selectableDayPredicate,
onMonthHeaderTap: () { _handleModeChanged(DatePickerMode.year); },
onMonthHeaderTap: _handleMonthHeaderTap,
);
case DatePickerMode.year:
return new YearPicker(

View File

@ -265,11 +265,7 @@ class _InkResponseState<T extends InkResponse> extends State<T> with AutomaticKe
shape: widget.highlightShape,
borderRadius: widget.borderRadius,
rectCallback: widget.getRectCallback(referenceBox),
onRemoved: () {
assert(_lastHighlight != null);
_lastHighlight = null;
updateKeepAlive();
},
onRemoved: _handleInkHighlightRemoval,
);
updateKeepAlive();
} else {
@ -283,6 +279,12 @@ class _InkResponseState<T extends InkResponse> extends State<T> with AutomaticKe
widget.onHighlightChanged(value);
}
void _handleInkHighlightRemoval() {
assert(_lastHighlight != null);
_lastHighlight = null;
updateKeepAlive();
}
void _handleTapDown(TapDownDetails details) {
final RenderBox referenceBox = context.findRenderObject();
final RectCallback rectCallback = widget.getRectCallback(referenceBox);

View File

@ -272,6 +272,14 @@ class PaginatedDataTableState extends State<PaginatedDataTable> {
return result;
}
void _handlePrevious() {
pageTo(math.max(_firstRowIndex - widget.rowsPerPage, 0));
}
void _handleNext() {
pageTo(_firstRowIndex + widget.rowsPerPage);
}
final GlobalKey _tableKey = new GlobalKey();
@override
@ -346,18 +354,14 @@ class PaginatedDataTableState extends State<PaginatedDataTable> {
icon: const Icon(Icons.chevron_left),
padding: EdgeInsets.zero,
tooltip: 'Previous page',
onPressed: _firstRowIndex <= 0 ? null : () {
pageTo(math.max(_firstRowIndex - widget.rowsPerPage, 0));
}
onPressed: _firstRowIndex <= 0 ? null : _handlePrevious
),
new Container(width: 24.0),
new IconButton(
icon: const Icon(Icons.chevron_right),
padding: EdgeInsets.zero,
tooltip: 'Next page',
onPressed: (!_rowCountApproximate && (_firstRowIndex + widget.rowsPerPage >= _rowCount)) ? null : () {
pageTo(_firstRowIndex + widget.rowsPerPage);
}
onPressed: (!_rowCountApproximate && (_firstRowIndex + widget.rowsPerPage >= _rowCount)) ? null : _handleNext
),
new Container(width: 14.0),
]);

View File

@ -177,16 +177,18 @@ class _TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
super.dispose();
}
void _handleLongPress() {
final bool tooltipCreated = ensureTooltipVisible();
if (tooltipCreated)
Feedback.forLongPress(context);
}
@override
Widget build(BuildContext context) {
assert(Overlay.of(context, debugRequiredFor: widget) != null);
return new GestureDetector(
behavior: HitTestBehavior.opaque,
onLongPress: () {
final bool tooltipCreated = ensureTooltipVisible();
if (tooltipCreated)
Feedback.forLongPress(context);
},
onLongPress: _handleLongPress,
excludeFromSemantics: true,
child: new Semantics(
label: widget.message,

View File

@ -183,6 +183,13 @@ class UserAccountsDrawerHeader extends StatefulWidget {
class _UserAccountsDrawerHeaderState extends State<UserAccountsDrawerHeader> {
bool _isOpen = false;
void _handleDetailsPressed() {
setState(() {
_isOpen = !_isOpen;
});
widget.onDetailsPressed();
}
@override
Widget build(BuildContext context) {
assert(debugCheckHasMaterial(context));
@ -204,12 +211,7 @@ class _UserAccountsDrawerHeaderState extends State<UserAccountsDrawerHeader> {
accountName: widget.accountName,
accountEmail: widget.accountEmail,
isOpen: _isOpen,
onTap: widget.onDetailsPressed == null ? null : () {
setState(() {
_isOpen = !_isOpen;
});
widget.onDetailsPressed();
},
onTap: widget.onDetailsPressed == null ? null : _handleDetailsPressed,
),
],
),

View File

@ -528,12 +528,14 @@ class _DragAvatar<T> extends Drag {
_enteredTargets.add(target);
return target.didEnter(this);
},
orElse: () => null
orElse: _null
);
_activeTarget = newTarget;
}
static Null _null() => null;
Iterable<_DragTargetState<T>> _getDragTargets(List<HitTestEntry> path) sync* {
// Look for the RenderBoxes that corresponds to the hit target (the hit target
// widgets build RenderMetaData boxes for us for this purpose).