flutterdartwidgetscrollableflutter-sliver

How to make flutter page scrollable using slivers


I am trying to implement a sliver in CustScrollView, below is my code

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        slivers: [
          SliverAppBar(
            floating: true,
            snap: true,
            expandedHeight: 300,
            flexibleSpace: FlexibleSpaceBar(
              background: Image.asset(
                "assets/images/food6.jpg",
                width: double.maxFinite,
                fit: BoxFit.cover,
              ),
            ),
          ),
          const SliverToBoxAdapter(
            child: Text("Chinese fruit food details. Chinese fruit food details Chinese fruit food details Chinese fruit food details Chinese fruit food details "),
          ),
        ],
      ),
    );
  }

the issue is that the page is not scrollable. I have tried to detect where my mistake is coming from but I couldn't.


Solution

  • Make the text in the Text() widget under SliverToBoxAdapter() longer than the screen size, scroll will automatically be applied.