Skip to content

Commit c5da8b5

Browse files
committed
changes done
1 parent 01cf2c8 commit c5da8b5

File tree

4 files changed

+154
-147
lines changed

4 files changed

+154
-147
lines changed

example/lib/main_temp.dart

Lines changed: 118 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -88,126 +88,126 @@ class _MyHomePageState extends State<MyHomePage>
8888
),
8989
body:
9090

91-
// ListView.builder(
92-
// itemCount: imageList.length,
93-
// itemBuilder: (context, index) => GFStickyHeaderBuilder(
94-
// direction: Axis.horizontal,
95-
// // enableHeaderOverlap: true,
96-
// // stickyContentPosition: GFPosition.end,
97-
// stickyContentBuilder:
98-
// (BuildContext context, double stuckValue) {
99-
// stuckValue = 1.0 - stuckValue.clamp(0.0, 1.0);
100-
// return Container(
101-
// height: 50,
102-
// width: MediaQuery.of(context).size.width * 0.5,
103-
// color: Color.lerp(Colors.teal[100], Colors.teal[600], stuckValue),
104-
// padding: const EdgeInsets.symmetric(horizontal: 16),
105-
// alignment: Alignment.centerLeft,
106-
// child: Row(
107-
// children: <Widget>[
108-
// Expanded(
109-
// child: Text(
110-
// 'Image #$index',
111-
// style: const TextStyle(color: Colors.white),
112-
// ),
113-
// ),
114-
// Offstage(
115-
// offstage: stuckValue <= 0.0,
116-
// child: Opacity(
117-
// opacity: stuckValue,
118-
// child: IconButton(
119-
// icon: const Icon(Icons.image, color: Colors.white),
120-
// onPressed: () =>
121-
// Scaffold.of(context).showSnackBar(SnackBar(content: Text('Favorite #$index'))),
122-
// ),
123-
// ),
124-
// ),
125-
// ],
126-
// ),
127-
// );
128-
// },
129-
// content: Container(
130-
// // margin: EdgeInsets.all(8),
131-
// height: 200,
132-
// width: MediaQuery.of(context).size.width * 0.5,
133-
// color: Colors.teal,
134-
// child: Image.network(imageList[index],
135-
// fit: BoxFit.cover, width: 100, height: 200),
136-
// ),
137-
// ))
138-
// );
91+
// ListView.builder(
92+
// itemCount: imageList.length,
93+
// itemBuilder: (context, index) => GFStickyHeaderBuilder(
94+
// direction: Axis.horizontal,
95+
// // enableHeaderOverlap: true,
96+
// // stickyContentPosition: GFPosition.end,
97+
// stickyContentBuilder:
98+
// (BuildContext context, double stuckValue) {
99+
// stuckValue = 1.0 - stuckValue.clamp(0.0, 1.0);
100+
// return Container(
101+
// height: 50,
102+
// width: MediaQuery.of(context).size.width * 0.5,
103+
// color: Color.lerp(Colors.teal[100], Colors.teal[600], stuckValue),
104+
// padding: const EdgeInsets.symmetric(horizontal: 16),
105+
// alignment: Alignment.centerLeft,
106+
// child: Row(
107+
// children: <Widget>[
108+
// Expanded(
109+
// child: Text(
110+
// 'Image #$index',
111+
// style: const TextStyle(color: Colors.white),
112+
// ),
113+
// ),
114+
// Offstage(
115+
// offstage: stuckValue <= 0.0,
116+
// child: Opacity(
117+
// opacity: stuckValue,
118+
// child: IconButton(
119+
// icon: const Icon(Icons.image, color: Colors.white),
120+
// onPressed: () =>
121+
// Scaffold.of(context).showSnackBar(SnackBar(content: Text('Favorite #$index'))),
122+
// ),
123+
// ),
124+
// ),
125+
// ],
126+
// ),
127+
// );
128+
// },
129+
// content: Container(
130+
// // margin: EdgeInsets.all(8),
131+
// height: 200,
132+
// width: MediaQuery.of(context).size.width * 0.5,
133+
// color: Colors.teal,
134+
// child: Image.network(imageList[index],
135+
// fit: BoxFit.cover, width: 100, height: 200),
136+
// ),
137+
// ))
138+
// );
139139

140-
// Center(
141-
// // alignment: AlignmentDirectional.center,
142-
// child: ListView.builder(
143-
// itemCount: imageList.length,
144-
// itemBuilder: (context, index) => GFStickyHeaderBuilder(
145-
// direction: Axis.vertical,
146-
// // enableHeaderOverlap: true,
147-
// // stickyContentPosition: GFPosition.end,
148-
// stickyContentBuilder:
149-
// (BuildContext context, double stuckValue) {
150-
// stuckValue = 1.0 - stuckValue.clamp(0.0, 1.0);
151-
// return Center(
152-
// child: Container(
153-
// height: 50.0,
154-
// width: 100,
155-
// color:
156-
// Colors.grey[900].withOpacity(0.6 + stuckValue * 0.4),
157-
// padding: EdgeInsets.symmetric(horizontal: 16.0),
158-
// alignment: Alignment.centerLeft,
159-
// child: Text(
160-
// 'Header #$index',
161-
// style: const TextStyle(color: Colors.white),
162-
// ),
163-
// ),
164-
// );
165-
// },
166-
// content: Container(
167-
// // margin: EdgeInsets.all(8),
168-
// height: 200,
169-
// width: 200,
170-
// color: Colors.teal,
171-
// child: Image.network(imageList[index],
172-
// fit: BoxFit.cover, width: 100, height: 200.0),
173-
// ),
174-
// ))),
175-
// );
140+
// Center(
141+
// // alignment: AlignmentDirectional.center,
142+
// child: ListView.builder(
143+
// itemCount: imageList.length,
144+
// itemBuilder: (context, index) => GFStickyHeaderBuilder(
145+
// direction: Axis.vertical,
146+
// // enableHeaderOverlap: true,
147+
// // stickyContentPosition: GFPosition.end,
148+
// stickyContentBuilder:
149+
// (BuildContext context, double stuckValue) {
150+
// stuckValue = 1.0 - stuckValue.clamp(0.0, 1.0);
151+
// return Center(
152+
// child: Container(
153+
// height: 50.0,
154+
// width: 100,
155+
// color:
156+
// Colors.grey[900].withOpacity(0.6 + stuckValue * 0.4),
157+
// padding: EdgeInsets.symmetric(horizontal: 16.0),
158+
// alignment: Alignment.centerLeft,
159+
// child: Text(
160+
// 'Header #$index',
161+
// style: const TextStyle(color: Colors.white),
162+
// ),
163+
// ),
164+
// );
165+
// },
166+
// content: Container(
167+
// // margin: EdgeInsets.all(8),
168+
// height: 200,
169+
// width: 200,
170+
// color: Colors.teal,
171+
// child: Image.network(imageList[index],
172+
// fit: BoxFit.cover, width: 100, height: 200.0),
173+
// ),
174+
// ))),
175+
// );
176176

