Skip to content

Commit

Permalink
Added the possibility to have multiple slivers as child, and even sti…
Browse files Browse the repository at this point in the history
…cky header (currently one one inside one other works).

Also solves letsar#62
  • Loading branch information
UnderKoen committed Jun 16, 2021
1 parent ea97f54 commit 8da6c56
Show file tree
Hide file tree
Showing 5 changed files with 378 additions and 105 deletions.
63 changes: 63 additions & 0 deletions example/lib/examples/double_list.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import 'package:flutter/material.dart';
import 'package:flutter_sticky_header/flutter_sticky_header.dart';

import '../common.dart';

class DoubleListExample extends StatelessWidget {
const DoubleListExample({
Key? key,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return AppScaffold(
title: 'List Example',
slivers: [
_StickyHeaderList(index: 0),
_StickyHeaderList(index: 1),
_StickyHeaderList(index: 2),
_StickyHeaderList(index: 3),
],
);
}
}

class _StickyHeaderList extends StatelessWidget {
const _StickyHeaderList({
Key? key,
this.index,
}) : super(key: key);

final int? index;

@override
Widget build(BuildContext context) {
return SliverStickyHeader(
header: Header(index: index),
slivers: [
SliverList(
delegate: SliverChildBuilderDelegate(
(context, i) => ListTile(
leading: CircleAvatar(
child: Text('$index'),
),
title: Text('List tile #$i'),
),
childCount: 6,
),
),
SliverList(
delegate: SliverChildBuilderDelegate(
(context, i) => ListTile(
trailing: CircleAvatar(
child: Text('$index'),
),
title: Text('List tile #$i'),
),
childCount: 3,
),
),
],
);
}
}
89 changes: 89 additions & 0 deletions example/lib/examples/indented_header.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import 'package:flutter/material.dart';
import 'package:flutter_sticky_header/flutter_sticky_header.dart';

import '../common.dart';

class IndentedHeaderExample extends StatelessWidget {
const IndentedHeaderExample({
Key? key,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return AppScaffold(
title: 'List Example',
slivers: [
_StickyHeaderList(index: 0),
_StickyHeaderList(index: 1),
_StickyHeaderList(index: 2),
_StickyHeaderList(index: 3),
],
);
}
}

class _StickyHeaderList extends StatelessWidget {
const _StickyHeaderList({
Key? key,
this.index,
}) : super(key: key);

final int? index;

@override
Widget build(BuildContext context) {
return SliverStickyHeader(
header: Header(index: index),
slivers: [
SliverStickyHeader(
header: Header(title: "Subheader #1"),
slivers: [
SliverList(
delegate: SliverChildBuilderDelegate(
(context, i) => ListTile(
leading: CircleAvatar(
child: Text('$index'),
),
title: Text('List tile #$i'),
),
childCount: 6,
),
),
],
),
SliverStickyHeader(
header: Header(title: "Subheader #2"),
slivers: [
SliverList(
delegate: SliverChildBuilderDelegate(
(context, i) => ListTile(
leading: CircleAvatar(
child: Text('$index'),
),
title: Text('List tile #$i'),
),
childCount: 6,
),
),
],
),
SliverStickyHeader(
header: Header(title: "Subheader #3"),
slivers: [
SliverList(
delegate: SliverChildBuilderDelegate(
(context, i) => ListTile(
leading: CircleAvatar(
child: Text('$index'),
),
title: Text('List tile #$i'),
),
childCount: 6,
),
),
],
),
],
);
}
}
10 changes: 10 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:example/examples/double_list.dart';
import 'package:example/examples/indented_header.dart';
import 'package:flutter/material.dart';

import 'examples/animated_header.dart';
Expand Down Expand Up @@ -65,6 +67,14 @@ class _Home extends StatelessWidget {
text: 'Mixing other slivers',
builder: (_) => const MixSliversExample(),
),
_Item(
text: 'Multiple Slivers List Example',
builder: (_) => const DoubleListExample(),
),
_Item(
text: 'Indented Slivers List Example',
builder: (_) => const IndentedHeaderExample(),
),
],
),
);
Expand Down
Loading

0 comments on commit 8da6c56

Please sign in to comment.