-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsliver_separated_child_builder_delegate.dart
More file actions
40 lines (36 loc) · 1.09 KB
/
Copy pathsliver_separated_child_builder_delegate.dart
File metadata and controls
40 lines (36 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import 'dart:math' as math;
import 'package:flutter/material.dart';
class SliverSeparatedChildBuilderDelegate extends SliverChildBuilderDelegate {
SliverSeparatedChildBuilderDelegate({
required NullableIndexedWidgetBuilder builder,
required IndexedWidgetBuilder separatorBuilder,
required int childCount,
}) : super(
(context, index) => _separatedBuilder(
context,
index,
builder,
separatorBuilder,
),
childCount: math.max(0, childCount * 2 - 1),
semanticIndexCallback: _separatedSemanticIndexCallback,
);
static int? _separatedSemanticIndexCallback(Widget _, int localIndex) {
if (localIndex.isEven) {
return localIndex ~/ 2;
}
return null;
}
static Widget? _separatedBuilder(
BuildContext context,
int index,
NullableIndexedWidgetBuilder builder,
IndexedWidgetBuilder separatorBuilder,
) {
final int itemIndex = index ~/ 2;
if (index.isEven) {
return builder(context, itemIndex);
}
return separatorBuilder(context, itemIndex);
}
}