check null safety for my data table
This commit is contained in:
@@ -75,7 +75,7 @@ class MyDataRow {
|
||||
this.key,
|
||||
this.selected = false,
|
||||
this.onSelectChanged,
|
||||
@required this.cells,
|
||||
required this.cells,
|
||||
}) : assert(cells != null);
|
||||
|
||||
/// Creates the configuration for a row of a [MyDataTable], deriving
|
||||
@@ -83,10 +83,10 @@ class MyDataRow {
|
||||
///
|
||||
/// The [cells] argument must not be null.
|
||||
MyDataRow.byIndex({
|
||||
int index,
|
||||
int index = 0,
|
||||
this.selected = false,
|
||||
this.onSelectChanged,
|
||||
@required this.cells,
|
||||
required this.cells,
|
||||
}) : assert(cells != null),
|
||||
key = ValueKey<int>(index);
|
||||
|
||||
@@ -96,7 +96,7 @@ class MyDataRow {
|
||||
/// remain on the right row visually.
|
||||
///
|
||||
/// If the table never changes once created, no key is necessary.
|
||||
final LocalKey key;
|
||||
final LocalKey? key;
|
||||
|
||||
/// Called when the user selects or unselects a selectable row.
|
||||
///
|
||||
@@ -111,7 +111,7 @@ class MyDataRow {
|
||||
/// A row whose [onSelectChanged] callback is null is ignored for
|
||||
/// the purposes of determining the state of the "all" checkbox,
|
||||
/// and its checkbox is disabled.
|
||||
final ValueChanged<bool> onSelectChanged;
|
||||
final ValueChanged<bool>? onSelectChanged;
|
||||
|
||||
/// Whether the row is selected.
|
||||
///
|
||||
@@ -193,7 +193,7 @@ class MyDataCell {
|
||||
/// If non-null, tapping the cell will call this callback. If
|
||||
/// null, tapping the cell will attempt to select the row (if
|
||||
/// [MyDataRow.onSelectChanged] is provided).
|
||||
final VoidCallback onTap;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
bool get _debugInteractive => onTap != null;
|
||||
}
|
||||
@@ -309,8 +309,8 @@ class MyDataTable extends StatelessWidget {
|
||||
/// the sort order is ascending, this should be true (the default),
|
||||
/// otherwise it should be false.
|
||||
MyDataTable({
|
||||
Key key,
|
||||
@required this.columns,
|
||||
Key? key,
|
||||
required this.columns,
|
||||
this.sortColumnIndex,
|
||||
this.sortAscending = true,
|
||||
this.onSelectAll,
|
||||
@@ -339,8 +339,8 @@ class MyDataTable extends StatelessWidget {
|
||||
/// The configuration and labels for the columns in the table.
|
||||
final List<MyDataColumn> columns;
|
||||
|
||||
final Decoration oddLine;
|
||||
final Decoration evenLine;
|
||||
final Decoration? oddLine;
|
||||
final Decoration? evenLine;
|
||||
|
||||
/// The current primary sort key's column.
|
||||
///
|
||||
@@ -353,7 +353,7 @@ class MyDataTable extends StatelessWidget {
|
||||
///
|
||||
/// When this is null, it implies that the table's sort order does
|
||||
/// not correspond to any of the columns.
|
||||
final int sortColumnIndex;
|
||||
final int? sortColumnIndex;
|
||||
|
||||
/// Whether the column mentioned in [sortColumnIndex], if any, is sorted
|
||||
/// in ascending order.
|
||||
@@ -376,7 +376,7 @@ class MyDataTable extends StatelessWidget {
|
||||
/// To control whether a particular row is selectable or not, see
|
||||
/// [MyDataRow.onSelectChanged]. This callback is only relevant if any
|
||||
/// row is selectable.
|
||||
final ValueSetter<bool> onSelectAll;
|
||||
final ValueSetter<bool>? onSelectAll;
|
||||
|
||||
/// The height of each row (excluding the row that contains column headings).
|
||||
///
|
||||
@@ -413,11 +413,10 @@ class MyDataTable extends StatelessWidget {
|
||||
// non-numeric, if there is exactly one, otherwise null.
|
||||
final int _onlyTextColumn;
|
||||
static int _initOnlyTextColumn(List<MyDataColumn> columns) {
|
||||
int result;
|
||||
int result = 0;
|
||||
for (int index = 0; index < columns.length; index += 1) {
|
||||
final MyDataColumn column = columns[index];
|
||||
if (!column.numeric) {
|
||||
if (result != null) return null;
|
||||
result = index;
|
||||
}
|
||||
}
|
||||
@@ -433,11 +432,11 @@ class MyDataTable extends StatelessWidget {
|
||||
|
||||
void _handleSelectAll(bool checked) {
|
||||
if (onSelectAll != null) {
|
||||
onSelectAll(checked);
|
||||
onSelectAll!(checked);
|
||||
} else {
|
||||
for (MyDataRow row in rows) {
|
||||
if ((row.onSelectChanged != null) && (row.selected != checked))
|
||||
row.onSelectChanged(checked);
|
||||
row.onSelectChanged!(checked);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -613,8 +612,8 @@ class MyDataTable extends StatelessWidget {
|
||||
final bool showCheckboxColumn = false;
|
||||
final bool allChecked = false;
|
||||
|
||||
final List<TableColumnWidth> tableColumns =
|
||||
List<TableColumnWidth>(columns.length + (showCheckboxColumn ? 1 : 0));
|
||||
final List<TableColumnWidth> tableColumns = (columns.length +
|
||||
(showCheckboxColumn ? 1 : 0)) as List<TableColumnWidth>;
|
||||
final List<TableRow> tableRows = List<TableRow>.generate(
|
||||
rows.length + 1, // the +1 is for the header row
|
||||
(int index) {
|
||||
@@ -745,7 +744,7 @@ class MyDataTable extends StatelessWidget {
|
||||
class TableRowInkWell extends InkResponse {
|
||||
/// Creates an ink well for a table row.
|
||||
const TableRowInkWell({
|
||||
Key key,
|
||||
Key? key,
|
||||
Widget child,
|
||||
GestureTapCallback onTap,
|
||||
GestureTapCallback onDoubleTap,
|
||||
@@ -799,7 +798,7 @@ class TableRowInkWell extends InkResponse {
|
||||
|
||||
class _SortArrow extends StatefulWidget {
|
||||
const _SortArrow({
|
||||
Key key,
|
||||
Key? key,
|
||||
this.visible,
|
||||
this.down,
|
||||
this.duration,
|
||||
@@ -816,14 +815,14 @@ class _SortArrow extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _SortArrowState extends State<_SortArrow> with TickerProviderStateMixin {
|
||||
AnimationController _opacityController;
|
||||
Animation<double> _opacityAnimation;
|
||||
late AnimationController _opacityController;
|
||||
late Animation<double> _opacityAnimation;
|
||||
|
||||
AnimationController _orientationController;
|
||||
Animation<double> _orientationAnimation;
|
||||
late AnimationController _orientationController;
|
||||
late Animation<double> _orientationAnimation;
|
||||
double _orientationOffset = 0.0;
|
||||
|
||||
bool _down;
|
||||
late bool _down;
|
||||
|
||||
static final Animatable<double> _turnTween =
|
||||
Tween<double>(begin: 0.0, end: math.pi)
|
||||
@@ -869,7 +868,7 @@ class _SortArrowState extends State<_SortArrow> with TickerProviderStateMixin {
|
||||
void didUpdateWidget(_SortArrow oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
bool skipArrow = false;
|
||||
final bool newDown = widget.down ?? _down;
|
||||
final bool newDown = widget.down;
|
||||
if (oldWidget.visible != widget.visible) {
|
||||
if (widget.visible &&
|
||||
(_opacityController.status == AnimationStatus.dismissed)) {
|
||||
|
||||
Reference in New Issue
Block a user