Repository navigation
Commit c983254
authored
[two_dimensional_scrollables] Exclude trailing pinned spans from the non-pinned range (#12666)
`RenderTableViewport` lays out and paints the table as nine regions: leading pinned, regular and
trailing pinned rows, each crossed with the same three column categories.
`_updateFirstAndLastVisibleCell` binary searches for the last regular row and column of the visible
range, and when no regular span reaches the trailing edge of the layout target it fell back to the
last index in the metrics map:
```dart
_lastNonPinnedColumn ??= _columnMetrics.length - 1;
```
Whenever `trailingPinnedRowCount` or `trailingPinnedColumnCount` is greater than zero, that last
index *is* a trailing pinned span. The regular range then overlaps the trailing pinned range, and
the same `TableVicinity` is visited by two regions in a single layout and paint pass.
`_updateColumnMetrics` and `_updateRowMetrics` already cap the same value correctly, with the rule
that `_lastRegularColumnIndex` and `_lastRegularRowIndex` express, so the two code paths disagreed.
This PR makes `_updateFirstAndLastVisibleCell` use those getters. The old fallback is kept for the
case where they are null — infinite spans with no null terminator — where trailing pinned spans
cannot exist, since `_firstTrailingPinnedColumn` and `_firstTrailingPinnedRow` both require a
non-null span count.
Fixes flutter/flutter#185842
Fixes flutter/flutter#190800
## Beyond the duplicated work
The overlap is not only wasted layout. Scrolling a table to the end with a trailing pinned span
throws, because two regions claim the same cell:
```
Expected to re-use an element at (row: 0, column: 19), but none was found.
package:flutter/src/widgets/two_dimensional_viewport.dart:377 'elementToReuse != null'
```
and, once the spans carry a decoration, the non-pinned region reaches a cell whose `paintOffset` was
never set for it:
```
Null check operator used on a null value
RenderTableViewport._paintCells.getColumnRect (table.dart:1888)
```
Dragging through a 60x60 table with pinned and trailing pinned rows and columns throws
`Expected to re-use an element at ...` and `TableViewCell for (row: 1, column: 58) could not be
found` before this change, and nothing after it. That is the same subsystem and trigger as
flutter/flutter#190800, but the specific assertion reported there did not
reproduce in my runs, so I am not claiming this fixes it.
## Tests
Two regression tests are added to `table_test.dart`, one per axis. Each scrolls a table with a
trailing pinned span to the end, asserts that no exception is thrown, and asserts that the trailing
pinned span's decoration is painted exactly once — by the trailing pinned region only. Both fail
before this change.
Counting `cellBuilder` calls does not work as a test here: `buildOrObtainChildFor` caches children
for the frame and `RenderObject.layout` early-returns on unchanged constraints, so the duplicated
visit is invisible from the delegate. The new `CountingSpanDecoration` helper observes it through
the public `TableSpanDecoration.paint` API instead.
## Pre-Review Checklist
[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.1 parent 6b8b927 commit c983254
4 files changed
Lines changed: 291 additions & 10 deletions
File tree
- packages/two_dimensional_scrollables
- lib/src/table_view
- test/table_view
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1033 | 1033 | | |
1034 | 1034 | | |
1035 | 1035 | | |
1036 | | - | |
1037 | | - | |
1038 | | - | |
1039 | | - | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
1040 | 1052 | | |
1041 | 1053 | | |
1042 | 1054 | | |
1043 | | - | |
1044 | | - | |
| 1055 | + | |
| 1056 | + | |
1045 | 1057 | | |
1046 | 1058 | | |
1047 | 1059 | | |
| |||
1081 | 1093 | | |
1082 | 1094 | | |
1083 | 1095 | | |
| 1096 | + | |
| 1097 | + | |
1084 | 1098 | | |
1085 | 1099 | | |
1086 | 1100 | | |
1087 | 1101 | | |
| 1102 | + | |
| 1103 | + | |
1088 | 1104 | | |
1089 | 1105 | | |
1090 | | - | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
1091 | 1109 | | |
1092 | 1110 | | |
1093 | 1111 | | |
| |||
1110 | 1128 | | |
1111 | 1129 | | |
1112 | 1130 | | |
| 1131 | + | |
| 1132 | + | |
1113 | 1133 | | |
1114 | 1134 | | |
1115 | 1135 | | |
1116 | 1136 | | |
| 1137 | + | |
| 1138 | + | |
1117 | 1139 | | |
1118 | 1140 | | |
1119 | | - | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
1120 | 1144 | | |
1121 | 1145 | | |
1122 | 1146 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
42 | 56 | | |
43 | 57 | | |
44 | 58 | | |
| |||
4008 | 4022 | | |
4009 | 4023 | | |
4010 | 4024 | | |
| 4025 | + | |
| 4026 | + | |
| 4027 | + | |
| 4028 | + | |
| 4029 | + | |
| 4030 | + | |
| 4031 | + | |
| 4032 | + | |
| 4033 | + | |
| 4034 | + | |
| 4035 | + | |
| 4036 | + | |
| 4037 | + | |
| 4038 | + | |
| 4039 | + | |
| 4040 | + | |
| 4041 | + | |
| 4042 | + | |
| 4043 | + | |
| 4044 | + | |
| 4045 | + | |
| 4046 | + | |
| 4047 | + | |
| 4048 | + | |
| 4049 | + | |
| 4050 | + | |
| 4051 | + | |
| 4052 | + | |
| 4053 | + | |
| 4054 | + | |
| 4055 | + | |
| 4056 | + | |
| 4057 | + | |
| 4058 | + | |
| 4059 | + | |
| 4060 | + | |
| 4061 | + | |
| 4062 | + | |
| 4063 | + | |
| 4064 | + | |
| 4065 | + | |
| 4066 | + | |
| 4067 | + | |
| 4068 | + | |
| 4069 | + | |
| 4070 | + | |
| 4071 | + | |
| 4072 | + | |
| 4073 | + | |
| 4074 | + | |
| 4075 | + | |
| 4076 | + | |
| 4077 | + | |
| 4078 | + | |
| 4079 | + | |
| 4080 | + | |
| 4081 | + | |
| 4082 | + | |
| 4083 | + | |
| 4084 | + | |
| 4085 | + | |
| 4086 | + | |
| 4087 | + | |
| 4088 | + | |
| 4089 | + | |
| 4090 | + | |
| 4091 | + | |
| 4092 | + | |
| 4093 | + | |
| 4094 | + | |
| 4095 | + | |
| 4096 | + | |
| 4097 | + | |
| 4098 | + | |
| 4099 | + | |
| 4100 | + | |
| 4101 | + | |
| 4102 | + | |
| 4103 | + | |
| 4104 | + | |
| 4105 | + | |
| 4106 | + | |
| 4107 | + | |
| 4108 | + | |
| 4109 | + | |
| 4110 | + | |
| 4111 | + | |
| 4112 | + | |
| 4113 | + | |
| 4114 | + | |
| 4115 | + | |
| 4116 | + | |
| 4117 | + | |
| 4118 | + | |
| 4119 | + | |
| 4120 | + | |
| 4121 | + | |
| 4122 | + | |
| 4123 | + | |
| 4124 | + | |
| 4125 | + | |
| 4126 | + | |
| 4127 | + | |
| 4128 | + | |
| 4129 | + | |
| 4130 | + | |
| 4131 | + | |
| 4132 | + | |
| 4133 | + | |
| 4134 | + | |
| 4135 | + | |
| 4136 | + | |
| 4137 | + | |
| 4138 | + | |
| 4139 | + | |
| 4140 | + | |
| 4141 | + | |
| 4142 | + | |
| 4143 | + | |
| 4144 | + | |
| 4145 | + | |
| 4146 | + | |
| 4147 | + | |
| 4148 | + | |
| 4149 | + | |
| 4150 | + | |
| 4151 | + | |
| 4152 | + | |
| 4153 | + | |
| 4154 | + | |
| 4155 | + | |
| 4156 | + | |
| 4157 | + | |
| 4158 | + | |
| 4159 | + | |
| 4160 | + | |
| 4161 | + | |
| 4162 | + | |
| 4163 | + | |
| 4164 | + | |
| 4165 | + | |
| 4166 | + | |
| 4167 | + | |
| 4168 | + | |
| 4169 | + | |
| 4170 | + | |
| 4171 | + | |
| 4172 | + | |
| 4173 | + | |
| 4174 | + | |
| 4175 | + | |
| 4176 | + | |
| 4177 | + | |
| 4178 | + | |
| 4179 | + | |
| 4180 | + | |
| 4181 | + | |
| 4182 | + | |
| 4183 | + | |
| 4184 | + | |
| 4185 | + | |
| 4186 | + | |
| 4187 | + | |
| 4188 | + | |
| 4189 | + | |
| 4190 | + | |
| 4191 | + | |
| 4192 | + | |
| 4193 | + | |
| 4194 | + | |
| 4195 | + | |
| 4196 | + | |
| 4197 | + | |
| 4198 | + | |
| 4199 | + | |
| 4200 | + | |
| 4201 | + | |
| 4202 | + | |
| 4203 | + | |
| 4204 | + | |
| 4205 | + | |
| 4206 | + | |
| 4207 | + | |
| 4208 | + | |
| 4209 | + | |
| 4210 | + | |
| 4211 | + | |
| 4212 | + | |
| 4213 | + | |
| 4214 | + | |
| 4215 | + | |
| 4216 | + | |
| 4217 | + | |
| 4218 | + | |
| 4219 | + | |
| 4220 | + | |
| 4221 | + | |
| 4222 | + | |
| 4223 | + | |
| 4224 | + | |
| 4225 | + | |
| 4226 | + | |
| 4227 | + | |
| 4228 | + | |
| 4229 | + | |
| 4230 | + | |
| 4231 | + | |
| 4232 | + | |
| 4233 | + | |
| 4234 | + | |
| 4235 | + | |
| 4236 | + | |
| 4237 | + | |
| 4238 | + | |
| 4239 | + | |
| 4240 | + | |
| 4241 | + | |
| 4242 | + | |
| 4243 | + | |
| 4244 | + | |
| 4245 | + | |
| 4246 | + | |
| 4247 | + | |
| 4248 | + | |
| 4249 | + | |
| 4250 | + | |
| 4251 | + | |
| 4252 | + | |
| 4253 | + | |
| 4254 | + | |
| 4255 | + | |
| 4256 | + | |
| 4257 | + | |
| 4258 | + | |
| 4259 | + | |
| 4260 | + | |
| 4261 | + | |
| 4262 | + | |
| 4263 | + | |
| 4264 | + | |
| 4265 | + | |
4011 | 4266 | | |
4012 | 4267 | | |
4013 | 4268 | | |
| |||
0 commit comments