fluttercandies / extended_nested_scroll_view

extended nested scroll view to fix following issues. 1.pinned sliver header issue 2.inner scrollables in tabview sync issue 3.pull to refresh is not work. 4.do without ScrollController in NestedScrollView's body
MIT License
604 stars 120 forks source link

I have used ExtendedNestedScrollView+TabView+GridView.builder, TabView will still be scrolled synchronously. #142

Open zhao004 opened 1 year ago

zhao004 commented 1 year ago

Content

https://github.com/fluttercandies/extended_nested_scroll_view/assets/82579833/ff157b34-35b3-4bfb-b7e8-249d8557d2f6


CodeSegment:

    return ExtendedNestedScrollView(
      onlyOneScrollInBody: true,
      headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
        return [
          buildSliverAppBar(),
          SliverToBoxAdapter(
            child: Container(
              color: Colors.red,
              width: double.infinity,
              height: 150,
              child: const Center(child: Text('Carousel')),
            ),
          ),
          buildSliverPersistentHeader(),
        ];
      },
      body: buildTabBarView(),
    );
  }

  Widget buildTabBarView() {
    return GetBuilder<FrontpageLogic>(
        id: 'body',
        builder: (logic) {
          return logic.tags.isEmpty
              ? Center(
                  child: logic.login,
                )
              : Padding(
                  padding: const EdgeInsets.all(6.0),
                  child: TabBarView(
                    controller: logic.tabController,
                    children: logic.tags
                        .map((e) => ExtendedVisibilityDetector(
                              uniqueKey: Key(e.tag),
                              child: FrontCartoonListComponent(
                                tag: e.tag,
                              ),
                            ))
                        .toList(),
                  ),
                );
        });
  }

///首页动漫列表组件
class FrontCartoonListComponent extends StatefulWidget {
  final String tag;

  const FrontCartoonListComponent({Key? key, required this.tag})
      : super(key: key);

  @override
  State<FrontCartoonListComponent> createState() =>
      _FrontCartoonListComponentState();
}

class _FrontCartoonListComponentState extends State<FrontCartoonListComponent>
    with AutomaticKeepAliveClientMixin {
  List<AltagData>? data = [];
  Widget login = const Login();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getData();
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return data!.isEmpty
        ? Center(child: login)
        : ListView.builder(
            itemCount: data?.length,
            padding: const EdgeInsets.all(0),
            itemBuilder: (ctx, i) {
              return Card(
                elevation: 1,
                color: Colors.white,
                clipBehavior: Clip.antiAlias,
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(5),
                ),
                child: Column(
                  children: [
                    buildRow(i),
                    buildGridView(i),
                    const SizedBox(height: 20),
                  ],
                ),
              );
            });
  }

  //分类标题
  Widget buildRow(int i) {
    var more = data?[i].more;
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Expanded(
            child: Text(
              data?[i].title ?? '',
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
              style: const TextStyle(
                color: Colors.black87,
                fontSize: 18,
                fontWeight: FontWeight.bold,
              ),
            ),
          ),
          if (more != null) ...[
            //更多 图标
            IconButton(
              onPressed: () {},
              icon: const Icon(Icons.more_horiz),
            ),
          ]
        ],
      ),
    );
  }

  //图片网格
  Widget buildGridView(int i) {
    return GridView.builder(
      shrinkWrap: true,
      padding: const EdgeInsets.all(0),
      physics: const NeverScrollableScrollPhysics(),
      gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 3,
        childAspectRatio: 0.65,
        crossAxisSpacing: 5,
        mainAxisSpacing: 5,
        // mainAxisExtent: 195,
      ),
      itemCount: data?[i].list?.length ?? 0,
      itemBuilder: (ctx, index) {
        return Gridimage(
          image: data?[i].list?[index].img,
          title: data?[i].list?[index].title,
          tag: data?[i].list?[index].tag,
          url: data?[i].list?[index].url,
          chapter: data?[i].list?[index].chapter,
        );
      },
    );
  }

  //获取数据
  Future<void> getData() async {
    try {
      AltagEntity? res = await Cartoon.getHome(widget.tag ?? '');
      if (res != null) {
        if (res.code != Cartoon.success) {
          login = Text(res.msg ?? '');
        }
        data = res.data;
      }
    } catch (e) {
      // log(e.toString(), name: 'CartoonErro');
      login = Text(e.toString());
    } finally {
      setState(() {});
    }
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => true;
}

FlutterViersion:

Flutter 3.10.6 • channel stable • https://github.com/flutter/flutter.git
Framework • revision f468f3366c (2 weeks ago) • 2023-07-12 15:19:05 -0700
Engine • revision cdbeda788a
Tools • Dart 3.0.6 • DevTools 2.23.1

PluginVersion:

extended_nested_scroll_view: ^6.1.2
zmtzawqlp commented 1 year ago

你把header 拉到滚动了。就会全部重置掉

zhao004 commented 1 year ago

你把header 拉到滚动了。就会全部重置掉

大佬能不能给了代码例子?

zmtzawqlp commented 1 year ago

as design

popsams commented 1 year ago

extended_nested_scroll_view: ^3.0.1 使用这个版本,后面版本有问题

CoderST commented 10 months ago

请问你解决了吗?我也遇到同样的问题?感谢 @zhao004

zmtzawqlp commented 10 months ago

没有可以运行的例子,也没有版本,我很难去调查问题的原因呢

woodjobber commented 6 months ago

同样问题。

woodjobber commented 6 months ago

页面结构是 ExtendedNestedScrollView-> TabBarView->CustomScrollView->SliverList 。无法到达 预期效果