Flutter: Stepper is not scrolling when added inside ListView

后端 未结 2 1500
轻奢々
轻奢々 2021-01-05 19:19

I have ListView which contains - 1. Banner Image 2. Container with some Text 3. Container with Some more Text 4. Container consist of Stepper.

I\'m unable to scrol

相关标签:
2条回答
  • 2021-01-05 19:43

    Found the solution. Stepper is already scroll-able widget, And as i was adding Stepper inside ListView it was becoming Scrollable widget inside another Scrollable widget.

    @FunMiles from Gitter suggested to use NestedScrollView widget instead of ListView & that solved my prob.

    class TestAppHomePage extends StatefulWidget {
      @override
      TestAppHomePageState createState() => new TestAppHomePageState();
    }
    
    class TestAppHomePageState extends State<TestAppHomePage>
        with TickerProviderStateMixin {
      ScrollController _scrollController = new ScrollController();
    
      @override
      Widget build(BuildContext context) {
        return new Scaffold(
          appBar: new AppBar(
            title: new Text('Test Title'),
            elevation: 0.0,
          ),
          body: new NestedScrollView(
            controller: _scrollController,
            headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
              return <Widget>[
                new SliverList(
                  delegate:new SliverChildListDelegate(<Widget>[
                        new MyContents(),
                        new MyContents(),
                        new MyContents(),
                        new MyContents(),
                  ]),
                ),
              ];
            },
            body: new SimpleWidget(),
          ),
        );
      }
    }
    
    0 讨论(0)
  • 2021-01-05 19:49

    If the stepper is contained within another scrollable, you can set stepper physics to ClampingScrollPhysics

    Stepper(physics: ClampingScrollPhysics(), //remaing stepper code
    

    in your case you are using listview which is scrollable, by setting stepper physics to ClampingScrollPhysics() the parent widget (listview) will have the controller of stepper scroll

    Edit: as @asubanovsky stated in the comment, you can use NeverScrollableScrollPhysics() as well to be more precise for removing the scroll behavior of the current widget and let the parent widget handle it

    0 讨论(0)
提交回复
热议问题