@@ -105,32 +105,37 @@ import 'table_span.dart';
105105///
106106/// * [TableSpan] , describes the configuration for a row or column in the
107107/// TableView.
108- /// * [TwoDimensionalScrollView] , the super class that is extended by TableView.
108+ /// * [TwoDimensionalScrollView] , a scroll view that can scroll in two
109+ /// dimensions.
109110/// * [GridView] , another scrolling widget that can be used to create tables
110111/// that scroll in one dimension.
111- class TableView extends TwoDimensionalScrollView {
112+ class TableView extends StatefulWidget {
112113 /// Creates a [TableView] that scrolls in both dimensions.
113114 ///
114115 /// A non-null [delegate] must be provided.
115116 const TableView ({
116117 super .key,
117- super .primary,
118- super .mainAxis,
119- super .horizontalDetails,
120- super .verticalDetails,
121- super .cacheExtent,
122- required TableCellDelegateMixin super .delegate,
123- super .diagonalDragBehavior = DiagonalDragBehavior .none,
124- super .dragStartBehavior,
125- super .keyboardDismissBehavior,
126- super .clipBehavior,
118+ this .primary,
119+ this .mainAxis = Axis .vertical,
120+ this .verticalDetails = const ScrollableDetails .vertical (),
121+ this .horizontalDetails = const ScrollableDetails .horizontal (),
122+ @Deprecated (
123+ 'Use scrollCacheExtent instead. '
124+ 'This feature was deprecated after v3.41.0-0.0.pre.' ,
125+ )
126+ this .cacheExtent,
127+ required this .delegate,
128+ this .diagonalDragBehavior = DiagonalDragBehavior .none,
129+ this .dragStartBehavior = DragStartBehavior .start,
130+ this .keyboardDismissBehavior,
131+ this .clipBehavior = Clip .hardEdge,
127132 this .alignment = Alignment .topLeft,
128- });
133+ }) : _isInternalDelegate = false ;
129134
130135 /// Creates a [TableView] of widgets that are created on demand.
131136 ///
132137 /// This constructor is appropriate for table views with a large
133- /// number of cells because the [cellbuilder ] is called only for those
138+ /// number of cells because the [cellBuilder ] is called only for those
134139 /// cells that are actually visible.
135140 ///
136141 /// This constructor generates a [TableCellBuilderDelegate] for building
@@ -148,15 +153,20 @@ class TableView extends TwoDimensionalScrollView {
148153 /// returning null from [ListView.builder] to signify the end of the list.
149154 TableView .builder ({
150155 super .key,
151- super .primary,
152- super .mainAxis,
153- super .horizontalDetails,
154- super .verticalDetails,
155- super .cacheExtent,
156- super .diagonalDragBehavior = DiagonalDragBehavior .none,
157- super .dragStartBehavior,
158- super .keyboardDismissBehavior,
159- super .clipBehavior,
156+
157+ this .primary,
158+ this .mainAxis = Axis .vertical,
159+ this .verticalDetails = const ScrollableDetails .vertical (),
160+ this .horizontalDetails = const ScrollableDetails .horizontal (),
161+ @Deprecated (
162+ 'Use scrollCacheExtent instead. '
163+ 'This feature was deprecated after v3.41.0-0.0.pre.' ,
164+ )
165+ this .cacheExtent,
166+ this .diagonalDragBehavior = DiagonalDragBehavior .none,
167+ this .dragStartBehavior = DragStartBehavior .start,
168+ this .keyboardDismissBehavior,
169+ this .clipBehavior = Clip .hardEdge,
160170 int pinnedRowCount = 0 ,
161171 int pinnedColumnCount = 0 ,
162172 int trailingPinnedRowCount = 0 ,
@@ -175,19 +185,18 @@ class TableView extends TwoDimensionalScrollView {
175185 assert (pinnedColumnCount >= 0 ),
176186 assert (trailingPinnedColumnCount >= 0 ),
177187 assert (columnCount == null || columnCount >= pinnedColumnCount + trailingPinnedColumnCount),
178- super (
179- delegate: TableCellBuilderDelegate (
180- columnCount: columnCount,
181- rowCount: rowCount,
182- pinnedColumnCount: pinnedColumnCount,
183- pinnedRowCount: pinnedRowCount,
184- trailingPinnedColumnCount: trailingPinnedColumnCount,
185- trailingPinnedRowCount: trailingPinnedRowCount,
186- cellBuilder: cellBuilder,
187- columnBuilder: columnBuilder,
188- rowBuilder: rowBuilder,
189- ),
190- );
188+ delegate = TableCellBuilderDelegate (
189+ columnCount: columnCount,
190+ rowCount: rowCount,
191+ pinnedColumnCount: pinnedColumnCount,
192+ pinnedRowCount: pinnedRowCount,
193+ trailingPinnedColumnCount: trailingPinnedColumnCount,
194+ trailingPinnedRowCount: trailingPinnedRowCount,
195+ cellBuilder: cellBuilder,
196+ columnBuilder: columnBuilder,
197+ rowBuilder: rowBuilder,
198+ ),
199+ _isInternalDelegate = true ;
191200
192201 /// Creates a [TableView] from an explicit two dimensional array of children.
193202 ///
@@ -201,15 +210,19 @@ class TableView extends TwoDimensionalScrollView {
201210 /// `children[vicinity.column][vicinity.row]` .
202211 TableView .list ({
203212 super .key,
204- super .primary,
205- super .mainAxis,
206- super .horizontalDetails,
207- super .verticalDetails,
208- super .cacheExtent,
209- super .diagonalDragBehavior = DiagonalDragBehavior .none,
210- super .dragStartBehavior,
211- super .keyboardDismissBehavior,
212- super .clipBehavior,
213+ this .primary,
214+ this .mainAxis = Axis .vertical,
215+ this .verticalDetails = const ScrollableDetails .vertical (),
216+ this .horizontalDetails = const ScrollableDetails .horizontal (),
217+ @Deprecated (
218+ 'Use scrollCacheExtent instead. '
219+ 'This feature was deprecated after v3.41.0-0.0.pre.' ,
220+ )
221+ this .cacheExtent,
222+ this .diagonalDragBehavior = DiagonalDragBehavior .none,
223+ this .dragStartBehavior = DragStartBehavior .start,
224+ this .keyboardDismissBehavior,
225+ this .clipBehavior = Clip .hardEdge,
213226 int pinnedRowCount = 0 ,
214227 int pinnedColumnCount = 0 ,
215228 int trailingPinnedRowCount = 0 ,
@@ -222,17 +235,134 @@ class TableView extends TwoDimensionalScrollView {
222235 assert (pinnedColumnCount >= 0 ),
223236 assert (trailingPinnedRowCount >= 0 ),
224237 assert (trailingPinnedColumnCount >= 0 ),
225- super (
226- delegate: TableCellListDelegate (
227- pinnedColumnCount: pinnedColumnCount,
228- pinnedRowCount: pinnedRowCount,
229- trailingPinnedColumnCount: trailingPinnedColumnCount,
230- trailingPinnedRowCount: trailingPinnedRowCount,
231- cells: cells,
232- columnBuilder: columnBuilder,
233- rowBuilder: rowBuilder,
234- ),
235- );
238+ delegate = TableCellListDelegate (
239+ pinnedColumnCount: pinnedColumnCount,
240+ pinnedRowCount: pinnedRowCount,
241+ trailingPinnedColumnCount: trailingPinnedColumnCount,
242+ trailingPinnedRowCount: trailingPinnedRowCount,
243+ cells: cells,
244+ columnBuilder: columnBuilder,
245+ rowBuilder: rowBuilder,
246+ ),
247+ _isInternalDelegate = true ;
248+
249+ /// {@macro flutter.widgets.scroll_view.primary}
250+ final bool ? primary;
251+
252+ /// The main axis of the two.
253+ ///
254+ /// Used to determine how to apply [primary] when true.
255+ ///
256+ /// This value should also be provided to the subclass of
257+ /// [TwoDimensionalViewport] , where it is used to determine paint order of
258+ /// children.
259+ final Axis mainAxis;
260+
261+ /// The configuration of the horizontal Scrollable.
262+ ///
263+ /// These [ScrollableDetails] can be used to set the [AxisDirection] ,
264+ /// [ScrollController] , [ScrollPhysics] and more for the horizontal axis.
265+ final ScrollableDetails horizontalDetails;
266+
267+ /// The configuration of the vertical Scrollable.
268+ ///
269+ /// These [ScrollableDetails] can be used to set the [AxisDirection] ,
270+ /// [ScrollController] , [ScrollPhysics] and more for the vertical axis.
271+ final ScrollableDetails verticalDetails;
272+
273+ /// {@macro flutter.rendering.RenderViewportBase.cacheExtent}
274+ @Deprecated (
275+ 'Use scrollCacheExtent instead. '
276+ 'This feature was deprecated after v3.41.0-0.0.pre.' ,
277+ )
278+ final double ? cacheExtent;
279+
280+ /// A delegate that provides the children for the [TwoDimensionalScrollView] .
281+ final TableCellDelegateMixin delegate;
282+
283+ /// Whether the [delegate] was provided by the user or created internally by
284+ /// the [TableView] .
285+ final bool _isInternalDelegate;
286+
287+ /// Whether scrolling gestures should lock to one axes, allow free movement
288+ /// in both axes, or be evaluated on a weighted scale.
289+ ///
290+ /// Defaults to [DiagonalDragBehavior.none] , locking axes to receive input one
291+ /// at a time.
292+ final DiagonalDragBehavior diagonalDragBehavior;
293+
294+ /// {@macro flutter.widgets.scrollable.dragStartBehavior}
295+ final DragStartBehavior dragStartBehavior;
296+
297+ /// {@macro flutter.widgets.scroll_view.keyboardDismissBehavior}
298+ ///
299+ /// If [keyboardDismissBehavior] is null then it will fallback to the inherited
300+ /// [ScrollBehavior.getKeyboardDismissBehavior] .
301+ final ScrollViewKeyboardDismissBehavior ? keyboardDismissBehavior;
302+
303+ /// {@macro flutter.material.Material.clipBehavior}
304+ ///
305+ /// Defaults to [Clip.hardEdge] .
306+ final Clip clipBehavior;
307+
308+ /// The alignment of the table within the viewport when there is extra space.
309+ ///
310+ /// Defaults to [Alignment.topLeft] .
311+ final AlignmentGeometry alignment;
312+
313+ @override
314+ State <TableView > createState () => _TableViewState ();
315+ }
316+
317+ class _TableViewState extends State <TableView > {
318+ @override
319+ void didUpdateWidget (TableView oldWidget) {
320+ super .didUpdateWidget (oldWidget);
321+ if (oldWidget._isInternalDelegate) {
322+ oldWidget.delegate.dispose ();
323+ }
324+ }
325+
326+ @override
327+ void dispose () {
328+ if (widget._isInternalDelegate) {
329+ widget.delegate.dispose ();
330+ }
331+ super .dispose ();
332+ }
333+
334+ @override
335+ Widget build (BuildContext context) {
336+ return _TableView (
337+ primary: widget.primary,
338+ mainAxis: widget.mainAxis,
339+ horizontalDetails: widget.horizontalDetails,
340+ verticalDetails: widget.verticalDetails,
341+ cacheExtent: widget.cacheExtent,
342+ diagonalDragBehavior: widget.diagonalDragBehavior,
343+ dragStartBehavior: widget.dragStartBehavior,
344+ keyboardDismissBehavior: widget.keyboardDismissBehavior,
345+ clipBehavior: widget.clipBehavior,
346+ delegate: widget.delegate,
347+ alignment: widget.alignment,
348+ );
349+ }
350+ }
351+
352+ class _TableView extends TwoDimensionalScrollView {
353+ const _TableView ({
354+ super .primary,
355+ super .mainAxis,
356+ super .horizontalDetails,
357+ super .verticalDetails,
358+ super .cacheExtent,
359+ required TableCellDelegateMixin super .delegate,
360+ super .diagonalDragBehavior = DiagonalDragBehavior .none,
361+ super .dragStartBehavior,
362+ super .keyboardDismissBehavior,
363+ super .clipBehavior,
364+ this .alignment = Alignment .topLeft,
365+ });
236366
237367 /// The alignment of the table within the viewport when there is extra space.
238368 ///
0 commit comments