robert-luoqing / flutter_list_view

MIT License
47 stars 17 forks source link

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

Closed Iridescentangle closed 1 year ago

Iridescentangle commented 1 year ago

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 commented 1 year ago

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

robert-luoqing commented 1 year ago

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

Iridescentangle commented 1 year ago

https://user-images.githubusercontent.com/33859295/205048220-5b958f8d-cc55-4a79-87f2-e2766471db39.mp4

@robert-luoqing

Iridescentangle commented 1 year ago

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

robert-luoqing commented 1 year ago

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

Iridescentangle commented 1 year ago

@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👍🏻