Skip to content

Commit 4cf3d89

Browse files
committed
Adds custom sliver example code
1 parent 63fe1ba commit 4cf3d89

File tree

7 files changed

+400
-0
lines changed

7 files changed

+400
-0
lines changed

067-sliver-guide/.gitignore

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
12+
# IntelliJ related
13+
*.iml
14+
*.ipr
15+
*.iws
16+
.idea/
17+
18+
# The .vscode folder contains launch configuration and tasks you configure in
19+
# VS Code which you may wish to be included in version control, so this line
20+
# is commented out by default.
21+
#.vscode/
22+
23+
# Flutter/Dart/Pub related
24+
**/doc/api/
25+
**/ios/Flutter/.last_build_id
26+
.dart_tool/
27+
.flutter-plugins
28+
.flutter-plugins-dependencies
29+
.packages
30+
.pub-cache/
31+
.pub/
32+
/build/
33+
34+
# Web related
35+
lib/generated_plugin_registrant.dart
36+
37+
# Symbolication related
38+
app.*.symbols
39+
40+
# Obfuscation related
41+
app.*.map.json
42+
43+
# Android Studio will place build artifacts here
44+
/android/app/debug
45+
/android/app/profile
46+
/android/app/release

067-sliver-guide/.metadata

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: f4abaa0735eba4dfd8f33f73363911d63931fe03
8+
channel: stable
9+
10+
project_type: app

067-sliver-guide/lib/main.dart

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter/rendering.dart';
3+
4+
void main() {
5+
runApp(MyApp());
6+
}
7+
8+
class MyApp extends StatelessWidget {
9+
@override
10+
Widget build(BuildContext context) {
11+
return MaterialApp(
12+
title: 'Flutter Demo',
13+
theme: ThemeData(
14+
primarySwatch: Colors.blue,
15+
),
16+
home: Scaffold(
17+
body: CustomScrollView(
18+
slivers: [
19+
...List<int>.generate(5, (index) => index).map(
20+
(e) => SliverToBoxAdapter(
21+
child: Container(
22+
height: 300,
23+
color: Colors.red,
24+
margin: const EdgeInsets.symmetric(vertical: 5),
25+
),
26+
),
27+
),
28+
StickySliver(
29+
child: Container(
30+
height: 400,
31+
color: Colors.purple,
32+
),
33+
),
34+
...List<int>.generate(5, (index) => index).map(
35+
(e) => SliverToBoxAdapter(
36+
child: Container(
37+
height: 300,
38+
color: Colors.red,
39+
margin: const EdgeInsets.symmetric(vertical: 10),
40+
),
41+
),
42+
)
43+
],
44+
),
45+
),
46+
);
47+
}
48+
}
49+
50+
class RenderStickySliver extends RenderSliverSingleBoxAdapter {
51+
RenderStickySliver({RenderBox? child}) : super(child: child);
52+
53+
@override
54+
void performLayout() {
55+
var myCurrentConstraints = constraints;
56+
57+
geometry = SliverGeometry.zero;
58+
59+
child?.layout(
60+
constraints.asBoxConstraints(),
61+
parentUsesSize: true,
62+
);
63+
64+
double childExtent = child?.size.height ?? 0;
65+
66+
geometry = SliverGeometry(
67+
paintExtent: childExtent,
68+
maxPaintExtent: childExtent,
69+
paintOrigin: constraints.scrollOffset,
70+
);
71+
72+
setChildParentData(child!, constraints, geometry!);
73+
}
74+
}
75+
76+
class StickySliver extends SingleChildRenderObjectWidget {
77+
StickySliver({Widget? child, Key? key}) : super(child: child, key: key);
78+
79+
@override
80+
RenderObject createRenderObject(BuildContext context) {
81+
return RenderStickySliver();
82+
}
83+
}

