tp7309 / flutter_sticky_and_expandable_list

粘性头部与分组列表Sliver实现 Build a grouped list, which support expand/collapse section and sticky headers, support use it with sliver widget.
MIT License
141 stars 27 forks source link

sliver sticky header does not work? #45

Closed jat1168 closed 2 years ago

jat1168 commented 2 years ago

Hi, I use ExampleSliver code, sticky header does not work?

https://user-images.githubusercontent.com/1092021/179167268-aad59659-c2df-40be-bcae-5c3a6f7744f9.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; } } `

tp7309 commented 2 years ago

Sticky header version? Flutter version?

jat1168 commented 2 years ago

Sticky header version? Flutter version?

sticky_and_expandable_list: 1.1.0 Flutter 3.0.2

tp7309 commented 2 years ago

issue solved. use verison 1.1.2.