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
596 stars 120 forks source link

[How to use] child scrollview adding scrollcontroller #155

Closed LEEKIWAN closed 5 months ago

LEEKIWAN commented 5 months ago

Platforms

dart

Description

I want to add a scroll controller to the child view on the tab view page because paging is required, but there is an issue where full scrolling is possible when I add it. Is there a way?

My code

class SymbolDetailPage extends GetView<SymbolDetailPageController> {
  final double tabBarHeight = 40;

  SymbolDetailPage({super.key});

  @override
  Widget build(BuildContext context) {
    context.theme;
    return Scaffold(
      body: SafeArea(
        child: Column(
          children: [
            Obx(() => SymbolDetailNavigationBar(
                symbolDetail: controller.symbolDetail.value, naviBottomScrollController: controller.naviBottomScrollController, naviTopScrollController: controller.naviTopScrollController)),
            Expanded(
              child: ExtendedNestedScrollView(
                headerSliverBuilder: (BuildContext c, bool f) {
                  return [
                    SliverToBoxAdapter(
                      child: Obx(
                        () => SymbolDetailHeader(
                          symbolDetail: controller.symbolDetail.value,
                          isFolded: controller.isHeaderFolded.value,
                          onExpandTapped: () {
                            controller.isHeaderFolded.value = !controller.isHeaderFolded.value;
                          },
                        ),
                      ),
                    ),
                  ];
                },
                controller: controller.outerScrollController,
                pinnedHeaderSliverHeightBuilder: () => 0,
                body: Obx(
                  () => Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      if (controller.tabController.value != null)
                        tabbar(),
                      Divider(height: 1),
                      if (controller.tabController.value != null)
                        Expanded(
                          child: TabBarView(
                            controller: controller.tabController.value,
                            children: controller.tabPageList,                 //      !!!!!!!!!!!!!!!!!!!!!!!
                          ),
                        )
                    ],
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget tabbar() {
    return TabBar(
      padding: EdgeInsets.symmetric(horizontal: 24),
      labelPadding: EdgeInsets.symmetric(horizontal: 10),
      controller: controller.tabController.value,
      labelColor: Get.textTheme.bodyMedium?.color,
      indicatorColor: Get.textTheme.bodyMedium?.color,
      indicatorSize: TabBarIndicatorSize.tab,
      isScrollable: true,
      unselectedLabelColor: Get.textTheme.bodySmall?.color,
      labelStyle: Get.textTheme.titleSmall?.copyWith(fontWeight: FontWeight.w700),
      tabs: [
        SizedBox(height: tabBarHeight, child: Tab(text: 'Chart')),
        SizedBox(height: tabBarHeight, child: Tab(text: 'Signal')),
        SizedBox(height: tabBarHeight, child: Tab(text: 'News')),
        SizedBox(height: tabBarHeight, child: Tab(text: 'Overview')),
      ],
    );
  }
}
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:waiker/modules/symbol_detail/controller/symbol_detail_news_page_controller.dart';

class SymbolDetailNewsPage extends GetView<SymbolDetailNewsPageController> {

  const SymbolDetailNewsPage({super.key});

  @override
  Widget build(BuildContext context) {

    return SingleChildScrollView(
      key: const PageStorageKey<String>('Tab2'),
      physics: const ClampingScrollPhysics(),
      controller: controller.scrollController,       //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! this paiging 
      child: Column( 
        children: [
          Container(
            height: 400,
            color: Colors.blue,
          ),
          Container(
            height: 400,
            color: Colors.red,
          ),
        ],
      ),
    );
  }
}

Try do it

TT

zmtzawqlp commented 5 months ago

please check https://github.com/fluttercandies/extended_nested_scroll_view/blob/acf0f8201a169663ae8e809f134a939e08a6b752/lib/src/extended_nested_scroll_view.dart#L514

LEEKIWAN commented 5 months ago
class SymbolDetailPage extends GetView<SymbolDetailPageController> {

  final GlobalKey<ExtendedNestedScrollViewState> _nestedScrollViewState = GlobalKey<ExtendedNestedScrollViewState>();  //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  final double tabBarHeight = 40;

  SymbolDetailPage({super.key});

  @override
  Widget build(BuildContext context) {
    context.theme;
    return Scaffold(
      body: SafeArea(
        child: Column(
          children: [
            Obx(() => SymbolDetailNavigationBar(
                symbolDetail: controller.symbolDetail.value, naviBottomScrollController: controller.naviBottomScrollController, naviTopScrollController: controller.naviTopScrollController)),
            Expanded(
              child: ExtendedNestedScrollView(
                key: _nestedScrollViewState,                   // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                headerSliverBuilder: (BuildContext c, bool f) {
                  return [

other class Using It


    final GlobalKey<ExtendedNestedScrollViewState> _nestedScrollViewState = GlobalKey<ExtendedNestedScrollViewState>();

    print('sdfsfdsdsfsdsdf');
    print(_nestedScrollViewState);

    _nestedScrollViewState.currentState!.innerController.addListener(() {
      print('sdsdfdsdf');
    });

    _nestedScrollViewState.currentState!.outerController.addListener(() {
      print('sdsdfdsdf');
    });

    print(_nestedScrollViewState.currentContext);
    print(_nestedScrollViewState.currentWidget);
    print(_nestedScrollViewState);

i'm a newbie so it doesn't work out well. It seems to be used as a global key, but it is difficult to apply from the description alone. Are there any sample examples?

zmtzawqlp commented 5 months ago

https://github.com/fluttercandies/extended_nested_scroll_view/blob/acf0f8201a169663ae8e809f134a939e08a6b752/example/lib/pages/complex/scroll_to_top.dart#L47

make sure you are using it at right moment.

LEEKIWAN commented 5 months ago

thanks~! shie shie

i can do