sliver sticky header does not work?
jat1168 opened this issue · comments
Hi, I use ExampleSliver code, sticky header does not work?
XRecorder_15072022_143553.mp4
`import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:secuxtwallet/controller/gallery_controller.dart';
import 'package:secuxtwallet/model/secux_asset.dart';
import 'package:secuxtwallet/model/secux_collection.dart';
import 'package:secuxtwallet/util/socket_io_client.dart';
import 'package:sticky_and_expandable_list/sticky_and_expandable_list.dart';
class ExampleSliver extends StatefulWidget {
@OverRide
_ExampleSliverState createState() => _ExampleSliverState();
}
class _ExampleSliverState extends State {
final controller = Get.find();
final sectionList = [];
final expandableListController = ExpandableListController();
final socketIoClient = SocketIoClient();
final collectionMap = <String, List>{}.obs;
final collections = SecuXCollectionsResponse(count: '', dataList: [], isCompleted: false).obs;
final isScanning = true.obs;
@OverRide
initState() {
super.initState();
Future.delayed(Duration(seconds: 1), () async {
await socketIoClient.getNFTCollectionsByOwner(
collections, 'eth,bsc,polygon', '0xa96F57429c77352d625A3F57a94eC27C6c128f5D', '300');
await socketIoClient.getCollectionNFTsByOwner(
collectionMap, isScanning, 'eth,bsc,polygon', '0xa96F57429c77352d625A3F57a94eC27C6c128f5D', '', '50');
while (isScanning.isTrue) {
await Future.delayed(const Duration(seconds: 1), null);
}
for (final collection in collections.value.dataList) {
ExampleSection section = ExampleSection();
section.header = collection.collectionName;
section.items =
collectionMap['${collection.chain}_${collection.slug}']?.map((e) => e.imageName).toList() ?? <String>[];
section.expanded = true;
setState(() {
sectionList.add(section);
});
}
});
}
@OverRide
Widget build(BuildContext context) {
return sectionList.isEmpty
? const SafeArea(child: Scaffold(body: Text('1111')))
: SafeArea(
child: Scaffold(
body: CustomScrollView(
slivers: [
SliverAppBar(
pinned: true,
floating: true,
expandedHeight: 50,
flexibleSpace: FlexibleSpaceBar(
title: Text(
"Sliver Example",
style: TextStyle(color: Colors.white),
),
),
iconTheme: IconThemeData(color: Colors.white),
),
SliverExpandableList(
builder: SliverExpandableChildDelegate<String, ExampleSection>(
sectionList: sectionList,
headerBuilder: _buildHeader,
itemBuilder: (context, sectionIndex, itemIndex, index) {
String item = sectionList[sectionIndex].items[itemIndex];
return ListTile(
leading: CircleAvatar(
child: Text("$index"),
),
title: Text(item),
);
},
),
),
],
),
),
);
}
Widget _buildHeader(BuildContext context, int sectionIndex, int index) {
ExampleSection section = sectionList[sectionIndex];
return InkWell(
child: Container(
color: Colors.lightBlue,
height: 48,
padding: EdgeInsets.only(left: 20),
alignment: Alignment.centerLeft,
child: Text(
section.header,
style: TextStyle(color: Colors.white),
)),
onTap: () {
//toggle section expand state
setState(() {
section.setSectionExpanded(!section.isSectionExpanded());
});
});
}
}
class ExampleSection implements ExpandableListSection {
//store expand state.
late bool expanded;
//return item model list.
late List items;
//example header, optional
late String header;
@OverRide
List getItems() {
return items;
}
@OverRide
bool isSectionExpanded() {
return expanded;
}
@OverRide
void setSectionExpanded(bool expanded) {
this.expanded = expanded;
}
}
`
Sticky header version?
Flutter version?
Sticky header version? Flutter version?
sticky_and_expandable_list: 1.1.0
Flutter 3.0.2
issue solved. use verison 1.1.2
.