177-
Container(
178-
height: 600,
179-
color: Colors.teal,
180-
child: ListView.builder(
181-
itemCount: imageList.length,
182-
itemBuilder: (context, index) => GFStickyHeader(
183-
enableHeaderOverlap: true,
184-
direction: Axis.vertical,
185-
stickyContentPosition: GFPosition.end,
186-
stickyContent: Container(
187-
// alignment: AlignmentDirectional.centerEnd,
188-
child: Container(
189-
alignment: AlignmentDirectional.center,
190-
height: 50,
191-
width: 100,
192-
color: Colors.blueGrey[700],
193-
padding: EdgeInsets.symmetric(horizontal: 16.0),
194-
child: Text(
195-
'Image $index',
196-
style: const TextStyle(color: Colors.white),
197-
),
198-
),
199-
),
200-
content: Container(
201-
// height: 100,
202-
width: 200,
203-
child: Image.network(imageList[index],
204-
fit: BoxFit.cover, height: 100,
205-
),
206-
),
207-
)
208-
),
209-
)
210-
);
177+
Container(
178+
height: 600,
179+
color: Colors.teal,
180+
child: ListView.builder(
181+
itemCount: imageList.length,
182+
itemBuilder: (context, index) => GFStickyHeader(
183+
// enableHeaderOverlap: true,
184+
direction: Axis.horizontal,
185+
stickyContentPosition: GFPosition.end,
186+
stickyContent: Container(
187+
// alignment: AlignmentDirectional.centerEnd,
188+
child: Container(
189+
alignment: AlignmentDirectional.center,
190+
height: 50,
191+
width: 100,
192+
color: Colors.blueGrey[700],
193+
padding: EdgeInsets.symmetric(horizontal: 16.0),
194+
child: Text(
195+
'Image $index',
196+
style: const TextStyle(color: Colors.white),
197+
),
198+
),
199+
),
200+
content: Container(
201+
// height: 100,
202+
width: 200,
203+
child: Image.network(
204+
imageList[index],
205+
fit: BoxFit.cover,
206+
height: 100,
207+
),
208+
),
209+
)),
210+
));
211211

212212
// ListView(
213213
// children: [

lib/components/sticky_header/gf_sticky_header.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ class GFStickyHeader extends MultiChildRenderObjectWidget {
1919
: assert(direction != null),
2020
super(
2121
key: key,
22-
children: stickyContentPosition == GFPosition.start && direction == Axis.horizontal
22+
children: stickyContentPosition == GFPosition.start &&
23+
direction == Axis.horizontal
2324
? [stickyContent, content]
24-
: stickyContentPosition == GFPosition.start && direction == Axis.vertical ? [content, stickyContent]
25-
: [content, stickyContent]);
25+
: stickyContentPosition == GFPosition.start &&
26+
direction == Axis.vertical
27+
? [content, stickyContent]
28+
: [content, stickyContent]);
2629

