-
Notifications
You must be signed in to change notification settings - Fork 3
/
sliver_sticky_header_centered_example.dart
94 lines (84 loc) · 2.54 KB
/
sliver_sticky_header_centered_example.dart
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:slyverin/slyverin.dart';
import 'fixtures.dart';
class SliverStickyHeaderCenteredExample extends StatefulWidget {
SliverStickyHeaderCenteredExample({Key? key}) : super(key: key);
@override
_SliverStickyHeaderCenteredExampleState createState() =>
_SliverStickyHeaderCenteredExampleState();
}
class _SliverStickyHeaderCenteredExampleState
extends State<SliverStickyHeaderCenteredExample> {
final _center = GlobalKey();
@override
Widget build(BuildContext context) {
return FutureBuilder<List<ImageAsset>>(
future: loadImages(),
builder: (context, snapshot) {
if (!snapshot.hasData)
return Center(child: CircularProgressIndicator());
final images = snapshot.data!;
final firstHalfImages = images.sublist(0, images.length ~/ 2);
final secondHalfImages = images.sublist(firstHalfImages.length);
return Scaffold(
appBar: AppBar(
title: Text('SliverStickyHeader: Centered'),
),
body: CustomScrollView(
center: _center,
slivers: [
for (final img in firstHalfImages)
_buildImageItem(img, reverse: true),
_buildCenter(),
for (final img in secondHalfImages) _buildImageItem(img),
],
),
);
},
);
}
SliverStickyHeader _buildImageItem(ImageAsset img, {bool reverse = false}) {
return SliverStickyHeader(
reverse: reverse,
overlayHeader: true,
header: ClipRect(
clipBehavior: Clip.hardEdge,
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 20, sigmaY: 20),
child: Container(
padding: EdgeInsets.all(16),
alignment: Alignment.center,
color: Colors.white.withOpacity(.4),
child: Text(
img.title,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
),
),
),
body: SliverToBoxAdapter(
child: RawImage(
image: img.image,
fit: BoxFit.cover,
),
),
);
}
SliverToBoxAdapter _buildCenter() {
return SliverToBoxAdapter(
key: _center,
child: Container(
decoration:
BoxDecoration(border: Border.symmetric(vertical: BorderSide())),
padding: EdgeInsets.all(16),
child: Center(
child: Text('Center'),
),
),
);
}
}