Commit 272b0b95 authored by Carlo Bernaschina's avatar Carlo Bernaschina Committed by GitHub

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.
parent 2e57189a
...@@ -179,10 +179,14 @@ class _ModalBottomSheet<T> extends StatefulWidget { ...@@ -179,10 +179,14 @@ class _ModalBottomSheet<T> extends StatefulWidget {
} }
class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> { class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> {
void _navigatorPop() {
Navigator.pop(context);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new GestureDetector( return new GestureDetector(
onTap: () => Navigator.pop(context), onTap: _navigatorPop,
child: new AnimatedBuilder( child: new AnimatedBuilder(
animation: widget.route.animation, animation: widget.route.animation,
builder: (BuildContext context, Widget child) { builder: (BuildContext context, Widget child) {
......
...@@ -735,6 +735,10 @@ class _DatePickerDialogState extends State<_DatePickerDialog> { ...@@ -735,6 +735,10 @@ class _DatePickerDialogState extends State<_DatePickerDialog> {
Navigator.pop(context, _selectedDate); Navigator.pop(context, _selectedDate);
} }
void _handleMonthHeaderTap() {
_handleModeChanged(DatePickerMode.year);
}
Widget _buildPicker() { Widget _buildPicker() {
assert(_mode != null); assert(_mode != null);
switch (_mode) { switch (_mode) {
...@@ -746,7 +750,7 @@ class _DatePickerDialogState extends State<_DatePickerDialog> { ...@@ -746,7 +750,7 @@ class _DatePickerDialogState extends State<_DatePickerDialog> {
firstDate: widget.firstDate, firstDate: widget.firstDate,
lastDate: widget.lastDate, lastDate: widget.lastDate,
selectableDayPredicate: widget.selectableDayPredicate, selectableDayPredicate: widget.selectableDayPredicate,
onMonthHeaderTap: () { _handleModeChanged(DatePickerMode.year); }, onMonthHeaderTap: _handleMonthHeaderTap,
); );
case DatePickerMode.year: case DatePickerMode.year:
return new YearPicker( return new YearPicker(
......
...@@ -265,11 +265,7 @@ class _InkResponseState<T extends InkResponse> extends State<T> with AutomaticKe ...@@ -265,11 +265,7 @@ class _InkResponseState<T extends InkResponse> extends State<T> with AutomaticKe
shape: widget.highlightShape, shape: widget.highlightShape,
borderRadius: widget.borderRadius, borderRadius: widget.borderRadius,
rectCallback: widget.getRectCallback(referenceBox), rectCallback: widget.getRectCallback(referenceBox),
onRemoved: () { onRemoved: _handleInkHighlightRemoval,
assert(_lastHighlight != null);
_lastHighlight = null;
updateKeepAlive();
},
); );
updateKeepAlive(); updateKeepAlive();
} else { } else {
...@@ -283,6 +279,12 @@ class _InkResponseState<T extends InkResponse> extends State<T> with AutomaticKe ...@@ -283,6 +279,12 @@ class _InkResponseState<T extends InkResponse> extends State<T> with AutomaticKe
widget.onHighlightChanged(value); widget.onHighlightChanged(value);
} }
void _handleInkHighlightRemoval() {
assert(_lastHighlight != null);
_lastHighlight = null;
updateKeepAlive();
}
void _handleTapDown(TapDownDetails details) { void _handleTapDown(TapDownDetails details) {
final RenderBox referenceBox = context.findRenderObject(); final RenderBox referenceBox = context.findRenderObject();
final RectCallback rectCallback = widget.getRectCallback(referenceBox); final RectCallback rectCallback = widget.getRectCallback(referenceBox);
......
...@@ -272,6 +272,14 @@ class PaginatedDataTableState extends State<PaginatedDataTable> { ...@@ -272,6 +272,14 @@ class PaginatedDataTableState extends State<PaginatedDataTable> {
return result; return result;
} }
void _handlePrevious() {
pageTo(math.max(_firstRowIndex - widget.rowsPerPage, 0));
}
void _handleNext() {
pageTo(_firstRowIndex + widget.rowsPerPage);
}
final GlobalKey _tableKey = new GlobalKey(); final GlobalKey _tableKey = new GlobalKey();
@override @override
...@@ -346,18 +354,14 @@ class PaginatedDataTableState extends State<PaginatedDataTable> { ...@@ -346,18 +354,14 @@ class PaginatedDataTableState extends State<PaginatedDataTable> {
icon: const Icon(Icons.chevron_left), icon: const Icon(Icons.chevron_left),
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
tooltip: 'Previous page', tooltip: 'Previous page',
onPressed: _firstRowIndex <= 0 ? null : () { onPressed: _firstRowIndex <= 0 ? null : _handlePrevious
pageTo(math.max(_firstRowIndex - widget.rowsPerPage, 0));
}
), ),
new Container(width: 24.0), new Container(width: 24.0),
new IconButton( new IconButton(
icon: const Icon(Icons.chevron_right), icon: const Icon(Icons.chevron_right),
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
tooltip: 'Next page', tooltip: 'Next page',
onPressed: (!_rowCountApproximate && (_firstRowIndex + widget.rowsPerPage >= _rowCount)) ? null : () { onPressed: (!_rowCountApproximate && (_firstRowIndex + widget.rowsPerPage >= _rowCount)) ? null : _handleNext
pageTo(_firstRowIndex + widget.rowsPerPage);
}
), ),
new Container(width: 14.0), new Container(width: 14.0),
]); ]);
......
...@@ -177,16 +177,18 @@ class _TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin { ...@@ -177,16 +177,18 @@ class _TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
super.dispose(); super.dispose();
} }
void _handleLongPress() {
final bool tooltipCreated = ensureTooltipVisible();
if (tooltipCreated)
Feedback.forLongPress(context);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
assert(Overlay.of(context, debugRequiredFor: widget) != null); assert(Overlay.of(context, debugRequiredFor: widget) != null);
return new GestureDetector( return new GestureDetector(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onLongPress: () { onLongPress: _handleLongPress,
final bool tooltipCreated = ensureTooltipVisible();
if (tooltipCreated)
Feedback.forLongPress(context);
},
excludeFromSemantics: true, excludeFromSemantics: true,
child: new Semantics( child: new Semantics(
label: widget.message, label: widget.message,
......
...@@ -183,6 +183,13 @@ class UserAccountsDrawerHeader extends StatefulWidget { ...@@ -183,6 +183,13 @@ class UserAccountsDrawerHeader extends StatefulWidget {
class _UserAccountsDrawerHeaderState extends State<UserAccountsDrawerHeader> { class _UserAccountsDrawerHeaderState extends State<UserAccountsDrawerHeader> {
bool _isOpen = false; bool _isOpen = false;
void _handleDetailsPressed() {
setState(() {
_isOpen = !_isOpen;
});
widget.onDetailsPressed();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
assert(debugCheckHasMaterial(context)); assert(debugCheckHasMaterial(context));
...@@ -204,12 +211,7 @@ class _UserAccountsDrawerHeaderState extends State<UserAccountsDrawerHeader> { ...@@ -204,12 +211,7 @@ class _UserAccountsDrawerHeaderState extends State<UserAccountsDrawerHeader> {
accountName: widget.accountName, accountName: widget.accountName,
accountEmail: widget.accountEmail, accountEmail: widget.accountEmail,
isOpen: _isOpen, isOpen: _isOpen,
onTap: widget.onDetailsPressed == null ? null : () { onTap: widget.onDetailsPressed == null ? null : _handleDetailsPressed,
setState(() {
_isOpen = !_isOpen;
});
widget.onDetailsPressed();
},
), ),
], ],
), ),
......
...@@ -528,12 +528,14 @@ class _DragAvatar<T> extends Drag { ...@@ -528,12 +528,14 @@ class _DragAvatar<T> extends Drag {
_enteredTargets.add(target); _enteredTargets.add(target);
return target.didEnter(this); return target.didEnter(this);
}, },
orElse: () => null orElse: _null
); );
_activeTarget = newTarget; _activeTarget = newTarget;
} }
static Null _null() => null;
Iterable<_DragTargetState<T>> _getDragTargets(List<HitTestEntry> path) sync* { Iterable<_DragTargetState<T>> _getDragTargets(List<HitTestEntry> path) sync* {
// Look for the RenderBoxes that corresponds to the hit target (the hit target // Look for the RenderBoxes that corresponds to the hit target (the hit target
// widgets build RenderMetaData boxes for us for this purpose). // widgets build RenderMetaData boxes for us for this purpose).
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment