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