Skip to content

Commit 955f728

Browse files
authored
Merge pull request #41 from deepikahr/GFStickyHeader
Gf sticky header component completed
2 parents d9347a9 + e99fedb commit 955f728

File tree

5 files changed

+412
-0
lines changed

5 files changed

+412
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
}=- m
2+
0[
3+
14
[![pub package](https://img.shields.io/pub/v/getwidget.svg)](https://pub.dartlang.org/packages/getwidget) [![Build Status](https://travis-ci.org/ionicfirebaseapp/getwidget.svg?branch=master)](https://travis-ci.com/ionicfirebaseapp/getwidget) [![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=102)](https://opensource.org/licenses/MIT) [![License](https://img.shields.io/badge/license-MIT-orange.svg)](https://github.com/ionicfirebaseapp/getwidget/blob/master/LICENSE) [![Twitter Follow](https://img.shields.io/twitter/follow/getwidgetdev.svg?style=social)](https://twitter.com/getwidgetdev)
25

36

7+
":????????????//// ;/p[[[[`"
8+
9+
410
<p align="center">
511
<a href="https://docs.getwidget.dev/" target="_blank">
612
<img src="https://ik.imagekit.io/ionicfirebaseapp/logo.black_iOBoLWdj2I.png" alt="GetWidget">
@@ -28,6 +34,7 @@
2834
</p>
2935

3036

37+
3138
## Quick start
3239

3340
Read the [Getting started page](https://docs.getwidget.dev)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import 'package:flutter/foundation.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:flutter/rendering.dart';
4+
import 'package:flutter/widgets.dart';
5+
import 'package:meta/meta.dart';
6+
import 'package:getwidget/getwidget.dart';
7+
8+
/// Place this widget inside a [ListView], [GridView], [CustomScrollView], [SingleChildScrollView] or similar.
9+
10+
class GFStickyHeader extends MultiChildRenderObjectWidget {
11+
GFStickyHeader(
12+
{Key key,
13+
@required this.stickyContent,
14+
@required this.content,
15+
this.direction = Axis.vertical,
16+
this.enableHeaderOverlap = false,
17+
this.callback,
18+
this.stickyContentPosition = GFPosition.start})
19+
: assert(direction != null),
20+
super(
21+
key: key,
22+
children: stickyContentPosition == GFPosition.start &&
23+
direction == Axis.horizontal
24+
? [stickyContent, content]
25+
: stickyContentPosition == GFPosition.start &&
26+
direction == Axis.vertical
27+
? [content, stickyContent]
28+
: [content, stickyContent]);
29+
30+
/// widget can be used to define [stickyContent].
31+
final Widget stickyContent;
32+
33+
/// widget can be used to define [content].
34+
final Widget content;
35+
36+
/// On state true, the [stickyContent] will overlap the [content].
37+
/// Only works when direction is [Axis.vertical]. Default set to false.
38+
final bool enableHeaderOverlap;
39+
40+
/// [GFPosition] allows to [stickyContentPosition] to stick at top in [Axis.vertical] and stick at start in [Axis.horizontal]
41+
/// Defaults to [GFPosition.start]
42+
final GFPosition stickyContentPosition;
43+
44+
/// Allows to add custom stickyHeader stuck offset value
45+
final RenderGFStickyHeaderCallback callback;
46+
47+
/// [direction] allows children to align in vertical / horizontal way
48+
/// Defaults to [Axis.vertical]
49+
final Axis direction;
50+
51+
@override
52+
RenderGFStickyHeader createRenderObject(BuildContext context) {
53+
final scrollable = Scrollable.of(context);
54+
assert(scrollable != null);
55+
return RenderGFStickyHeader(
56+
direction: direction,
57+
scrollable: scrollable,
58+
enableHeaderOverlap: enableHeaderOverlap,
59+
callback: callback,
60+
stickyContentPosition: stickyContentPosition,
61+
);
62+
}
63+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:getwidget/getwidget.dart';
3+
4+
typedef StickyHeaderWidgetBuilder = Widget Function(
5+
BuildContext context, double stuckValue);
6+
7+
/// Place this widget inside a [ListView], [GridView], [CustomScrollView], [SingleChildScrollView] or similar.
8+
9+
class GFStickyHeaderBuilder extends StatefulWidget {
10+
/// Constructs a new [GFStickyHeaderBuilder] widget.
11+
const GFStickyHeaderBuilder({
12+
Key key,
13+
@required this.stickyContentBuilder,
14+
@required this.content,
15+
this.direction = Axis.vertical,
16+
this.enableHeaderOverlap = false,
17+
this.callback,
18+
this.stickyContentPosition = GFPosition.start,
19+
}) : assert(direction != null),
20+
super(key: key);
21+
22+
/// widget can be used to define [stickyContentBuilder].
23+
final StickyHeaderWidgetBuilder stickyContentBuilder;
24+
25+
/// widget can be used to define [content].
26+
final Widget content;
27+
28+
/// On state true, the [stickyContentBuilder] will overlap the [content].
29+
/// Only works when direction is [Axis.vertical]. Default set to false.
30+
final bool enableHeaderOverlap;
31+
32+
/// [GFPosition] allows to [stickyContentPosition] to stick at top in [Axis.vertical] and stick at start in [Axis.horizontal]
33+
/// Defaults to [GFPosition.start]
34+
final GFPosition stickyContentPosition;
35+
36+
/// Allows to add custom stickyHeader stuck offset value
37+
final RenderGFStickyHeaderCallback callback;
38+
39+
/// [direction] allows children to align in vertical / horizontal way
40+
/// Defaults to [Axis.vertical]
41+
final Axis direction;
42+
43+
@override
44+
_GFStickyHeaderBuilderState createState() => _GFStickyHeaderBuilderState();
45+
}
46+
47+
class _GFStickyHeaderBuilderState extends State<GFStickyHeaderBuilder> {
48+
double _stuckValue;
49+
50+
@override
51+
Widget build(BuildContext context) => GFStickyHeader(
52+
enableHeaderOverlap: widget.enableHeaderOverlap,
53+
direction: widget.direction,
54+
stickyContentPosition: widget.stickyContentPosition,
55+
stickyContent: LayoutBuilder(
56+
builder: (context, _) =>
57+
widget.stickyContentBuilder(context, _stuckValue ?? 0.0),
58+
),
59+
content: widget.content,
60+
callback: (double stuckValue) {
61+
if (_stuckValue != stuckValue) {
62+
_stuckValue = stuckValue;
63+
WidgetsBinding.instance.endOfFrame.then((_) {
64+
if (mounted) {
65+
setState(() {});
66+
}
67+
});
68+
}
69+
},
70+
);
71+
}

0 commit comments

Comments
 (0)