2730
/// widget can be used to define [stickyContent].
2831
final Widget stickyContent;
@@ -31,7 +34,7 @@ class GFStickyHeader extends MultiChildRenderObjectWidget {
3134
final Widget content;
3235

3336
/// On state true, the [stickyContent] will overlap the [content].
34-
/// Default value is false.
37+
/// Only works when direction is [Axis.vertical]. Default set to false.
3538
final bool enableHeaderOverlap;
3639

3740
/// [GFPosition] allows to [stickyContentPosition] to stick at top in [Axis.vertical] and stick at start in [Axis.horizontal]

lib/components/sticky_header/gf_sticky_header_builder.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class GFStickyHeaderBuilder extends StatefulWidget {
2626
final Widget content;
2727

2828
/// On state true, the [stickyContentBuilder] will overlap the [content].
29-
/// Default value is false.
29+
/// Only works when direction is [Axis.vertical]. Default set to false.
3030
final bool enableHeaderOverlap;
3131

3232
/// [GFPosition] allows to [stickyContentPosition] to stick at top in [Axis.vertical] and stick at start in [Axis.horizontal]

lib/components/sticky_header/render_gf_sticky_header.dart

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ class RenderGFStickyHeader extends RenderBox
4646
}
4747

4848
// ignore: avoid_setters_without_getters
49-
set callback(RenderGFStickyHeaderCallback newValue) {
50-
if (_callback == newValue) {
49+
set callback(RenderGFStickyHeaderCallback value) {
50+
if (_callback == value) {
5151
return;
5252
}
53-
_callback = newValue;
53+
_callback = value;
5454
markNeedsLayout();
5555
}
5656

@@ -61,14 +61,6 @@ class RenderGFStickyHeader extends RenderBox
6161
}
6262
}
6363

64-
@override
65-
double computeDistanceToActualBaseline(TextBaseline baseline) {
66-
if (_direction == Axis.horizontal) {
67-
return defaultComputeDistanceToHighestActualBaseline(baseline);
68-
}
69-
return defaultComputeDistanceToFirstActualBaseline(baseline);
70-
}
71-
7264
int _getFlex(RenderBox child) {
7365
final FlexParentData childParentData = child.parentData;
7466
return childParentData.flex ?? 0;
@@ -108,12 +100,19 @@ class RenderGFStickyHeader extends RenderBox
108100
super.detach();
109101
}
110102

111-
RenderBox get _stickyContentBody =>
112-
_stickyContentPosition == GFPosition.start && _direction == Axis.horizontal ? firstChild
113-
: _stickyContentPosition == GFPosition.end && _direction == Axis.vertical ? firstChild: lastChild;
114-
RenderBox get _contentBody =>
115-
_stickyContentPosition == GFPosition.start && _direction == Axis.horizontal ? lastChild
116-
: _stickyContentPosition == GFPosition.end && _direction == Axis.vertical ? lastChild: firstChild;
103+
RenderBox get _stickyContentBody => _stickyContentPosition ==
104+
GFPosition.start &&
105+
_direction == Axis.horizontal
106+
? firstChild
107+
: _stickyContentPosition == GFPosition.end && _direction == Axis.vertical
108+
? firstChild
109+
: lastChild;
110+
RenderBox get _contentBody => _stickyContentPosition == GFPosition.start &&
111+
_direction == Axis.horizontal
112+
? lastChild
113+
: _stickyContentPosition == GFPosition.end && _direction == Axis.vertical
114+
? lastChild
115+
: firstChild;
117116

118117
double getHeaderTileStuckOffset() {
119118
final scrollableContent = _scrollable.context.findRenderObject();
@@ -149,11 +148,10 @@ class RenderGFStickyHeader extends RenderBox
149148

150149
final double stickyContentBodyOffset = getHeaderTileStuckOffset();
151150

152-
153151
assert(constraints != null);
154152

155153
double crossSize = 0;
156-
double allocatedSize = 0;
154+
double allotedSize = 0;
157155
RenderBox child = firstChild;
158156
// ignore: unused_local_variable
159157
int totalChildren = 0;
@@ -174,14 +172,14 @@ class RenderGFStickyHeader extends RenderBox
174172
break;
175173
}
176174
child.layout(innerConstraints, parentUsesSize: true);
177-
allocatedSize += _getMainSize(child);
175+
allotedSize += _getMainSize(child);
178176
crossSize = math.max(crossSize, _getCrossSize(child));
179177
}
180178
assert(child.parentData == childParentData);
181179
child = childParentData.nextSibling;
182180
}
183181

184-
final double idealSize = allocatedSize;
182+
final double idealSize = allotedSize;
185183
double actualSize;
186184
switch (_direction) {
187185
case Axis.horizontal:
@@ -213,11 +211,17 @@ class RenderGFStickyHeader extends RenderBox
213211
case Axis.horizontal:
214212
final FlexParentData contentBodyParentData = _contentBody.parentData;
215213
contentBodyParentData.offset =
216-
_stickyContentPosition == GFPosition.start ? Offset(_stickyContentBody.size.width, 0) : const Offset(0, 0);
214+
_stickyContentPosition == GFPosition.start
215+
? Offset(_stickyContentBody.size.width, 0)
216+
: const Offset(0, 0);
217217
final FlexParentData stickyContentBodyParentData =
218218
_stickyContentBody.parentData;
219-
stickyContentBodyParentData.offset =
220-
Offset(childMainPosition, max(min(-stickyContentBodyOffset, height - stickyContentBodyHeight), 0));
219+
stickyContentBodyParentData.offset = Offset(
220+
childMainPosition,
221+
max(
222+
min(-stickyContentBodyOffset,
223+
height - stickyContentBodyHeight),
224+
0));
221225
break;
222226
case Axis.vertical:
223227
final FlexParentData contentBodyParentData = _contentBody.parentData;

0 commit comments

Comments
 (0)