Home > Software design >  Remove Widget when NestedScrollView reach end of screen
Remove Widget when NestedScrollView reach end of screen

Time:09-11

Hi I'm new to flutter and I tried to use NestedScrollView Widget to show my widget. I've managed to create the NestedScrollView widget and I wanted to remove my bottom sheet when the scrollView already reach the end of the screen. Is there any way that I can achieve it ? Thanks Before

Here's my code:

NestedScrollView(
    headerSliverBuilder: (context, isScrolled) {
      return [
        SliverPersistentHeader(
          pinned: true,
          floating: false,
          delegate: ChooseUsersHeaderDelegate(
            widgetList: Container(
              color: Colors.white,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  /// Search Box
                  buildSearch(),
                ],
              ),
            ),
            minHeight: selectedContactId.isNotEmpty ? 135 : 60,
            maxHeight: selectedContactId.isNotEmpty ? 135 : 60,
            parentContext: context,
          ),
        ),
      ];
    },
    body: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Column(
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
        Text(
          'allContacts',
          style: GoogleFonts.montserrat(
            fontSize: 14,
            fontWeight: FontWeight.w500,
            color: primaryColor,
            fontStyle: FontStyle.normal,
          ),
        ).tr(),

        Column(
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            isLoading
                ? ReusableLoadingContact()
                : NotificationListener<
                        OverscrollIndicatorNotification>(
                    onNotification: (overScroll) {
                      overScroll.disallowIndicator();
                      return true;
                    },
                    child: buildWidget(context, 'contacts')),
          ],
        ),
      ],
    ),
  ),

bottomSheet: Container(
        height: 40,
        width: double.infinity,
        decoration: BoxDecoration(
          gradient: LinearGradient(
            begin: Alignment.topCenter,
            end: FractionalOffset.bottomCenter,
            colors: <Color>[
              Colors.white.withOpacity(0.1),
              Colors.white,
            ],
            stops: [0, 1],
          ),
        ),
      ),

CodePudding user response:

Change your StatelessWidget into StatefulWidget you need to make result

instead of ternary operators you can use Visibility too

CodePudding user response:

you want yo use nested scrolls!

first wrap you Scaffold body to singleChildScrollView widget after than add ListView() Or ListView.Builder()

like:-

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

@override
State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

 @override
 Widget build(BuildContext context) {
  return Scaffold(
  
  body: SingleChildScrollView(
    child: Column(children: [
      Text("Hello World"),
      ListView(
        shrinkWrap: true,
        physics: NeverScrollableScrollPhysics(),
      ),
    ]),
  ),
 
   );
 }
}
  • Related