mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
use isEmpty and isNotEmpty (#7207)
This commit is contained in:
parent
778b30ac0b
commit
9eaaa91df7
@ -39,7 +39,7 @@ class Expression extends EquationMember {
|
||||
Expression asExpression() => this;
|
||||
|
||||
@override
|
||||
bool get isConstant => terms.length == 0;
|
||||
bool get isConstant => terms.isEmpty;
|
||||
|
||||
@override
|
||||
double get value => terms.fold(constant, (double value, Term term) => value + term.value);
|
||||
|
||||
@ -773,7 +773,7 @@ class Solver {
|
||||
}
|
||||
|
||||
Result _dualOptimize() {
|
||||
while (_infeasibleRows.length != 0) {
|
||||
while (_infeasibleRows.isNotEmpty) {
|
||||
_Symbol leaving = _infeasibleRows.removeLast();
|
||||
_Row row = _rows[leaving];
|
||||
|
||||
|
||||
@ -62,12 +62,12 @@ void _debugPrintTask() {
|
||||
_debugPrintStopwatch.reset();
|
||||
_debugPrintedCharacters = 0;
|
||||
}
|
||||
while (_debugPrintedCharacters < _kDebugPrintCapacity && _debugPrintBuffer.length > 0) {
|
||||
while (_debugPrintedCharacters < _kDebugPrintCapacity && _debugPrintBuffer.isNotEmpty) {
|
||||
String line = _debugPrintBuffer.removeFirst();
|
||||
_debugPrintedCharacters += line.length; // TODO(ianh): Use the UTF-8 byte length instead
|
||||
print(line);
|
||||
}
|
||||
if (_debugPrintBuffer.length > 0) {
|
||||
if (_debugPrintBuffer.isNotEmpty) {
|
||||
_debugPrintScheduled = true;
|
||||
_debugPrintedCharacters = 0;
|
||||
new Timer(_kDebugPrintPauseTime, _debugPrintTask);
|
||||
|
||||
@ -259,7 +259,7 @@ class DataTable extends StatelessWidget {
|
||||
}) : columns = columns,
|
||||
_onlyTextColumn = _initOnlyTextColumn(columns), super(key: key) {
|
||||
assert(columns != null);
|
||||
assert(columns.length > 0);
|
||||
assert(columns.isNotEmpty);
|
||||
assert(sortColumnIndex == null || (sortColumnIndex >= 0 && sortColumnIndex < columns.length));
|
||||
assert(sortAscending != null);
|
||||
assert(rows != null);
|
||||
|
||||
@ -100,7 +100,7 @@ class IconThemeData {
|
||||
result.add('opacity: $_opacity');
|
||||
if (size != null)
|
||||
result.add('size: $size');
|
||||
if (result.length == 0)
|
||||
if (result.isEmpty)
|
||||
return '<no theme>';
|
||||
return result.join(', ');
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ class PaginatedDataTable extends StatefulWidget {
|
||||
}) : super(key: key) {
|
||||
assert(header != null);
|
||||
assert(columns != null);
|
||||
assert(columns.length > 0);
|
||||
assert(columns.isNotEmpty);
|
||||
assert(sortColumnIndex == null || (sortColumnIndex >= 0 && sortColumnIndex < columns.length));
|
||||
assert(sortAscending != null);
|
||||
assert(rowsPerPage != null);
|
||||
|
||||
@ -445,7 +445,7 @@ Future<dynamic/*=T*/> showMenu/*<T>*/({
|
||||
int elevation: 8
|
||||
}) {
|
||||
assert(context != null);
|
||||
assert(items != null && items.length > 0);
|
||||
assert(items != null && items.isNotEmpty);
|
||||
return Navigator.push(context, new _PopupMenuRoute<dynamic/*=T*/>(
|
||||
position: position,
|
||||
items: items,
|
||||
|
||||
@ -930,7 +930,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
|
||||
if (!config.resizeToAvoidBottomPadding)
|
||||
padding = new EdgeInsets.fromLTRB(padding.left, padding.top, padding.right, 0.0);
|
||||
|
||||
if (_snackBars.length > 0) {
|
||||
if (_snackBars.isNotEmpty) {
|
||||
final ModalRoute<dynamic> route = ModalRoute.of(context);
|
||||
if (route == null || route.isCurrent) {
|
||||
if (_snackBarController.isCompleted && _snackBarTimer == null)
|
||||
|
||||
@ -476,7 +476,7 @@ class TabBarSelection<T> extends StatefulWidget {
|
||||
this.onChanged,
|
||||
@required this.child
|
||||
}) : super(key: key) {
|
||||
assert(values != null && values.length > 0);
|
||||
assert(values != null && values.isNotEmpty);
|
||||
assert(new Set<T>.from(values).length == values.length);
|
||||
assert(value == null ? true : values.where((T e) => e == value).length == 1);
|
||||
assert(child != null);
|
||||
@ -847,7 +847,7 @@ class _TabBarState<T> extends ScrollableState<TabBar<T>> implements TabBarSelect
|
||||
|
||||
@override
|
||||
void handleStatusChange(AnimationStatus status) {
|
||||
if (config.labels.length == 0)
|
||||
if (config.labels.isEmpty)
|
||||
return;
|
||||
|
||||
if (_valueIsChanging && status == AnimationStatus.completed) {
|
||||
@ -861,7 +861,7 @@ class _TabBarState<T> extends ScrollableState<TabBar<T>> implements TabBarSelect
|
||||
|
||||
@override
|
||||
void handleProgressChange() {
|
||||
if (config.labels.length == 0 || _selection == null)
|
||||
if (config.labels.isEmpty || _selection == null)
|
||||
return;
|
||||
|
||||
if (_lastSelectedIndex != _selection.index) {
|
||||
|
||||
@ -380,7 +380,7 @@ class BoxConstraints extends Constraints {
|
||||
affectedFieldsList.add('minHeight');
|
||||
if (maxHeight.isNaN)
|
||||
affectedFieldsList.add('maxHeight');
|
||||
assert(affectedFieldsList.length > 0);
|
||||
assert(affectedFieldsList.isNotEmpty);
|
||||
if (affectedFieldsList.length > 1)
|
||||
affectedFieldsList.add('and ${affectedFieldsList.removeLast()}');
|
||||
String whichFields = '';
|
||||
|
||||
@ -1022,7 +1022,7 @@ class PipelineOwner {
|
||||
if (node._needsPaint && node.owner == this)
|
||||
PaintingContext.repaintCompositedChild(node);
|
||||
}
|
||||
assert(_nodesNeedingPaint.length == 0);
|
||||
assert(_nodesNeedingPaint.isEmpty);
|
||||
} finally {
|
||||
_debugDoingPaint = false;
|
||||
Timeline.finishSync();
|
||||
|
||||
@ -492,7 +492,7 @@ class RenderTable extends RenderBox {
|
||||
assert(rows == null || children == null);
|
||||
assert(defaultColumnWidth != null);
|
||||
assert(configuration != null);
|
||||
_columns = columns ?? (children != null && children.length > 0 ? children.first.length : 0);
|
||||
_columns = columns ?? (children != null && children.isNotEmpty ? children.first.length : 0);
|
||||
_rows = rows ?? 0;
|
||||
_children = new List<RenderBox>()..length = _columns * _rows;
|
||||
_columnWidths = columnWidths ?? new HashMap<int, TableColumnWidth>();
|
||||
@ -691,10 +691,10 @@ class RenderTable extends RenderBox {
|
||||
return;
|
||||
assert(columns >= 0);
|
||||
// consider the case of a newly empty table
|
||||
if (columns == 0 || cells.length == 0) {
|
||||
assert(cells == null || cells.length == 0);
|
||||
if (columns == 0 || cells.isEmpty) {
|
||||
assert(cells == null || cells.isEmpty);
|
||||
_columns = columns;
|
||||
if (_children.length == 0) {
|
||||
if (_children.isEmpty) {
|
||||
assert(_rows == 0);
|
||||
return;
|
||||
}
|
||||
@ -757,7 +757,7 @@ class RenderTable extends RenderBox {
|
||||
dropChild(oldChild);
|
||||
}
|
||||
_children.clear();
|
||||
_columns = cells.length > 0 ? cells.first.length : 0;
|
||||
_columns = cells.isNotEmpty ? cells.first.length : 0;
|
||||
_rows = 0;
|
||||
for (List<RenderBox> row in cells)
|
||||
addRow(row);
|
||||
@ -1282,7 +1282,7 @@ class RenderTable extends RenderBox {
|
||||
super.debugFillDescription(description);
|
||||
if (border != null)
|
||||
description.add('border: $border');
|
||||
if (_columnWidths.length > 0)
|
||||
if (_columnWidths.isNotEmpty)
|
||||
description.add('specified column widths: $_columnWidths');
|
||||
description.add('default column width: $defaultColumnWidth');
|
||||
description.add('table size: $columns\u00D7$rows');
|
||||
|
||||
@ -2365,7 +2365,7 @@ abstract class Element implements BuildContext {
|
||||
assert(widget != null);
|
||||
assert(depth != null);
|
||||
assert(_active);
|
||||
if (_dependencies != null && _dependencies.length > 0) {
|
||||
if (_dependencies != null && _dependencies.isNotEmpty) {
|
||||
for (InheritedElement dependency in _dependencies)
|
||||
dependency._dependents.remove(this);
|
||||
// For expediency, we don't actually clear the list here, even though it's
|
||||
@ -2629,7 +2629,7 @@ abstract class Element implements BuildContext {
|
||||
String result = '$prefixLineOne$this\n';
|
||||
List<Element> children = <Element>[];
|
||||
visitChildren(children.add);
|
||||
if (children.length > 0) {
|
||||
if (children.isNotEmpty) {
|
||||
Element last = children.removeLast();
|
||||
for (Element child in children)
|
||||
result += '${child.toStringDeep("$prefixOtherLines\u251C", "$prefixOtherLines\u2502")}';
|
||||
@ -2803,7 +2803,7 @@ abstract class BuildableElement extends Element {
|
||||
|
||||
@override
|
||||
void activate() {
|
||||
final bool hadDependencies = ((_dependencies != null && _dependencies.length > 0) || _hadUnsatisfiedDependencies);
|
||||
final bool hadDependencies = ((_dependencies != null && _dependencies.isNotEmpty) || _hadUnsatisfiedDependencies);
|
||||
super.activate(); // clears _dependencies, and sets active to true
|
||||
if (_dirty) {
|
||||
if (_inDirtyList) {
|
||||
|
||||
@ -432,7 +432,7 @@ class _HeroParty {
|
||||
}
|
||||
|
||||
void setAnimation(Animation<double> animation) {
|
||||
assert(animation != null || _heroes.length == 0);
|
||||
assert(animation != null || _heroes.isEmpty);
|
||||
if (animation != _currentAnimation) {
|
||||
_clearCurrentAnimation();
|
||||
_currentAnimation = animation;
|
||||
|
||||
@ -644,7 +644,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin {
|
||||
/// The only route that cannot be popped off the navigator is the initial
|
||||
/// route.
|
||||
bool canPop() {
|
||||
assert(_history.length > 0);
|
||||
assert(_history.isNotEmpty);
|
||||
return _history.length > 1 || _history[0].willHandlePopInternally;
|
||||
}
|
||||
|
||||
|
||||
@ -319,7 +319,7 @@ abstract class LocalHistoryRoute<T> extends Route<T> {
|
||||
|
||||
@override
|
||||
bool didPop(T result) {
|
||||
if (_localHistory != null && _localHistory.length > 0) {
|
||||
if (_localHistory != null && _localHistory.isNotEmpty) {
|
||||
LocalHistoryEntry entry = _localHistory.removeLast();
|
||||
assert(entry._owner == this);
|
||||
entry._owner = null;
|
||||
@ -331,7 +331,7 @@ abstract class LocalHistoryRoute<T> extends Route<T> {
|
||||
|
||||
@override
|
||||
bool get willHandlePopInternally {
|
||||
return _localHistory != null && _localHistory.length > 0;
|
||||
return _localHistory != null && _localHistory.isNotEmpty;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -59,7 +59,7 @@ class TableRow {
|
||||
result.write('$decoration, ');
|
||||
if (children == null) {
|
||||
result.write('child list is null');
|
||||
} else if (children.length == 0) {
|
||||
} else if (children.isEmpty) {
|
||||
result.write('no children');
|
||||
} else {
|
||||
result.write('$children');
|
||||
@ -137,7 +137,7 @@ class Table extends RenderObjectWidget {
|
||||
return true;
|
||||
});
|
||||
assert(() {
|
||||
if (children.length > 0) {
|
||||
if (children.isNotEmpty) {
|
||||
final int cellCount = children.first.children.length;
|
||||
if (children.any((TableRow row) => row.children.length != cellCount)) {
|
||||
throw new FlutterError(
|
||||
@ -195,7 +195,7 @@ class Table extends RenderObjectWidget {
|
||||
@override
|
||||
RenderTable createRenderObject(BuildContext context) {
|
||||
return new RenderTable(
|
||||
columns: children.length > 0 ? children[0].children.length : 0,
|
||||
columns: children.isNotEmpty ? children[0].children.length : 0,
|
||||
rows: children.length,
|
||||
columnWidths: columnWidths,
|
||||
defaultColumnWidth: defaultColumnWidth,
|
||||
@ -209,7 +209,7 @@ class Table extends RenderObjectWidget {
|
||||
|
||||
@override
|
||||
void updateRenderObject(BuildContext context, RenderTable renderObject) {
|
||||
assert(renderObject.columns == (children.length > 0 ? children[0].children.length : 0));
|
||||
assert(renderObject.columns == (children.isNotEmpty ? children[0].children.length : 0));
|
||||
assert(renderObject.rows == children.length);
|
||||
renderObject
|
||||
..columnWidths = columnWidths
|
||||
@ -318,7 +318,7 @@ class _TableElement extends RenderObjectElement {
|
||||
void _updateRenderObjectChildren() {
|
||||
assert(renderObject != null);
|
||||
renderObject.setFlatChildren(
|
||||
_children.length > 0 ? _children[0].children.length : 0,
|
||||
_children.isNotEmpty ? _children[0].children.length : 0,
|
||||
_children.expand((_TableElementRow row) => row.children.map((Element child) => child.renderObject)).toList()
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user