add @required when there's an assert not null (#9124)

* add @required when there's an assert not null

* address review comments
This commit is contained in:
Alexandre Ardhuin
2017-03-31 18:34:13 +02:00
committed by GitHub
parent 86e9fc1c68
commit 2de61a0853
70 changed files with 247 additions and 164 deletions

View File

@@ -31,8 +31,8 @@ const double _kAppBarMidHeight = 256.0;
// TODO(hansmuller): it would be worth adding something like this to the framework.
class _RenderStatusBarPaddingSliver extends RenderSliver {
_RenderStatusBarPaddingSliver({
double maxHeight,
double scrollFactor,
@required double maxHeight,
@required double scrollFactor,
}) : _maxHeight = maxHeight, _scrollFactor = scrollFactor {
assert(maxHeight != null && maxHeight >= 0.0);
assert(scrollFactor != null && scrollFactor >= 1.0);
@@ -264,8 +264,8 @@ class _AllSectionsView extends AnimatedWidget {
_AllSectionsView({
Key key,
this.sectionIndex,
this.sections,
this.selectedIndex,
@required this.sections,
@required this.selectedIndex,
this.minHeight,
this.midHeight,
this.maxHeight,

View File

@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'sections.dart';
@@ -10,7 +11,7 @@ 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, this.section }) : super(key: key) {
SectionCard({ Key key, @required this.section }) : super(key: key) {
assert(section != null);
}
@@ -60,7 +61,12 @@ class SectionTitle extends StatelessWidget {
color: const Color(0x19000000),
);
SectionTitle({ Key key, this.section, this.scale, this.opacity }) : super(key: key) {
SectionTitle({
Key key,
@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);
@@ -115,7 +121,7 @@ class SectionIndicator extends StatelessWidget {
// Display a single SectionDetail.
class SectionDetailView extends StatelessWidget {
SectionDetailView({ Key key, this.detail }) : super(key: key) {
SectionDetailView({ Key key, @required this.detail }) : super(key: key) {
assert(detail != null && detail.imageAsset != null);
assert((detail.imageAsset ?? detail.title) != null);
}

View File

@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
const double kColorItemHeight = 48.0;
@@ -41,7 +42,12 @@ final List<Palette> allPalettes = <Palette>[
class ColorItem extends StatelessWidget {
ColorItem({ Key key, this.index, this.color, this.prefix: '' }) : super(key: key) {
ColorItem({
Key key,
@required this.index,
@required this.color,
this.prefix: '',
}) : super(key: key) {
assert(index != null);
assert(color != null);
assert(prefix != null);

View File

@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
class TravelDestination {
@@ -36,7 +37,7 @@ final List<TravelDestination> destinations = <TravelDestination>[
];
class TravelDestinationItem extends StatelessWidget {
TravelDestinationItem({ Key key, this.destination }) : super(key: key) {
TravelDestinationItem({ Key key, @required this.destination }) : super(key: key) {
assert(destination != null && destination.isValid);
}

View File

@@ -2,8 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:intl/intl.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
// This demo is based on
// https://material.google.com/components/dialogs.html#dialogs-full-screen-dialogs
@@ -15,7 +16,7 @@ enum DismissDialogAction {
}
class DateTimeItem extends StatelessWidget {
DateTimeItem({ Key key, DateTime dateTime, this.onChanged })
DateTimeItem({ Key key, DateTime dateTime, @required this.onChanged })
: date = new DateTime(dateTime.year, dateTime.month, dateTime.day),
time = new TimeOfDay(hour: dateTime.hour, minute: dateTime.minute),
super(key: key) {

View File

@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
enum GridDemoTileStyle {
@@ -143,9 +144,9 @@ class _GridPhotoViewerState extends State<GridPhotoViewer> with SingleTickerProv
class GridDemoPhotoItem extends StatelessWidget {
GridDemoPhotoItem({
Key key,
this.photo,
this.tileStyle,
this.onBannerTap
@required this.photo,
@required this.tileStyle,
@required this.onBannerTap
}) : super(key: key) {
assert(photo != null && photo.isValid);
assert(tileStyle != null);

View File

@@ -116,7 +116,7 @@ class _ShrineGridDelegate extends SliverGridDelegate {
// Displays the Vendor's name and avatar.
class _VendorItem extends StatelessWidget {
_VendorItem({ Key key, this.vendor }) : super(key: key) {
_VendorItem({ Key key, @required this.vendor }) : super(key: key) {
assert(vendor != null);
}
@@ -148,7 +148,7 @@ class _VendorItem extends StatelessWidget {
// Displays the product's price. If the product is in the shopping cart then the
// background is highlighted.
abstract class _PriceItem extends StatelessWidget {
_PriceItem({ Key key, this.product }) : super(key: key) {
_PriceItem({ Key key, @required this.product }) : super(key: key) {
assert(product != null);
}
@@ -240,7 +240,8 @@ class _HeadingLayout extends MultiChildLayoutDelegate {
// A card that highlights the "featured" catalog item.
class _Heading extends StatelessWidget {
_Heading({ Key key, this.product }) : super(key: key) {
_Heading({ Key key, @required this.product }) : super(key: key) {
assert(product != null);
assert(product.featureTitle != null);
assert(product.featureDescription != null);
}
@@ -293,7 +294,7 @@ 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, this.product, this.onPressed }) : super(key: key) {
_ProductItem({ Key key, @required this.product, this.onPressed }) : super(key: key) {
assert(product != null);
}

View File

@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import '../shrine_demo.dart' show ShrinePageRoute;
@@ -11,7 +12,12 @@ import 'shrine_types.dart';
// Displays the product title's, description, and order quantity dropdown.
class _ProductItem extends StatelessWidget {
_ProductItem({ Key key, this.product, this.quantity, this.onChanged }) : super(key: key) {
_ProductItem({
Key key,
@required this.product,
@required this.quantity,
@required this.onChanged,
}) : super(key: key) {
assert(product != null);
assert(quantity != null);
assert(onChanged != null);
@@ -64,7 +70,7 @@ class _ProductItem extends StatelessWidget {
// Vendor name and description
class _VendorItem extends StatelessWidget {
_VendorItem({ Key key, this.vendor }) : super(key: key) {
_VendorItem({ Key key, @required this.vendor }) : super(key: key) {
assert(vendor != null);
}
@@ -135,7 +141,12 @@ class _HeadingLayout extends MultiChildLayoutDelegate {
// Describes a product and vendor in detail, supports specifying
// a order quantity (0-5). Appears at the top of the OrderPage.
class _Heading extends StatelessWidget {
_Heading({ Key key, this.product, this.quantity, this.quantityChanged }) : super(key: key) {
_Heading({
Key key,
@required this.product,
@required this.quantity,
this.quantityChanged,
}) : super(key: key) {
assert(product != null);
assert(quantity != null && quantity >= 0 && quantity <= 5);
}
@@ -197,7 +208,12 @@ class _Heading extends StatelessWidget {
}
class OrderPage extends StatefulWidget {
OrderPage({ Key key, this.order, this.products, this.shoppingCart }) : super(key: key) {
OrderPage({
Key key,
@required this.order,
@required this.products,
@required this.shoppingCart,
}) : super(key: key) {
assert(order != null);
assert(products != null && products.isNotEmpty);
assert(shoppingCart != null);

View File

@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'shrine_theme.dart';
@@ -16,8 +17,8 @@ enum ShrineAction {
class ShrinePage extends StatefulWidget {
ShrinePage({
Key key,
this.scaffoldKey,
this.body,
@required this.scaffoldKey,
@required this.body,
this.floatingActionButton,
this.products,
this.shoppingCart

View File

@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
class ShrineStyle extends TextStyle {
@@ -26,7 +27,7 @@ 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, Widget child }) : super(key: key, child: child) {
ShrineTheme({ Key key, @required Widget child }) : super(key: key, child: child) {
assert(child != null);
}

View File

@@ -4,6 +4,8 @@
import 'dart:ui' show hashValues;
import 'package:flutter/foundation.dart';
class Vendor {
const Vendor({
this.name,
@@ -64,7 +66,7 @@ class Product {
}
class Order {
Order({ this.product, this.quantity: 1, this.inCart: false }) {
Order({ @required this.product, this.quantity: 1, this.inCart: false }) {
assert(product != null);
assert(quantity != null && quantity >= 0);
assert(inCart != null);

View File

@@ -2,10 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
class TextStyleItem extends StatelessWidget {
TextStyleItem({ Key key, this.name, this.style, this.text }) : super(key: key) {
TextStyleItem({
Key key,
@required this.name,
@required this.style,
@required this.text,
}) : super(key: key) {
assert(name != null);
assert(style != null);
assert(text != null);

View File

@@ -4,7 +4,7 @@
import 'dart:math' as math;
import 'package:flutter/foundation.dart' show defaultTargetPlatform;
import 'package:flutter/foundation.dart' show defaultTargetPlatform, required;
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@@ -90,9 +90,9 @@ class GalleryDrawer extends StatelessWidget {
GalleryDrawer({
Key key,
this.useLightTheme,
this.onThemeChanged,
@required this.onThemeChanged,
this.timeDilation,
this.onTimeDilationChanged,
@required this.onTimeDilationChanged,
this.showPerformanceOverlay,
this.onShowPerformanceOverlayChanged,
this.checkerboardRasterCacheImages,

View File

@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'drawer.dart';
@@ -68,9 +69,9 @@ class GalleryHome extends StatefulWidget {
GalleryHome({
Key key,
this.useLightTheme,
this.onThemeChanged,
@required this.onThemeChanged,
this.timeDilation,
this.onTimeDilationChanged,
@required this.onTimeDilationChanged,
this.showPerformanceOverlay,
this.onShowPerformanceOverlayChanged,
this.checkerboardRasterCacheImages,

View File

@@ -4,6 +4,7 @@
import 'dart:developer';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import '../demo/all.dart';
@@ -11,7 +12,13 @@ import '../demo/all.dart';
typedef Widget GalleryDemoBuilder();
class GalleryItem extends StatelessWidget {
GalleryItem({ this.title, this.subtitle, this.category, this.routeName, this.buildRoute }) {
GalleryItem({
@required this.title,
this.subtitle,
@required this.category,
@required this.routeName,
@required this.buildRoute,
}) {
assert(title != null);
assert(category != null);
assert(routeName != null);

View File

@@ -4,13 +4,14 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
typedef Future<String> UpdateUrlFetcher();
class Updater extends StatefulWidget {
Updater({ this.updateUrlFetcher, this.child, Key key }) : super(key: key) {
Updater({ @required this.updateUrlFetcher, this.child, Key key }) : super(key: key) {
assert(updateUrlFetcher != null);
}

View File

@@ -5,6 +5,7 @@
import 'dart:convert';
import 'dart:isolate';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@@ -16,7 +17,7 @@ typedef void OnResultListener(String result);
// The choice of JSON parsing here is meant as an example that might surface
// in real-world applications.
class Calculator {
Calculator({ this.onProgressListener, this.onResultListener, String data })
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) {
@@ -85,7 +86,7 @@ class CalculationMessage {
// This class manages these ports and maintains state related to the
// progress of the background computation.
class CalculationManager {
CalculationManager({ this.onProgressListener, this.onResultListener })
CalculationManager({ @required this.onProgressListener, @required this.onResultListener })
: _receivePort = new ReceivePort() {
assert(onProgressListener != null);
assert(onResultListener != null);

View File

@@ -2,21 +2,23 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/foundation.dart';
enum StockMode { optimistic, pessimistic }
enum BackupMode { enabled, disabled }
class StockConfiguration {
StockConfiguration({
this.stockMode,
this.backupMode,
this.debugShowGrid,
this.debugShowSizes,
this.debugShowBaselines,
this.debugShowLayers,
this.debugShowPointers,
this.debugShowRainbow,
this.showPerformanceOverlay,
this.showSemanticsDebugger
@required this.stockMode,
@required this.backupMode,
@required this.debugShowGrid,
@required this.debugShowSizes,
@required this.debugShowBaselines,
@required this.debugShowLayers,
@required this.debugShowPointers,
@required this.debugShowRainbow,
@required this.showPerformanceOverlay,
@required this.showSemanticsDebugger
}) {
assert(stockMode != null);
assert(backupMode != null);