067-sliver-guide/pubspec.lock

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# Generated by pub
2+
# See https://dart.dev/tools/pub/glossary#lockfile
3+
packages:
4+
async:
5+
dependency: transitive
6+
description:
7+
name: async
8+
url: "https://pub.dartlang.org"
9+
source: hosted
10+
version: "2.6.1"
11+
boolean_selector:
12+
dependency: transitive
13+
description:
14+
name: boolean_selector
15+
url: "https://pub.dartlang.org"
16+
source: hosted
17+
version: "2.1.0"
18+
characters:
19+
dependency: transitive
20+
description:
21+
name: characters
22+
url: "https://pub.dartlang.org"
23+
source: hosted
24+
version: "1.1.0"
25+
charcode:
26+
dependency: transitive
27+
description:
28+
name: charcode
29+
url: "https://pub.dartlang.org"
30+
source: hosted
31+
version: "1.2.0"
32+
clock:
33+
dependency: transitive
34+
description:
35+
name: clock
36+
url: "https://pub.dartlang.org"
37+
source: hosted
38+
version: "1.1.0"
39+
collection:
40+
dependency: transitive
41+
description:
42+
name: collection
43+
url: "https://pub.dartlang.org"
44+
source: hosted
45+
version: "1.15.0"
46+
cupertino_icons:
47+
dependency: "direct main"
48+
description:
49+
name: cupertino_icons
50+
url: "https://pub.dartlang.org"
51+
source: hosted
52+
version: "1.0.3"
53+
fake_async:
54+
dependency: transitive
55+
description:
56+
name: fake_async
57+
url: "https://pub.dartlang.org"
58+
source: hosted
59+
version: "1.2.0"
60+
flutter:
61+
dependency: "direct main"
62+
description: flutter
63+
source: sdk
64+
version: "0.0.0"
65+
flutter_test:
66+
dependency: "direct dev"
67+
description: flutter
68+
source: sdk
69+
version: "0.0.0"
70+
matcher:
71+
dependency: transitive
72+
description:
73+
name: matcher
74+
url: "https://pub.dartlang.org"
75+
source: hosted
76+
version: "0.12.10"
77+
meta:
78+
dependency: transitive
79+
description:
80+
name: meta
81+
url: "https://pub.dartlang.org"
82+
source: hosted
83+
version: "1.3.0"
84+
path:
85+
dependency: transitive
86+
description:
87+
name: path
88+
url: "https://pub.dartlang.org"
89+
source: hosted
90+
version: "1.8.0"
91+
sky_engine:
92+
dependency: transitive
93+
description: flutter
94+
source: sdk
95+
version: "0.0.99"
96+
source_span:
97+
dependency: transitive
98+
description:
99+
name: source_span
100+
url: "https://pub.dartlang.org"
101+
source: hosted
102+
version: "1.8.1"
103+
stack_trace:
104+
dependency: transitive
105+
description:
106+
name: stack_trace
107+
url: "https://pub.dartlang.org"
108+
source: hosted
109+
version: "1.10.0"
110+
stream_channel:
111+
dependency: transitive
112+
description:
113+
name: stream_channel
114+
url: "https://pub.dartlang.org"
115+
source: hosted
116+
version: "2.1.0"
117+
string_scanner:
118+
dependency: transitive
119+
description:
120+
name: string_scanner
121+
url: "https://pub.dartlang.org"
122+
source: hosted
123+
version: "1.1.0"
124+
term_glyph:
125+
dependency: transitive
126+
description:
127+
name: term_glyph
128+
url: "https://pub.dartlang.org"
129+
source: hosted
130+
version: "1.2.0"
131+
test_api:
132+
dependency: transitive
133+
description:
134+
name: test_api
135+
url: "https://pub.dartlang.org"
136+
source: hosted
137+
version: "0.3.0"
138+
typed_data:
139+
dependency: transitive
140+
description:
141+
name: typed_data
142+
url: "https://pub.dartlang.org"
143+
source: hosted
144+
version: "1.3.0"
145+
vector_math:
146+
dependency: transitive
147+
description:
148+
name: vector_math
149+
url: "https://pub.dartlang.org"
150+
source: hosted
151+
version: "2.1.0"
152+
sdks:
153+
dart: ">=2.12.0 <3.0.0"

067-sliver-guide/pubspec.yaml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: sliver_guide
2+
description: A new Flutter project.
3+
4+
# The following line prevents the package from being accidentally published to
5+
# pub.dev using `pub publish`. This is preferred for private packages.
6+
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
7+
8+
# The following defines the version and build number for your application.
9+
# A version number is three numbers separated by dots, like 1.2.43
10+
# followed by an optional build number separated by a +.
11+
# Both the version and the builder number may be overridden in flutter
12+
# build by specifying --build-name and --build-number, respectively.
13+
# In Android, build-name is used as versionName while build-number used as versionCode.
14+
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
15+
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
16+
# Read more about iOS versioning at
17+
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
18+
version: 1.0.0+1
19+
20+
environment:
21+
sdk: ">=2.12.0 <3.0.0"
22+
23+
dependencies:
24+
flutter:
25+
sdk: flutter
26+
27+
28+
# The following adds the Cupertino Icons font to your application.
29+
# Use with the CupertinoIcons class for iOS style icons.
30+
cupertino_icons: ^1.0.2
31+
32+
dev_dependencies:
33+
flutter_test:
34+
sdk: flutter
35+
36+
# For information on the generic Dart part of this file, see the
37+
# following page: https://dart.dev/tools/pub/pubspec
38+
39+
# The following section is specific to Flutter.
40+
flutter:
41+
42+
# The following line ensures that the Material Icons font is
43+
# included with your application, so that you can use the icons in
44+
# the material Icons class.
45+
uses-material-design: true
46+
47+
# To add assets to your application, add an assets section, like this:
48+
# assets:
49+
# - images/a_dot_burr.jpeg
50+
# - images/a_dot_ham.jpeg
51+
52+
# An image asset can refer to one or more resolution-specific "variants", see
53+
# https://flutter.dev/assets-and-images/#resolution-aware.
54+
55+
# For details regarding adding assets from package dependencies, see
56+
# https://flutter.dev/assets-and-images/#from-packages
57+
58+
# To add custom fonts to your application, add a fonts section here,
59+
# in this "flutter" section. Each entry in this list should have a
60+
# "family" key with the font family name, and a "fonts" key with a
61+
# list giving the asset and other descriptors for the font. For
62+
# example:
63+
# fonts:
64+
# - family: Schyler
65+
# fonts:
66+
# - asset: fonts/Schyler-Regular.ttf
67+
# - asset: fonts/Schyler-Italic.ttf
68+
# style: italic
69+
# - family: Trajan Pro
70+
# fonts:
71+
# - asset: fonts/TrajanPro.ttf
72+
# - asset: fonts/TrajanPro_Bold.ttf
73+
# weight: 700
74+
#
75+
# For details regarding fonts from package dependencies,
76+
# see https://flutter.dev/custom-fonts/#from-packages

0 commit comments

Comments
 (0)