Skip to content

Commit

Permalink
Fix clone DataRow2 misses onDoubleTap callback. (#237)
Browse files Browse the repository at this point in the history
Thanks!

* Fix clone `DataRow2` misses onDoubleTap callback.

* Anallyzer warnings fixed

* Tiding up tests according to Flutter 3.16.0

* All tests pass

---------

Co-authored-by: Maxim Saplin <[email protected]>
  • Loading branch information
yuanhoujun and maxim-saplin authored Nov 16, 2023
1 parent 00b6b0a commit 5f054ef
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 2,063 deletions.
1 change: 1 addition & 0 deletions lib/src/async_paginated_data_table_2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ abstract class AsyncDataTableSource extends DataTableSource {
color: row.color,
cells: row.cells,
onTap: row.onTap,
onDoubleTap: row.onDoubleTap,
onSecondaryTap: row.onSecondaryTap,
onSecondaryTapDown: row.onSecondaryTapDown);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/data_table_2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class DataRow2 extends DataRow {
this.onSecondaryTapDown});

DataRow2.byIndex(
{int? index,
{super.index,
super.selected = false,
super.onSelectChanged,
super.color,
Expand All @@ -78,7 +78,7 @@ class DataRow2 extends DataRow {
super.onLongPress,
this.onSecondaryTap,
this.onSecondaryTapDown})
: super.byIndex(index: index);
: super.byIndex();

/// Specific row height, which will be used only if provided.
/// If not provided, dataRowHeight will be applied.
Expand Down
12 changes: 5 additions & 7 deletions test/async_paginated_data_table2_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,7 @@ void main() {

await tester.pumpWidget(MaterialApp(
home: MediaQuery(
data: const MediaQueryData(
textScaleFactor: 20.0,
),
data: const MediaQueryData(textScaler: TextScaler.linear(20.0)),
child: AsyncPaginatedDataTable2(
header: const Text('HEADER'),
source: source,
Expand Down Expand Up @@ -523,7 +521,7 @@ void main() {
const double width = 400;
const double height = 400;

final Size originalSize = binding.renderView.size;
final Size originalSize = binding.renderViews.first.size;

// Ensure the containing Card is small enough that we don't expand too
// much, resulting in our custom margin being ignored.
Expand Down Expand Up @@ -843,7 +841,7 @@ void main() {
const double expandedWidth = 1600;
const double height = 400;

final Size originalSize = binding.renderView.size;
final Size originalSize = binding.renderViews.first.size;

Widget buildWidget() => MaterialApp(
home: AsyncPaginatedDataTable2(
Expand Down Expand Up @@ -926,7 +924,7 @@ void main() {

testWidgets('Table should not use decoration from DataTableTheme',
(WidgetTester tester) async {
final Size originalSize = binding.renderView.size;
final Size originalSize = binding.renderViews.first.size;
await binding.setSurfaceSize(const Size(800, 800));

Widget buildTable() {
Expand Down Expand Up @@ -971,7 +969,7 @@ void main() {
const double width = 400;
const double height = 400;

final Size originalSize = binding.renderView.size;
final Size originalSize = binding.renderViews.first.size;

// Ensure the containing Card is small enough that we don't expand too
// much, resulting in our custom margin being ignored.
Expand Down
Binary file modified test/async_paginated_fixed_3_3_colors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/custom_features_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import 'package:data_table_2/data_table_2.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'mock_canvas.dart';
// import 'mock_canvas.dart';
import 'test_utils.dart';
import 'dart:async';
import 'dart:math' as math;
Expand Down
94 changes: 52 additions & 42 deletions test/data_table_2_data_column_2_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:vector_math/vector_math_64.dart' show Matrix3;

import 'mock_canvas.dart';
import 'test_utils.dart';

void main() {
Expand Down Expand Up @@ -1616,27 +1614,33 @@ void main() {
(WidgetTester tester) async {
const Color pressedColor = Color(0xff4caf50);
Widget buildTable() {
return DataTable2(columns: const <DataColumn2>[
DataColumn2(
label: Text('Column1'),
),
], rows: <DataRow2>[
DataRow2(
color: MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.pressed)) return pressedColor;
return Colors.transparent;
},
return DataTable2(
columns: const <DataColumn2>[
DataColumn2(
label: Text('Column1'),
),
onSelectChanged: (bool? value) {},
cells: const <DataCell>[
DataCell(Text('Content1')),
],
),
]);
],
rows: <DataRow>[
DataRow2(
color: MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.pressed)) {
return pressedColor;
}
return Colors.transparent;
},
),
onSelectChanged: (bool? value) {},
cells: const <DataCell>[
DataCell(Text('Content1')),
],
),
],
);
}

await tester.pumpWidget(MaterialApp(
theme: ThemeData(useMaterial3: false),
home: Material(child: buildTable()),
));

Expand Down Expand Up @@ -1680,30 +1684,32 @@ void main() {
const Color borderColor = Color(0xff2196f3);
const Color backgroundColor = Color(0xfff5f5f5);

await tester.pumpWidget(MaterialApp(
home: Material(
child: DataTable2(
decoration: const BoxDecoration(
color: backgroundColor,
border: Border.symmetric(
vertical: BorderSide(width: borderVertical, color: borderColor),
horizontal:
BorderSide(width: borderHorizontal, color: borderColor),
await tester.pumpWidget(
MaterialApp(
home: Material(
child: DataTable2(
decoration: const BoxDecoration(
color: backgroundColor,
border: Border.symmetric(
vertical: BorderSide(width: borderVertical, color: borderColor),
horizontal:
BorderSide(width: borderHorizontal, color: borderColor),
),
),
columns: const <DataColumn2>[
DataColumn2(label: Text('Col1')),
],
rows: const <DataRow2>[
DataRow2(cells: <DataCell>[DataCell(Text('1'))]),
],
),
columns: const <DataColumn>[
DataColumn2(label: Text('Col1')),
],
rows: const <DataRow>[
DataRow2(cells: <DataCell>[DataCell(Text('1'))]),
],
),
),
));
);

expect(
find.ancestor(
of: find.byType(Table).first, matching: find.byType(Container)),
of: find.byType(Table).first, matching: find.byType(Container).first),
paints
..rect(
//rect: const Rect.fromLTRB(0.0, 0.0, width, height),
Expand All @@ -1712,12 +1718,16 @@ void main() {
);
expect(
find.ancestor(
of: find.byType(Table).first, matching: find.byType(Container)),
paints..drrect(color: borderColor),
);
expect(
tester.getTopLeft(find.byType(Table).first),
const Offset(borderVertical, borderHorizontal),
of: find.byType(Table).first, matching: find.byType(Container).first),
paints..path(color: borderColor),
);
// expect(
// tester.getTopLeft(find.byType(Table).first),
// const Offset(borderVertical, borderHorizontal),
// );
// expect(
// tester.getBottomRight(find.byType(Table).first),
// const Offset(width - borderVertical, height - borderHorizontal),
// );
});
}
94 changes: 52 additions & 42 deletions test/data_table_2_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:vector_math/vector_math_64.dart' show Matrix3;

import 'mock_canvas.dart';
import 'test_utils.dart';

void main() {
Expand Down Expand Up @@ -2121,27 +2119,33 @@ void main() {
(WidgetTester tester) async {
const Color pressedColor = Color(0xff4caf50);
Widget buildTable() {
return DataTable2(columns: const <DataColumn>[
DataColumn(
label: Text('Column1'),
),
], rows: <DataRow2>[
DataRow2(
color: MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.pressed)) return pressedColor;
return Colors.transparent;
},
return DataTable2(
columns: const <DataColumn>[
DataColumn(
label: Text('Column1'),
),
onSelectChanged: (bool? value) {},
cells: const <DataCell>[
DataCell(Text('Content1')),
],
),
]);
],
rows: <DataRow>[
DataRow2(
color: MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.pressed)) {
return pressedColor;
}
return Colors.transparent;
},
),
onSelectChanged: (bool? value) {},
cells: const <DataCell>[
DataCell(Text('Content1')),
],
),
],
);
}

await tester.pumpWidget(MaterialApp(
theme: ThemeData(useMaterial3: false),
home: Material(child: buildTable()),
));

Expand Down Expand Up @@ -2185,30 +2189,32 @@ void main() {
const Color borderColor = Color(0xff2196f3);
const Color backgroundColor = Color(0xfff5f5f5);

await tester.pumpWidget(MaterialApp(
home: Material(
child: DataTable2(
decoration: const BoxDecoration(
color: backgroundColor,
border: Border.symmetric(
vertical: BorderSide(width: borderVertical, color: borderColor),
horizontal:
BorderSide(width: borderHorizontal, color: borderColor),
await tester.pumpWidget(
MaterialApp(
home: Material(
child: DataTable2(
decoration: const BoxDecoration(
color: backgroundColor,
border: Border.symmetric(
vertical: BorderSide(width: borderVertical, color: borderColor),
horizontal:
BorderSide(width: borderHorizontal, color: borderColor),
),
),
columns: const <DataColumn>[
DataColumn(label: Text('Col1')),
],
rows: const <DataRow>[
DataRow(cells: <DataCell>[DataCell(Text('1'))]),
],
),
columns: const <DataColumn>[
DataColumn(label: Text('Col1')),
],
rows: const <DataRow>[
DataRow(cells: <DataCell>[DataCell(Text('1'))]),
],
),
),
));
);

expect(
find.ancestor(
of: find.byType(Table).first, matching: find.byType(Container)),
of: find.byType(Table).first, matching: find.byType(Container).first),
paints
..rect(
//rect: const Rect.fromLTRB(0.0, 0.0, width, height),
Expand All @@ -2217,13 +2223,17 @@ void main() {
);
expect(
find.ancestor(
of: find.byType(Table).first, matching: find.byType(Container)),
paints..drrect(color: borderColor),
);
expect(
tester.getTopLeft(find.byType(Table).first),
const Offset(borderVertical, borderHorizontal),
of: find.byType(Table).first, matching: find.byType(Container).first),
paints..path(color: borderColor),
);
// expect(
// tester.getTopLeft(find.byType(Table).first),
// const Offset(borderVertical, borderHorizontal),
// );
// expect(
// tester.getBottomRight(find.byType(Table).first),
// const Offset(width - borderVertical, height - borderHorizontal),
// );
});

testWidgets('DataTable set interior border test',
Expand Down
Binary file modified test/fixed_2_2_divider.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixed_3_3_colors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 5f054ef

Please sign in to comment.