Commit 7d713263 authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by GitHub

apply prefer_asserts_in_initializer_list lint (#10540)

parent 3e645ee2
......@@ -117,10 +117,9 @@ class ListModel<E> {
@required this.listKey,
@required this.removedItemBuilder,
Iterable<E> initialItems,
}) : _items = new List<E>.from(initialItems ?? <E>[]) {
assert(listKey != null);
assert(removedItemBuilder != null);
}
}) : assert(listKey != null),
assert(removedItemBuilder != null),
_items = new List<E>.from(initialItems ?? <E>[]);
final GlobalKey<AnimatedListState> listKey;
final dynamic removedItemBuilder;
......@@ -159,11 +158,10 @@ class CardItem extends StatelessWidget {
this.onTap,
@required this.item,
this.selected: false
}) : super(key: key) {
assert(animation != null);
assert(item != null && item >= 0);
assert(selected != null);
}
}) : assert(animation != null),
assert(item != null && item >= 0),
assert(selected != null),
super(key: key);
final Animation<double> animation;
final VoidCallback onTap;
......
......@@ -35,10 +35,10 @@ class _RenderStatusBarPaddingSliver extends RenderSliver {
_RenderStatusBarPaddingSliver({
@required double maxHeight,
@required double scrollFactor,
}) : _maxHeight = maxHeight, _scrollFactor = scrollFactor {
assert(maxHeight != null && maxHeight >= 0.0);
assert(scrollFactor != null && scrollFactor >= 1.0);
}
}) : assert(maxHeight != null && maxHeight >= 0.0),
assert(scrollFactor != null && scrollFactor >= 1.0),
_maxHeight = maxHeight,
_scrollFactor = scrollFactor;
// The height of the status bar
double get maxHeight => _maxHeight;
......@@ -79,10 +79,9 @@ class _StatusBarPaddingSliver extends SingleChildRenderObjectWidget {
Key key,
@required this.maxHeight,
this.scrollFactor: 5.0,
}) : super(key: key) {
assert(maxHeight != null && maxHeight >= 0.0);
assert(scrollFactor != null && scrollFactor >= 1.0);
}
}) : assert(maxHeight != null && maxHeight >= 0.0),
assert(scrollFactor != null && scrollFactor >= 1.0),
super(key: key);
final double maxHeight;
final double scrollFactor;
......@@ -272,14 +271,13 @@ class _AllSectionsView extends AnimatedWidget {
this.midHeight,
this.maxHeight,
this.sectionCards: const <Widget>[],
}) : super(key: key, listenable: selectedIndex) {
assert(sections != null);
assert(sectionCards != null);
assert(sectionCards.length == sections.length);
assert(sectionIndex >= 0 && sectionIndex < sections.length);
assert(selectedIndex != null);
assert(selectedIndex.value >= 0.0 && selectedIndex.value < sections.length.toDouble());
}
}) : assert(sections != null),
assert(sectionCards != null),
assert(sectionCards.length == sections.length),
assert(sectionIndex >= 0 && sectionIndex < sections.length),
assert(selectedIndex != null),
assert(selectedIndex.value >= 0.0 && selectedIndex.value < sections.length.toDouble()),
super(key: key, listenable: selectedIndex);
final int sectionIndex;
final List<Section> sections;
......
......@@ -11,9 +11,9 @@ const double kSectionIndicatorWidth = 32.0;
// The card for a single section. Displays the section's gradient and background image.
class SectionCard extends StatelessWidget {
SectionCard({ Key key, @required this.section }) : super(key: key) {
assert(section != null);
}
SectionCard({ Key key, @required this.section })
: assert(section != null),
super(key: key);
final Section section;
......@@ -65,11 +65,10 @@ class SectionTitle extends StatelessWidget {
@required this.section,
@required this.scale,
@required this.opacity,
}) : super(key: key) {
assert(section != null);
assert(scale != null);
assert(opacity != null && opacity >= 0.0 && opacity <= 1.0);
}
}) : assert(section != null),
assert(scale != null),
assert(opacity != null && opacity >= 0.0 && opacity <= 1.0),
super(key: key);
final Section section;
final double scale;
......@@ -118,10 +117,10 @@ class SectionIndicator extends StatelessWidget {
// Display a single SectionDetail.
class SectionDetailView extends StatelessWidget {
SectionDetailView({ Key key, @required this.detail }) : super(key: key) {
assert(detail != null && detail.imageAsset != null);
assert((detail.imageAsset ?? detail.title) != null);
}
SectionDetailView({ Key key, @required this.detail })
: assert(detail != null && detail.imageAsset != null),
assert((detail.imageAsset ?? detail.title) != null),
super(key: key);
final SectionDetail detail;
......
......@@ -47,11 +47,10 @@ class ColorItem extends StatelessWidget {
@required this.index,
@required this.color,
this.prefix: '',
}) : super(key: key) {
assert(index != null);
assert(color != null);
assert(prefix != null);
}
}) : assert(index != null),
assert(color != null),
assert(prefix != null),
super(key: key);
final int index;
final Color color;
......@@ -84,9 +83,8 @@ class PaletteTabView extends StatelessWidget {
PaletteTabView({
Key key,
@required this.colors,
}) : super(key: key) {
assert(colors != null && colors.isValid);
}
}) : assert(colors != null && colors.isValid),
super(key: key);
final Palette colors;
......
......@@ -37,9 +37,9 @@ class _ContactCategory extends StatelessWidget {
}
class _ContactItem extends StatelessWidget {
_ContactItem({ Key key, this.icon, this.lines, this.tooltip, this.onPressed }) : super(key: key) {
assert(lines.length > 1);
}
_ContactItem({ Key key, this.icon, this.lines, this.tooltip, this.onPressed })
: assert(lines.length > 1),
super(key: key);
final IconData icon;
final List<String> lines;
......
......@@ -37,9 +37,9 @@ final List<TravelDestination> destinations = <TravelDestination>[
];
class TravelDestinationItem extends StatelessWidget {
TravelDestinationItem({ Key key, @required this.destination }) : super(key: key) {
assert(destination != null && destination.isValid);
}
TravelDestinationItem({ Key key, @required this.destination })
: assert(destination != null && destination.isValid),
super(key: key);
static final double height = 366.0;
final TravelDestination destination;
......
......@@ -19,11 +19,10 @@ enum DismissDialogAction {
class DateTimeItem extends StatelessWidget {
DateTimeItem({ Key key, DateTime dateTime, @required this.onChanged })
: date = new DateTime(dateTime.year, dateTime.month, dateTime.day),
: assert(onChanged != null),
date = new DateTime(dateTime.year, dateTime.month, dateTime.day),
time = new TimeOfDay(hour: dateTime.hour, minute: dateTime.minute),
super(key: key) {
assert(onChanged != null);
}
super(key: key);
final DateTime date;
final TimeOfDay time;
......
......@@ -143,11 +143,10 @@ class GridDemoPhotoItem extends StatelessWidget {
@required this.photo,
@required this.tileStyle,
@required this.onBannerTap
}) : super(key: key) {
assert(photo != null && photo.isValid);
assert(tileStyle != null);
assert(onBannerTap != null);
}
}) : assert(photo != null && photo.isValid),
assert(tileStyle != null),
assert(onBannerTap != null),
super(key: key);
final Photo photo;
final GridDemoTileStyle tileStyle;
......
......@@ -116,9 +116,9 @@ class _ShrineGridDelegate extends SliverGridDelegate {
// Displays the Vendor's name and avatar.
class _VendorItem extends StatelessWidget {
_VendorItem({ Key key, @required this.vendor }) : super(key: key) {
assert(vendor != null);
}
_VendorItem({ Key key, @required this.vendor })
: assert(vendor != null),
super(key: key);
final Vendor vendor;
......@@ -240,11 +240,11 @@ class _HeadingLayout extends MultiChildLayoutDelegate {
// A card that highlights the "featured" catalog item.
class _Heading extends StatelessWidget {
_Heading({ Key key, @required this.product }) : super(key: key) {
assert(product != null);
assert(product.featureTitle != null);
assert(product.featureDescription != null);
}
_Heading({ Key key, @required this.product })
: assert(product != null),
assert(product.featureTitle != null),
assert(product.featureDescription != null),
super(key: key);
final Product product;
......@@ -294,9 +294,9 @@ class _Heading extends StatelessWidget {
// A card that displays a product's image, price, and vendor. The _ProductItem
// cards appear in a grid below the heading.
class _ProductItem extends StatelessWidget {
_ProductItem({ Key key, @required this.product, this.onPressed }) : super(key: key) {
assert(product != null);
}
_ProductItem({ Key key, @required this.product, this.onPressed })
: assert(product != null),
super(key: key);
final Product product;
final VoidCallback onPressed;
......
......@@ -17,11 +17,10 @@ class _ProductItem extends StatelessWidget {
@required this.product,
@required this.quantity,
@required this.onChanged,
}) : super(key: key) {
assert(product != null);
assert(quantity != null);
assert(onChanged != null);
}
}) : assert(product != null),
assert(quantity != null),
assert(onChanged != null),
super(key: key);
final Product product;
final int quantity;
......@@ -70,9 +69,9 @@ class _ProductItem extends StatelessWidget {
// Vendor name and description
class _VendorItem extends StatelessWidget {
_VendorItem({ Key key, @required this.vendor }) : super(key: key) {
assert(vendor != null);
}
_VendorItem({ Key key, @required this.vendor })
: assert(vendor != null),
super(key: key);
final Vendor vendor;
......@@ -146,10 +145,9 @@ class _Heading extends StatelessWidget {
@required this.product,
@required this.quantity,
this.quantityChanged,
}) : super(key: key) {
assert(product != null);
assert(quantity != null && quantity >= 0 && quantity <= 5);
}
}) : assert(product != null),
assert(quantity != null && quantity >= 0 && quantity <= 5),
super(key: key);
final Product product;
final int quantity;
......@@ -213,11 +211,10 @@ class OrderPage extends StatefulWidget {
@required this.order,
@required this.products,
@required this.shoppingCart,
}) : super(key: key) {
assert(order != null);
assert(products != null && products.isNotEmpty);
assert(shoppingCart != null);
}
}) : assert(order != null),
assert(products != null && products.isNotEmpty),
assert(shoppingCart != null),
super(key: key);
final Order order;
final List<Product> products;
......@@ -328,9 +325,8 @@ class ShrineOrderRoute extends ShrinePageRoute<Order> {
@required this.order,
WidgetBuilder builder,
RouteSettings settings: const RouteSettings(),
}) : super(builder: builder, settings: settings) {
assert(order != null);
}
}) : assert(order != null),
super(builder: builder, settings: settings);
Order order;
......
......@@ -22,10 +22,9 @@ class ShrinePage extends StatefulWidget {
this.floatingActionButton,
this.products,
this.shoppingCart
}) : super(key: key) {
assert(body != null);
assert(scaffoldKey != null);
}
}) : assert(body != null),
assert(scaffoldKey != null),
super(key: key);
final GlobalKey<ScaffoldState> scaffoldKey;
final Widget body;
......
......@@ -27,9 +27,9 @@ TextStyle abrilFatfaceRegular34(Color color) => new ShrineStyle.abrilFatface(34.
/// InheritedWidget is shared by all of the routes and widgets created for
/// the Shrine app.
class ShrineTheme extends InheritedWidget {
ShrineTheme({ Key key, @required Widget child }) : super(key: key, child: child) {
assert(child != null);
}
ShrineTheme({ Key key, @required Widget child })
: assert(child != null),
super(key: key, child: child);
final Color cardBackgroundColor = Colors.white;
final Color appBarBackgroundColor = Colors.white;
......
......@@ -66,11 +66,10 @@ class Product {
}
class Order {
Order({ @required this.product, this.quantity: 1, this.inCart: false }) {
assert(product != null);
assert(quantity != null && quantity >= 0);
assert(inCart != null);
}
Order({ @required this.product, this.quantity: 1, this.inCart: false })
: assert(product != null),
assert(quantity != null && quantity >= 0),
assert(inCart != null);
final Product product;
final int quantity;
......
......@@ -11,11 +11,10 @@ class TextStyleItem extends StatelessWidget {
@required this.name,
@required this.style,
@required this.text,
}) : super(key: key) {
assert(name != null);
assert(style != null);
assert(text != null);
}
}) : assert(name != null),
assert(style != null),
assert(text != null),
super(key: key);
final String name;
final TextStyle style;
......
......@@ -102,10 +102,9 @@ class GalleryDrawer extends StatelessWidget {
this.onCheckerboardOffscreenLayersChanged,
this.onPlatformChanged,
this.onSendFeedback,
}) : super(key: key) {
assert(onThemeChanged != null);
assert(onTimeDilationChanged != null);
}
}) : assert(onThemeChanged != null),
assert(onTimeDilationChanged != null),
super(key: key);
final bool useLightTheme;
final ValueChanged<bool> onThemeChanged;
......
......@@ -80,10 +80,9 @@ class GalleryHome extends StatefulWidget {
this.onCheckerboardOffscreenLayersChanged,
this.onPlatformChanged,
this.onSendFeedback,
}) : super(key: key) {
assert(onThemeChanged != null);
assert(onTimeDilationChanged != null);
}
}) : assert(onThemeChanged != null),
assert(onTimeDilationChanged != null),
super(key: key);
final bool useLightTheme;
final ValueChanged<bool> onThemeChanged;
......
......@@ -18,12 +18,10 @@ class GalleryItem extends StatelessWidget {
@required this.category,
@required this.routeName,
@required this.buildRoute,
}) {
assert(title != null);
assert(category != null);
assert(routeName != null);
assert(buildRoute != null);
}
}) : assert(title != null),
assert(category != null),
assert(routeName != null),
assert(buildRoute != null);
final String title;
final String subtitle;
......
......@@ -12,9 +12,9 @@ import 'package:url_launcher/url_launcher.dart';
typedef Future<String> UpdateUrlFetcher();
class Updater extends StatefulWidget {
Updater({ @required this.updateUrlFetcher, this.child, Key key }) : super(key: key) {
assert(updateUrlFetcher != null);
}
Updater({ @required this.updateUrlFetcher, this.child, Key key })
: assert(updateUrlFetcher != null),
super(key: key);
final UpdateUrlFetcher updateUrlFetcher;
final Widget child;
......
......@@ -18,12 +18,11 @@ typedef void OnResultListener(String result);
// in real-world applications.
class Calculator {
Calculator({ @required this.onProgressListener, @required this.onResultListener, String data })
// In order to keep the example files smaller, we "cheat" a little and
// replicate our small json string into a 10,000-element array.
: _data = _replicateJson(data, 10000) {
assert(onProgressListener != null);
assert(onResultListener != null);
}
: assert(onProgressListener != null),
assert(onResultListener != null),
// In order to keep the example files smaller, we "cheat" a little and
// replicate our small json string into a 10,000-element array.
_data = _replicateJson(data, 10000);
final OnProgressListener onProgressListener;
final OnResultListener onResultListener;
......@@ -87,9 +86,9 @@ class CalculationMessage {
// progress of the background computation.
class CalculationManager {
CalculationManager({ @required this.onProgressListener, @required this.onResultListener })
: _receivePort = new ReceivePort() {
assert(onProgressListener != null);
assert(onResultListener != null);
: assert(onProgressListener != null),
assert(onResultListener != null),
_receivePort = new ReceivePort() {
_receivePort.listen(_handleMessage);
}
......
......@@ -19,18 +19,16 @@ class StockConfiguration {
@required this.debugShowRainbow,
@required this.showPerformanceOverlay,
@required this.showSemanticsDebugger
}) {
assert(stockMode != null);
assert(backupMode != null);
assert(debugShowGrid != null);
assert(debugShowSizes != null);
assert(debugShowBaselines != null);
assert(debugShowLayers != null);
assert(debugShowPointers != null);
assert(debugShowRainbow != null);
assert(showPerformanceOverlay != null);
assert(showSemanticsDebugger != null);
}
}) : assert(stockMode != null),
assert(backupMode != null),
assert(debugShowGrid != null),
assert(debugShowSizes != null),
assert(debugShowBaselines != null),
assert(debugShowLayers != null),
assert(debugShowPointers != null),
assert(debugShowRainbow != null),
assert(showPerformanceOverlay != null),
assert(showSemanticsDebugger != null);
final StockMode stockMode;
final BackupMode backupMode;
......
......@@ -79,9 +79,9 @@ class BitField<T extends dynamic> {
/// Creates a bit field of all zeros.
///
/// The given length must be at most 62.
BitField(this._length) : _bits = _kAllZeros {
assert(_length <= _kSMIBits);
}
BitField(this._length)
: assert(_length <= _kSMIBits),
_bits = _kAllZeros;
/// Creates a bit field filled with a particular value.
///
......@@ -89,9 +89,10 @@ class BitField<T extends dynamic> {
/// the bits are filled with zeros.
///
/// The given length must be at most 62.
BitField.filled(this._length, bool value) : _bits = value ? _kAllOnes : _kAllZeros {
assert(_length <= _kSMIBits);
}
BitField.filled(this._length, bool value)
: assert(_length <= _kSMIBits),
_bits = value ? _kAllOnes : _kAllZeros;
final int _length;
int _bits;
......
......@@ -135,8 +135,8 @@ class ClampingScrollSimulation extends Simulation {
@required this.velocity,
this.friction: 0.015,
Tolerance tolerance: Tolerance.defaultTolerance,
}) : super(tolerance: tolerance) {
assert(_flingVelocityPenetration(0.0) == _kInitialVelocityPenetration);
}) : assert(_flingVelocityPenetration(0.0) == _kInitialVelocityPenetration),
super(tolerance: tolerance) {
_duration = _flingDuration(velocity);
_distance = (velocity * _duration / _kInitialVelocityPenetration).abs();
}
......
......@@ -12,9 +12,8 @@ class Wrapper extends StatelessWidget {
Wrapper({
Key key,
@required this.child
}) : super(key: key) {
assert(child != null);
}
}) : assert(child != null),
super(key: key);
final Widget child;
......
......@@ -113,14 +113,13 @@ class LinkedScrollPosition extends ScrollPositionWithSingleContext {
ScrollContext context,
double initialPixels,
ScrollPosition oldPosition,
}) : super(
physics: physics,
context: context,
initialPixels: initialPixels,
oldPosition: oldPosition,
) {
assert(owner != null);
}
}) : assert(owner != null),
super(
physics: physics,
context: context,
initialPixels: initialPixels,
oldPosition: oldPosition,
);
final LinkedScrollController owner;
......@@ -547,4 +546,4 @@ void main() {
await tester.pump(const Duration(seconds: 1));
await tester.pump(const Duration(seconds: 60));
});
}
\ No newline at end of file
}
......@@ -29,9 +29,8 @@ final EnumIndex<HealthStatus> _healthStatusIndex =
class Health extends Result {
/// Creates a [Health] object with the given [status].
Health(this.status) {
assert(status != null);
}
Health(this.status)
: assert(status != null);
/// Deserializes the result from JSON.
static Health fromJson(Map<String, dynamic> json) {
......
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