Skip to content

Commit

Permalink
Incomplete null-safety.
Browse files Browse the repository at this point in the history
  • Loading branch information
bosskmk committed Apr 4, 2021
1 parent d759656 commit 3feac24
Show file tree
Hide file tree
Showing 132 changed files with 3,050 additions and 3,102 deletions.
15 changes: 8 additions & 7 deletions example/lib/dummy_data/development.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import 'package:faker/faker.dart';
import 'package:pluto_grid/pluto_grid.dart';

class DummyData {
List<PlutoColumn> columns;
List<PlutoRow> rows;
List<PlutoColumn>? columns;
List<PlutoRow>? rows;

DummyData(int columnLength, int rowLength) {
var faker = const Faker();
var faker = Faker();

columns = List<int>.generate(columnLength, (index) => index).map((i) {
return PlutoColumn(
Expand Down Expand Up @@ -36,17 +36,18 @@ class DummyData {
frozen: (int i) {
if (i < 1) return PlutoColumnFrozen.left;
if (i > columnLength - 2) return PlutoColumnFrozen.right;
return null;
return PlutoColumnFrozen.none;
}(i),
);
}).toList();

rows = rowsByColumns(length: rowLength, columns: columns);
}

static List<PlutoRow> rowsByColumns({int length, List<PlutoColumn> columns}) {
static List<PlutoRow> rowsByColumns(
{required int length, List<PlutoColumn>? columns}) {
return List<int>.generate(length, (index) => ++index).map((rowIndex) {
return rowByColumns(columns);
return rowByColumns(columns!);
}).toList();
}

Expand All @@ -59,7 +60,7 @@ class DummyData {
if (element.type.isNumber)
return faker.randomGenerator.decimal(scale: 1000000000);
else if (element.type.isSelect)
return (element.type.select.items.toList()..shuffle()).first;
return (element.type.select!.items!.toList()..shuffle()).first;
else if (element.type.isDate)
return DateTime.now()
.add(Duration(
Expand Down
4 changes: 2 additions & 2 deletions example/lib/dummy_data/quick_start.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:pluto_grid/pluto_grid.dart';

class DummyData {
List<PlutoColumn> columns;
List<PlutoRow> rows;
List<PlutoColumn>? columns;
List<PlutoRow>? rows;

DummyData() {
columns = [
Expand Down
56 changes: 28 additions & 28 deletions example/lib/screen/development_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ class DevelopmentScreen extends StatefulWidget {
}

class _DevelopmentScreenState extends State<DevelopmentScreen> {
List<PlutoColumn> columns;
List<PlutoColumn>? columns;

List<PlutoRow> rows;
List<PlutoRow>? rows;

PlutoGridStateManager stateManager;
PlutoGridStateManager? stateManager;

PlutoGridSelectingMode gridSelectingMode = PlutoGridSelectingMode.row;
PlutoGridSelectingMode? gridSelectingMode = PlutoGridSelectingMode.row;

@override
void initState() {
Expand All @@ -41,9 +41,9 @@ class _DevelopmentScreenState extends State<DevelopmentScreen> {
Icons.add_circle,
),
onPressed: () {
rendererContext.stateManager.insertRows(
rendererContext.rowIdx,
rendererContext.stateManager.getNewRows(count: 3),
rendererContext.stateManager!.insertRows(
rendererContext.rowIdx!,
rendererContext.stateManager!.getNewRows(count: 3),
);
},
iconSize: 18,
Expand All @@ -55,7 +55,7 @@ class _DevelopmentScreenState extends State<DevelopmentScreen> {
Icons.remove_circle_outlined,
),
onPressed: () {
rendererContext.stateManager
rendererContext.stateManager!
.removeRows([rendererContext.row]);
},
iconSize: 18,
Expand All @@ -64,7 +64,7 @@ class _DevelopmentScreenState extends State<DevelopmentScreen> {
),
Expanded(
child: Text(
'${rendererContext.row.sortIdx.toString()}(${rendererContext.row.cells[rendererContext.column.field].value.toString()})',
'${rendererContext.row!.sortIdx.toString()}(${rendererContext.row!.cells[rendererContext.column!.field]!.value.toString()})',
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
Expand All @@ -80,16 +80,16 @@ class _DevelopmentScreenState extends State<DevelopmentScreen> {
renderer: (rendererContext) {
Color textColor = Colors.black;

if (rendererContext.cell.value == 'red') {
if (rendererContext.cell!.value == 'red') {
textColor = Colors.red;
} else if (rendererContext.cell.value == 'blue') {
} else if (rendererContext.cell!.value == 'blue') {
textColor = Colors.blue;
} else if (rendererContext.cell.value == 'green') {
} else if (rendererContext.cell!.value == 'green') {
textColor = Colors.green;
}

return Text(
rendererContext.cell.value.toString(),
rendererContext.cell!.value.toString(),
style: TextStyle(
color: textColor,
fontWeight: FontWeight.bold,
Expand Down Expand Up @@ -129,34 +129,34 @@ class _DevelopmentScreenState extends State<DevelopmentScreen> {
rows = DummyData.rowsByColumns(length: 30, columns: columns);
}

void handleAddRowButton({int count}) {
void handleAddRowButton({int? count}) {
final List<PlutoRow> rows = count == null
? [DummyData.rowByColumns(columns)]
? [DummyData.rowByColumns(columns!)]
: DummyData.rowsByColumns(length: count, columns: columns);

stateManager.prependRows(rows);
stateManager!.prependRows(rows);
}

void handleRemoveCurrentRowButton() {
stateManager.removeCurrentRow();
stateManager!.removeCurrentRow();
}

void handleRemoveSelectedRowsButton() {
stateManager.removeRows(stateManager.currentSelectingRows);
stateManager!.removeRows(stateManager!.currentSelectingRows);
}

void handleToggleColumnFilter() {
stateManager.setShowColumnFilter(!stateManager.showColumnFilter);
stateManager!.setShowColumnFilter(!stateManager!.showColumnFilter);
}

void setGridSelectingMode(PlutoGridSelectingMode mode) {
void setGridSelectingMode(PlutoGridSelectingMode? mode) {
if (gridSelectingMode == mode) {
return;
}

setState(() {
gridSelectingMode = mode;
stateManager.setSelectingMode(mode);
stateManager!.setSelectingMode(mode!);
});
}

Expand All @@ -173,8 +173,8 @@ class _DevelopmentScreenState extends State<DevelopmentScreen> {
},
onLoaded: (PlutoGridOnLoadedEvent event) {
stateManager = event.stateManager;
stateManager.setSelectingMode(gridSelectingMode);
stateManager.setShowColumnFilter(true);
stateManager!.setSelectingMode(gridSelectingMode!);
stateManager!.setShowColumnFilter(true);
},
createHeader: (PlutoGridStateManager stateManager) {
return SingleChildScrollView(
Expand Down Expand Up @@ -230,7 +230,7 @@ class _DevelopmentScreenState extends State<DevelopmentScreen> {
),
);
}).toList(),
onChanged: (PlutoGridSelectingMode mode) {
onChanged: (PlutoGridSelectingMode? mode) {
setGridSelectingMode(mode);
},
),
Expand Down Expand Up @@ -275,11 +275,11 @@ class ClassYouImplemented implements PlutoFilterType {
String get title => 'Custom contains';

get compare => ({
String base,
String search,
PlutoColumn column,
required String? base,
required String? search,
required PlutoColumn? column,
}) {
var keys = search.split(',');
var keys = search!.split(',');

return keys.contains(base);
};
Expand Down
28 changes: 14 additions & 14 deletions example/lib/screen/feature/add_and_remove_rows_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ class AddAndRemoveRowsScreen extends StatefulWidget {
}

class _AddAndRemoveRowsScreenState extends State<AddAndRemoveRowsScreen> {
List<PlutoColumn> columns;
List<PlutoColumn>? columns;

List<PlutoRow> rows;
List<PlutoRow>? rows;

PlutoGridStateManager stateManager;
PlutoGridStateManager? stateManager;

PlutoGridSelectingMode gridSelectingMode = PlutoGridSelectingMode.row;
PlutoGridSelectingMode? gridSelectingMode = PlutoGridSelectingMode.row;

@override
void initState() {
Expand All @@ -32,34 +32,34 @@ class _AddAndRemoveRowsScreenState extends State<AddAndRemoveRowsScreen> {
rows = [];
}

void handleAddRowButton({int count}) {
void handleAddRowButton({int? count}) {
final List<PlutoRow> rows = count == null
? [DummyData.rowByColumns(columns)]
? [DummyData.rowByColumns(columns!)]
: DummyData.rowsByColumns(length: count, columns: columns);

stateManager.appendRows(rows);
stateManager!.appendRows(rows);
}

void handleRemoveCurrentRowButton() {
stateManager.removeCurrentRow();
stateManager!.removeCurrentRow();
}

void handleRemoveSelectedRowsButton() {
stateManager.removeRows(stateManager.currentSelectingRows);
stateManager!.removeRows(stateManager!.currentSelectingRows);
}

void handleFiltering() {
stateManager.setShowColumnFilter(!stateManager.showColumnFilter);
stateManager!.setShowColumnFilter(!stateManager!.showColumnFilter);
}

void setGridSelectingMode(PlutoGridSelectingMode mode) {
void setGridSelectingMode(PlutoGridSelectingMode? mode) {
if (gridSelectingMode == mode) {
return;
}

setState(() {
gridSelectingMode = mode;
stateManager.setSelectingMode(mode);
stateManager!.setSelectingMode(mode!);
});
}

Expand Down Expand Up @@ -124,7 +124,7 @@ class _AddAndRemoveRowsScreenState extends State<AddAndRemoveRowsScreen> {
),
);
}).toList(),
onChanged: (PlutoGridSelectingMode mode) {
onChanged: (PlutoGridSelectingMode? mode) {
setGridSelectingMode(mode);
},
),
Expand All @@ -141,7 +141,7 @@ class _AddAndRemoveRowsScreenState extends State<AddAndRemoveRowsScreen> {
},
onLoaded: (PlutoGridOnLoadedEvent event) {
stateManager = event.stateManager;
stateManager.setSelectingMode(gridSelectingMode);
stateManager!.setSelectingMode(gridSelectingMode!);
},
),
),
Expand Down
26 changes: 13 additions & 13 deletions example/lib/screen/feature/cell_renderer_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class CellRendererScreen extends StatefulWidget {
}

class _CellRendererScreenState extends State<CellRendererScreen> {
List<PlutoColumn> columns;
List<PlutoColumn>? columns;

List<PlutoRow> rows;
List<PlutoRow>? rows;

PlutoGridStateManager stateManager;
PlutoGridStateManager? stateManager;

@override
void initState() {
Expand All @@ -41,9 +41,9 @@ class _CellRendererScreenState extends State<CellRendererScreen> {
Icons.add_circle,
),
onPressed: () {
rendererContext.stateManager.insertRows(
rendererContext.rowIdx,
[rendererContext.stateManager.getNewRow()],
rendererContext.stateManager!.insertRows(
rendererContext.rowIdx!,
[rendererContext.stateManager!.getNewRow()],
);
},
iconSize: 18,
Expand All @@ -55,7 +55,7 @@ class _CellRendererScreenState extends State<CellRendererScreen> {
Icons.remove_circle_outlined,
),
onPressed: () {
rendererContext.stateManager
rendererContext.stateManager!
.removeRows([rendererContext.row]);
},
iconSize: 18,
Expand All @@ -64,7 +64,7 @@ class _CellRendererScreenState extends State<CellRendererScreen> {
),
Expanded(
child: Text(
rendererContext.row.cells[rendererContext.column.field].value
rendererContext.row!.cells[rendererContext.column!.field]!.value
.toString(),
maxLines: 1,
overflow: TextOverflow.ellipsis,
Expand All @@ -81,16 +81,16 @@ class _CellRendererScreenState extends State<CellRendererScreen> {
renderer: (rendererContext) {
Color textColor = Colors.black;

if (rendererContext.cell.value == 'red') {
if (rendererContext.cell!.value == 'red') {
textColor = Colors.red;
} else if (rendererContext.cell.value == 'blue') {
} else if (rendererContext.cell!.value == 'blue') {
textColor = Colors.blue;
} else if (rendererContext.cell.value == 'green') {
} else if (rendererContext.cell!.value == 'green') {
textColor = Colors.green;
}

return Text(
rendererContext.cell.value.toString(),
rendererContext.cell!.value.toString(),
style: TextStyle(
color: textColor,
fontWeight: FontWeight.bold,
Expand Down Expand Up @@ -144,7 +144,7 @@ class _CellRendererScreenState extends State<CellRendererScreen> {
print(event);
},
onLoaded: (PlutoGridOnLoadedEvent event) {
event.stateManager.setSelectingMode(PlutoGridSelectingMode.cell);
event.stateManager!.setSelectingMode(PlutoGridSelectingMode.cell);

stateManager = event.stateManager;
},
Expand Down
14 changes: 7 additions & 7 deletions example/lib/screen/feature/cell_selection_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class CellSelectionScreen extends StatefulWidget {
}

class _CellSelectionScreenState extends State<CellSelectionScreen> {
List<PlutoColumn> columns;
List<PlutoColumn>? columns;

List<PlutoRow> rows;
List<PlutoRow>? rows;

PlutoGridStateManager stateManager;
PlutoGridStateManager? stateManager;

@override
void initState() {
Expand All @@ -33,9 +33,9 @@ class _CellSelectionScreenState extends State<CellSelectionScreen> {
void handleSelected() async {
String value = '';

stateManager.currentSelectingPositionList.forEach((element) {
final cellValue = stateManager
.rows[element.rowIdx].cells[element.field].value
stateManager!.currentSelectingPositionList.forEach((element) {
final cellValue = stateManager!
.rows[element.rowIdx!]!.cells[element.field!]!.value
.toString();

value +=
Expand Down Expand Up @@ -108,7 +108,7 @@ class _CellSelectionScreenState extends State<CellSelectionScreen> {
print(event);
},
onLoaded: (PlutoGridOnLoadedEvent event) {
event.stateManager
event.stateManager!
.setSelectingMode(PlutoGridSelectingMode.cell);

stateManager = event.stateManager;
Expand Down
Loading

0 comments on commit 3feac24

Please sign in to comment.