Commit c55097da authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by GitHub

apply prefer_asserts_in_initializer_list lint (#10463)

parent fe520201
...@@ -63,12 +63,11 @@ class MaterialApp extends StatefulWidget { ...@@ -63,12 +63,11 @@ class MaterialApp extends StatefulWidget {
this.checkerboardOffscreenLayers: false, this.checkerboardOffscreenLayers: false,
this.showSemanticsDebugger: false, this.showSemanticsDebugger: false,
this.debugShowCheckedModeBanner: true this.debugShowCheckedModeBanner: true
}) : super(key: key) { }) : assert(debugShowMaterialGrid != null),
assert(debugShowMaterialGrid != null); assert(routes != null),
assert(routes != null); assert(!routes.containsKey(Navigator.defaultRouteName) || (home == null)),
assert(!routes.containsKey(Navigator.defaultRouteName) || (home == null)); assert(routes.containsKey(Navigator.defaultRouteName) || (home != null) || (onGenerateRoute != null)),
assert(routes.containsKey(Navigator.defaultRouteName) || (home != null) || (onGenerateRoute != null)); super(key: key);
}
/// A one-line description of this app for use in the window manager. /// A one-line description of this app for use in the window manager.
final String title; final String title;
......
...@@ -138,13 +138,12 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget { ...@@ -138,13 +138,12 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
this.centerTitle, this.centerTitle,
this.toolbarOpacity: 1.0, this.toolbarOpacity: 1.0,
this.bottomOpacity: 1.0, this.bottomOpacity: 1.0,
}) : preferredSize = new Size.fromHeight(kToolbarHeight + (bottom?.preferredSize?.height ?? 0.0)), }) : assert(elevation != null),
super(key: key) { assert(primary != null),
assert(elevation != null); assert(toolbarOpacity != null),
assert(primary != null); assert(bottomOpacity != null),
assert(toolbarOpacity != null); preferredSize = new Size.fromHeight(kToolbarHeight + (bottom?.preferredSize?.height ?? 0.0)),
assert(bottomOpacity != null); super(key: key);
}
/// A widget to display before the [title]. /// A widget to display before the [title].
/// ///
...@@ -513,9 +512,8 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate { ...@@ -513,9 +512,8 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
@required this.floating, @required this.floating,
@required this.pinned, @required this.pinned,
@required this.snapConfiguration, @required this.snapConfiguration,
}) : _bottomHeight = bottom?.preferredSize?.height ?? 0.0 { }) : assert(primary || topPadding == 0.0),
assert(primary || topPadding == 0.0); _bottomHeight = bottom?.preferredSize?.height ?? 0.0;
}
final Widget leading; final Widget leading;
final Widget title; final Widget title;
......
...@@ -69,14 +69,13 @@ class BottomNavigationBar extends StatefulWidget { ...@@ -69,14 +69,13 @@ class BottomNavigationBar extends StatefulWidget {
this.type: BottomNavigationBarType.fixed, this.type: BottomNavigationBarType.fixed,
this.fixedColor, this.fixedColor,
this.iconSize: 24.0, this.iconSize: 24.0,
}) : super(key: key) { }) : assert(items != null),
assert(items != null); assert(items.length >= 2),
assert(items.length >= 2); assert(0 <= currentIndex && currentIndex < items.length),
assert(0 <= currentIndex && currentIndex < items.length); assert(type != null),
assert(type != null); assert(type == BottomNavigationBarType.fixed || fixedColor == null),
assert(type == BottomNavigationBarType.fixed || fixedColor == null); assert(iconSize != null),
assert(iconSize != null); super(key: key);
}
/// The interactive items laid out within the bottom navigation bar. /// The interactive items laid out within the bottom navigation bar.
final List<BottomNavigationBarItem> items; final List<BottomNavigationBarItem> items;
...@@ -450,11 +449,9 @@ class _Circle { ...@@ -450,11 +449,9 @@ class _Circle {
@required this.index, @required this.index,
@required this.color, @required this.color,
@required TickerProvider vsync, @required TickerProvider vsync,
}) { }) : assert(state != null),
assert(state != null); assert(index != null),
assert(index != null); assert(color != null) {
assert(color != null);
controller = new AnimationController( controller = new AnimationController(
duration: kThemeAnimationDuration, duration: kThemeAnimationDuration,
vsync: vsync, vsync: vsync,
......
...@@ -259,14 +259,14 @@ class DataTable extends StatelessWidget { ...@@ -259,14 +259,14 @@ class DataTable extends StatelessWidget {
this.sortAscending: true, this.sortAscending: true,
this.onSelectAll, this.onSelectAll,
@required this.rows @required this.rows
}) : _onlyTextColumn = _initOnlyTextColumn(columns), super(key: key) { }) : assert(columns != null),
assert(columns != null); assert(columns.isNotEmpty),
assert(columns.isNotEmpty); assert(sortColumnIndex == null || (sortColumnIndex >= 0 && sortColumnIndex < columns.length)),
assert(sortColumnIndex == null || (sortColumnIndex >= 0 && sortColumnIndex < columns.length)); assert(sortAscending != null),
assert(sortAscending != null); assert(rows != null),
assert(rows != null); assert(!rows.any((DataRow row) => row.cells.length != columns.length)),
assert(!rows.any((DataRow row) => row.cells.length != columns.length)); _onlyTextColumn = _initOnlyTextColumn(columns),
} super(key: key);
/// The configuration and labels for the columns in the table. /// The configuration and labels for the columns in the table.
final List<DataColumn> columns; final List<DataColumn> columns;
......
...@@ -181,14 +181,13 @@ class DayPicker extends StatelessWidget { ...@@ -181,14 +181,13 @@ class DayPicker extends StatelessWidget {
@required this.lastDate, @required this.lastDate,
@required this.displayedMonth, @required this.displayedMonth,
this.selectableDayPredicate, this.selectableDayPredicate,
}) : super(key: key) { }) : assert(selectedDate != null),
assert(selectedDate != null); assert(currentDate != null),
assert(currentDate != null); assert(onChanged != null),
assert(onChanged != null); assert(displayedMonth != null),
assert(displayedMonth != null); assert(!firstDate.isAfter(lastDate)),
assert(!firstDate.isAfter(lastDate)); assert(selectedDate.isAfter(firstDate) || selectedDate.isAtSameMomentAs(firstDate)),
assert(selectedDate.isAfter(firstDate) || selectedDate.isAtSameMomentAs(firstDate)); super(key: key);
}
/// The currently selected date. /// The currently selected date.
/// ///
...@@ -331,12 +330,11 @@ class MonthPicker extends StatefulWidget { ...@@ -331,12 +330,11 @@ class MonthPicker extends StatefulWidget {
@required this.firstDate, @required this.firstDate,
@required this.lastDate, @required this.lastDate,
this.selectableDayPredicate, this.selectableDayPredicate,
}) : super(key: key) { }) : assert(selectedDate != null),
assert(selectedDate != null); assert(onChanged != null),
assert(onChanged != null); assert(!firstDate.isAfter(lastDate)),
assert(!firstDate.isAfter(lastDate)); assert(selectedDate.isAfter(firstDate) || selectedDate.isAtSameMomentAs(firstDate)),
assert(selectedDate.isAfter(firstDate) || selectedDate.isAtSameMomentAs(firstDate)); super(key: key);
}
/// The currently selected date. /// The currently selected date.
/// ///
...@@ -519,11 +517,10 @@ class YearPicker extends StatefulWidget { ...@@ -519,11 +517,10 @@ class YearPicker extends StatefulWidget {
@required this.onChanged, @required this.onChanged,
@required this.firstDate, @required this.firstDate,
@required this.lastDate, @required this.lastDate,
}) : super(key: key) { }) : assert(selectedDate != null),
assert(selectedDate != null); assert(onChanged != null),
assert(onChanged != null); assert(!firstDate.isAfter(lastDate)),
assert(!firstDate.isAfter(lastDate)); super(key: key);
}
/// The currently selected date. /// The currently selected date.
/// ///
......
...@@ -319,9 +319,8 @@ class _DialogRoute<T> extends PopupRoute<T> { ...@@ -319,9 +319,8 @@ class _DialogRoute<T> extends PopupRoute<T> {
@required this.theme, @required this.theme,
bool barrierDismissible: true, bool barrierDismissible: true,
@required this.child, @required this.child,
}) : _barrierDismissible = barrierDismissible { }) : assert(barrierDismissible != null),
assert(barrierDismissible != null); _barrierDismissible = barrierDismissible;
}
final Widget child; final Widget child;
final ThemeData theme; final ThemeData theme;
......
...@@ -266,9 +266,7 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> { ...@@ -266,9 +266,7 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> {
this.elevation: 8, this.elevation: 8,
this.theme, this.theme,
@required this.style, @required this.style,
}) { }) : assert(style != null);
assert(style != null);
}
final List<DropdownMenuItem<T>> items; final List<DropdownMenuItem<T>> items;
final Rect buttonRect; final Rect buttonRect;
...@@ -425,11 +423,9 @@ class DropdownButton<T> extends StatefulWidget { ...@@ -425,11 +423,9 @@ class DropdownButton<T> extends StatefulWidget {
this.style, this.style,
this.iconSize: 24.0, this.iconSize: 24.0,
this.isDense: false, this.isDense: false,
}) : super(key: key) { }) : assert(items != null),
assert(items != null); assert(value == null || items.where((DropdownMenuItem<T> item) => item.value == value).length == 1),
assert(value == null || super(key: key);
items.where((DropdownMenuItem<T> item) => item.value == value).length == 1);
}
/// The list of possible items to select among. /// The list of possible items to select among.
final List<DropdownMenuItem<T>> items; final List<DropdownMenuItem<T>> items;
......
...@@ -43,11 +43,9 @@ class ExpansionPanel { ...@@ -43,11 +43,9 @@ class ExpansionPanel {
@required this.headerBuilder, @required this.headerBuilder,
@required this.body, @required this.body,
this.isExpanded: false this.isExpanded: false
}) { }) : assert(headerBuilder != null),
assert(headerBuilder != null); assert(body != null),
assert(body != null);
assert(isExpanded != null); assert(isExpanded != null);
}
/// The widget builder that builds the expansion panels' header. /// The widget builder that builds the expansion panels' header.
final ExpansionPanelHeaderBuilder headerBuilder; final ExpansionPanelHeaderBuilder headerBuilder;
......
...@@ -43,13 +43,13 @@ class InkHighlight extends InkFeature { ...@@ -43,13 +43,13 @@ class InkHighlight extends InkFeature {
BorderRadius borderRadius, BorderRadius borderRadius,
RectCallback rectCallback, RectCallback rectCallback,
VoidCallback onRemoved, VoidCallback onRemoved,
}) : _color = color, }) : assert(color != null),
assert(shape != null),
_color = color,
_shape = shape, _shape = shape,
_borderRadius = borderRadius ?? BorderRadius.zero, _borderRadius = borderRadius ?? BorderRadius.zero,
_rectCallback = rectCallback, _rectCallback = rectCallback,
super(controller: controller, referenceBox: referenceBox, onRemoved: onRemoved) { super(controller: controller, referenceBox: referenceBox, onRemoved: onRemoved) {
assert(color != null);
assert(shape != null);
_alphaController = new AnimationController(duration: _kHighlightFadeDuration, vsync: controller.vsync) _alphaController = new AnimationController(duration: _kHighlightFadeDuration, vsync: controller.vsync)
..addListener(controller.markNeedsPaint) ..addListener(controller.markNeedsPaint)
..addStatusListener(_handleAlphaStatusChanged) ..addStatusListener(_handleAlphaStatusChanged)
......
...@@ -366,10 +366,9 @@ abstract class InkFeature { ...@@ -366,10 +366,9 @@ abstract class InkFeature {
@required MaterialInkController controller, @required MaterialInkController controller,
@required this.referenceBox, @required this.referenceBox,
this.onRemoved this.onRemoved
}) : _controller = controller { }) : assert(controller != null),
assert(_controller != null); assert(referenceBox != null),
assert(referenceBox != null); _controller = controller;
}
/// The [MaterialInkController] associated with this [InkFeature]. /// The [MaterialInkController] associated with this [InkFeature].
/// ///
......
...@@ -61,10 +61,9 @@ class MaterialPageRoute<T> extends PageRoute<T> { ...@@ -61,10 +61,9 @@ class MaterialPageRoute<T> extends PageRoute<T> {
RouteSettings settings: const RouteSettings(), RouteSettings settings: const RouteSettings(),
this.maintainState: true, this.maintainState: true,
this.fullscreenDialog: false, this.fullscreenDialog: false,
}) : super(settings: settings) { }) : assert(builder != null),
assert(builder != null); assert(opaque),
assert(opaque); super(settings: settings);
}
/// Builds the primary contents of the route. /// Builds the primary contents of the route.
final WidgetBuilder builder; final WidgetBuilder builder;
......
...@@ -73,21 +73,20 @@ class PaginatedDataTable extends StatefulWidget { ...@@ -73,21 +73,20 @@ class PaginatedDataTable extends StatefulWidget {
this.availableRowsPerPage: const <int>[defaultRowsPerPage, defaultRowsPerPage * 2, defaultRowsPerPage * 5, defaultRowsPerPage * 10], this.availableRowsPerPage: const <int>[defaultRowsPerPage, defaultRowsPerPage * 2, defaultRowsPerPage * 5, defaultRowsPerPage * 10],
this.onRowsPerPageChanged, this.onRowsPerPageChanged,
@required this.source @required this.source
}) : super(key: key) { }) : assert(header != null),
assert(header != null); assert(columns != null),
assert(columns != null); assert(columns.isNotEmpty),
assert(columns.isNotEmpty); assert(sortColumnIndex == null || (sortColumnIndex >= 0 && sortColumnIndex < columns.length)),
assert(sortColumnIndex == null || (sortColumnIndex >= 0 && sortColumnIndex < columns.length)); assert(sortAscending != null),
assert(sortAscending != null); assert(rowsPerPage != null),
assert(rowsPerPage != null); assert(rowsPerPage > 0),
assert(rowsPerPage > 0);
assert(() { assert(() {
if (onRowsPerPageChanged != null) if (onRowsPerPageChanged != null)
assert(availableRowsPerPage != null && availableRowsPerPage.contains(rowsPerPage)); assert(availableRowsPerPage != null && availableRowsPerPage.contains(rowsPerPage));
return true; return true;
}); }),
assert(source != null); assert(source != null),
} super(key: key);
/// The table card's header. /// The table card's header.
/// ///
......
...@@ -84,8 +84,8 @@ class _ScrollbarState extends State<Scrollbar> with TickerProviderStateMixin { ...@@ -84,8 +84,8 @@ class _ScrollbarState extends State<Scrollbar> with TickerProviderStateMixin {
} }
class _ScrollbarPainter extends ChangeNotifier implements CustomPainter { class _ScrollbarPainter extends ChangeNotifier implements CustomPainter {
_ScrollbarPainter(TickerProvider vsync) { _ScrollbarPainter(TickerProvider vsync)
assert(vsync != null); : assert(vsync != null) {
_fadeController = new AnimationController(duration: _kThumbFadeDuration, vsync: vsync); _fadeController = new AnimationController(duration: _kThumbFadeDuration, vsync: vsync);
_opacity = new CurvedAnimation(parent: _fadeController, curve: Curves.fastOutSlowIn) _opacity = new CurvedAnimation(parent: _fadeController, curve: Curves.fastOutSlowIn)
..addListener(notifyListeners); ..addListener(notifyListeners);
......
...@@ -280,12 +280,12 @@ class _RenderSlider extends RenderBox implements SemanticsActionHandler { ...@@ -280,12 +280,12 @@ class _RenderSlider extends RenderBox implements SemanticsActionHandler {
TextTheme textTheme, TextTheme textTheme,
this.onChanged, this.onChanged,
TickerProvider vsync, TickerProvider vsync,
}) : _value = value, }) : assert(value != null && value >= 0.0 && value <= 1.0),
_value = value,
_divisions = divisions, _divisions = divisions,
_activeColor = activeColor, _activeColor = activeColor,
_thumbOpenAtMin = thumbOpenAtMin, _thumbOpenAtMin = thumbOpenAtMin,
_textTheme = textTheme { _textTheme = textTheme {
assert(value != null && value >= 0.0 && value <= 1.0);
this.label = label; this.label = label;
final GestureArenaTeam team = new GestureArenaTeam(); final GestureArenaTeam team = new GestureArenaTeam();
_drag = new HorizontalDragGestureRecognizer() _drag = new HorizontalDragGestureRecognizer()
......
...@@ -140,12 +140,11 @@ class Stepper extends StatefulWidget { ...@@ -140,12 +140,11 @@ class Stepper extends StatefulWidget {
this.onStepTapped, this.onStepTapped,
this.onStepContinue, this.onStepContinue,
this.onStepCancel, this.onStepCancel,
}) : super(key: key) { }) : assert(steps != null),
assert(steps != null); assert(type != null),
assert(type != null); assert(currentStep != null),
assert(currentStep != null); assert(0 <= currentStep && currentStep < steps.length),
assert(0 <= currentStep && currentStep < steps.length); super(key: key);
}
/// The steps of the stepper whose titles, subtitles, icons always get shown. /// The steps of the stepper whose titles, subtitles, icons always get shown.
/// ///
......
...@@ -63,16 +63,15 @@ import 'constants.dart'; ...@@ -63,16 +63,15 @@ import 'constants.dart';
class TabController extends ChangeNotifier { class TabController extends ChangeNotifier {
/// Creates an object that manages the state required by [TabBar] and a [TabBarView]. /// Creates an object that manages the state required by [TabBar] and a [TabBarView].
TabController({ int initialIndex: 0, @required this.length, @required TickerProvider vsync }) TabController({ int initialIndex: 0, @required this.length, @required TickerProvider vsync })
: _index = initialIndex, : assert(length != null && length > 1),
assert(initialIndex != null && initialIndex >= 0 && initialIndex < length),
_index = initialIndex,
_previousIndex = initialIndex, _previousIndex = initialIndex,
_animationController = new AnimationController( _animationController = new AnimationController(
value: initialIndex.toDouble(), value: initialIndex.toDouble(),
upperBound: (length - 1).toDouble(), upperBound: (length - 1).toDouble(),
vsync: vsync vsync: vsync
) { );
assert(length != null && length > 1);
assert(initialIndex != null && initialIndex >= 0 && initialIndex < length);
}
/// An animation whose value represents the current position of the [TabBar]'s /// An animation whose value represents the current position of the [TabBar]'s
/// selected tab indicator as well as the scrollOffsets of the [TabBar] /// selected tab indicator as well as the scrollOffsets of the [TabBar]
......
...@@ -155,16 +155,15 @@ class _TabLabelBarRenderer extends RenderFlex { ...@@ -155,16 +155,15 @@ class _TabLabelBarRenderer extends RenderFlex {
CrossAxisAlignment crossAxisAlignment, CrossAxisAlignment crossAxisAlignment,
TextBaseline textBaseline, TextBaseline textBaseline,
@required this.onPerformLayout, @required this.onPerformLayout,
}) : super( }) : assert(onPerformLayout != null),
super(
children: children, children: children,
direction: direction, direction: direction,
mainAxisSize: mainAxisSize, mainAxisSize: mainAxisSize,
mainAxisAlignment: mainAxisAlignment, mainAxisAlignment: mainAxisAlignment,
crossAxisAlignment: crossAxisAlignment, crossAxisAlignment: crossAxisAlignment,
textBaseline: textBaseline, textBaseline: textBaseline,
) { );
assert(onPerformLayout != null);
}
ValueChanged<List<double>> onPerformLayout; ValueChanged<List<double>> onPerformLayout;
...@@ -411,10 +410,9 @@ class TabBar extends StatefulWidget implements PreferredSizeWidget { ...@@ -411,10 +410,9 @@ class TabBar extends StatefulWidget implements PreferredSizeWidget {
this.labelStyle, this.labelStyle,
this.unselectedLabelColor, this.unselectedLabelColor,
this.unselectedLabelStyle, this.unselectedLabelStyle,
}) : super(key: key) { }) : assert(tabs != null && tabs.length > 1),
assert(tabs != null && tabs.length > 1); assert(isScrollable != null),
assert(isScrollable != null); super(key: key);
}
/// Typically a list of [Tab] widgets. /// Typically a list of [Tab] widgets.
final List<Widget> tabs; final List<Widget> tabs;
...@@ -741,9 +739,8 @@ class TabBarView extends StatefulWidget { ...@@ -741,9 +739,8 @@ class TabBarView extends StatefulWidget {
Key key, Key key,
@required this.children, @required this.children,
this.controller, this.controller,
}) : super(key: key) { }) : assert(children != null && children.length > 1),
assert(children != null && children.length > 1); super(key: key);
}
/// This widget's selection and animation state. /// This widget's selection and animation state.
/// ///
......
...@@ -30,16 +30,16 @@ abstract class RenderToggleable extends RenderConstrainedBox implements Semantic ...@@ -30,16 +30,16 @@ abstract class RenderToggleable extends RenderConstrainedBox implements Semantic
@required Color inactiveColor, @required Color inactiveColor,
ValueChanged<bool> onChanged, ValueChanged<bool> onChanged,
@required TickerProvider vsync, @required TickerProvider vsync,
}) : _value = value, }) : assert(value != null),
assert(activeColor != null),
assert(inactiveColor != null),
assert(vsync != null),
_value = value,
_activeColor = activeColor, _activeColor = activeColor,
_inactiveColor = inactiveColor, _inactiveColor = inactiveColor,
_onChanged = onChanged, _onChanged = onChanged,
_vsync = vsync, _vsync = vsync,
super(additionalConstraints: new BoxConstraints.tight(size)) { super(additionalConstraints: new BoxConstraints.tight(size)) {
assert(value != null);
assert(activeColor != null);
assert(inactiveColor != null);
assert(vsync != null);
_tap = new TapGestureRecognizer() _tap = new TapGestureRecognizer()
..onTapDown = _handleTapDown ..onTapDown = _handleTapDown
..onTap = _handleTap ..onTap = _handleTap
......
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