robert-luoqing/flutter_list_view

Got incorrect position using renderObject when list is reversed and firstItemAlign is end

Closed this issue · 6 comments

Only occurs when items are not enough to fill the screen
It's easy to reproduce

Scaffold(
      body: FlutterListView(
        reverse: true,//
        delegate: FlutterListViewDelegate(
        (BuildContext context, int index) {
      return Container(
        margin: EdgeInsets.symmetric(horizontal: 20, vertical: 5),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(8),
          color: Color(0xFF333333),
        ),
        height: 100,
        child: Builder(
          builder: (BuildContext context) {
            return GestureDetector(
              onTap: () {
                try{
                  var box = context.findRenderObject() as RenderBox;
                  final Offset offset = box.localToGlobal(Offset.zero);
                  var size = box.size;
                  Get.to(Material(
                    color: Colors.transparent,
                    child: Stack(
                      children: [
                        Positioned(
                          left: offset.dx,
                          top: offset.dy,
                          child: Container(
                            color: Colors.yellow,
                            width: size.width,
                            height: size.height,
                          ),
                        )
                      ],
                    ),
                  ));
                }catch(e){
                  print(e);
                }
              },
            );
          },
        ),
      );},
          childCount: 5,
          firstItemAlign: FirstItemAlign.end, //for sure the list is aligning top
        ),
      ),
    );

Thanks report the issues. I'm going to check it and fix it ASAP

Hi @Iridescentangle
I'm tested in my computer. It work fine. Could you please share your screenshot to me to identify what issue you got.

image

screen-20221201-200229.mp4

@robert-luoqing

Only occurs when items are not enough to fill the screen It's easy to reproduce

Scaffold(
      body: FlutterListView(
        reverse: true,//
        delegate: FlutterListViewDelegate(
        (BuildContext context, int index) {
      return Container(
        margin: EdgeInsets.symmetric(horizontal: 20, vertical: 5),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(8),
          color: Color(0xFF333333),
        ),
        height: 100,
        child: Builder(
          builder: (BuildContext context) {
            return GestureDetector(
              onTap: () {
                try{
                  var box = context.findRenderObject() as RenderBox;
                  final Offset offset = box.localToGlobal(Offset.zero);
                  var size = box.size;
                  Get.to(Material(
                    color: Colors.transparent,
                    child: Stack(
                      children: [
                        Positioned(
                          left: offset.dx,
                          top: offset.dy,
                          child: Container(
                            color: Colors.yellow,
                            width: size.width,
                            height: size.height,
                          ),
                        )
                      ],
                    ),
                  ));
                }catch(e){
                  print(e);
                }
              },
            );
          },
        ),
      );},
          childCount: 5,
          firstItemAlign: FirstItemAlign.end, //for sure the list is aligning top
        ),
      ),
    );

@robert-luoqing Once you tap an item in the list, its position will be calculated by using its context,so the yellow container in the new page indicates the position of the item you tapped.You can find out it's just like the opposite of the original list before reversed

@Iridescentangle Thanks, I have fixed the issue. The version is 1.1.20.

@Iridescentangle Thanks, I have fixed the issue. The version is 1.1.20.

Thanks a lot for your help!I validated the new version and it's perfect👍🏻