Flutter : ListView : Scroll parent ListView when child ListView reach bottom - ClampingScrollPhysics not working in sized container

后端 未结 3 1674
醉酒成梦
醉酒成梦 2021-01-03 11:54

I\'m using Flutter version 1.12.13+hotfix.

I\'m looking for a solution to be able to scroll inside a ListView and when reached the bottom, automatically give scroll

3条回答
  •  长发绾君心
    2021-01-03 12:32

    A tricky way could be using NotificationListener. Put a Overscroll Notification Listener over your child scroll widget then ignore the pointer in case of overscroll. To let the child widget to scroll again in opposite direction, you have to set ignoring false after a short time. A detailed code sample:

    class _MyHomePageState extends State {
    
      var _scrollParent = false;
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Container(
            color: Colors.yellow,
            child: ListView.builder(
              itemBuilder: (c, i) => i == 10
                  ? Container(
                      height: 150,
                      color: Colors.red,
                      child: IgnorePointer(
                        ignoring: _scrollParent,
                        child: NotificationListener(
                          onNotification: (_) {
    
                            setState(() {
                              _scrollParent = true;
                            });
    
                            Timer(Duration(seconds: 1), () {
                              setState(() {
                                _scrollParent = false;
                              });
                            });
    
                            return false;
                          },
                          child: ListView.builder(
                            itemBuilder: (c, ii) => Text('-->' + ii.toString()),
                            itemCount: 100,
                          ),
                        ),
                      ),
                    )
                  : Text(i.toString()),
              itemCount: 100,
            ),
          ),
        );
      }
    }
    

    There would be some flaws like double scrolling requirement by user to activate parent scroll event (first one will ignore the pointer), or using timer to disable ignoring that leads to misbehavior in fast scrolling actions. But the implementation simplicity towards other solutions would be immense.

提交回复
热议问题