4

I want to create Horizontal V shaped List View just like in the following image , it will scroll from right to left and top to bottom. The labels are index of each container that will be inside it. List will contain a text widget displaying the index. List will detect users scroll up or down gesture and then move the list accordingly. When scrolled down , Label 1 will move to 2nd index that is in place of Label 2 and label 6 will move to index 0 that is place of Label 1 forming a loop.

enter image description here

I used chat GPT but the best code it has given me is this : -

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('V-Shaped ListView'),
        ),
        body: Center(
          child: ClipPath(
            clipper: VShapeClipper(),
            child: Container(
              color: Colors.blueAccent,
              width: 300,  // Width of the V-shape
              height: 500, // Height of the V-shape
              child: ListView.builder(
                itemCount: 20,
                itemBuilder: (context, index) {
                  return Card(
                    margin: EdgeInsets.all(8.0),
                    child: ListTile(
                      title: Text('Item $index'),
                    ),
                  );
                },
              ),
            ),
          ),
        ),
      ),
    );
  }
}

class VShapeClipper extends CustomClipper<Path> {
  @override
  Path getClip(Size size) {
    Path path = Path();
    
    // Start at the top left
    path.moveTo(0, 0);
    
    // Draw the left side of the V
    path.lineTo(size.width / 2, size.height);
    
    // Draw the right side of the V
    path.lineTo(size.width, 0);
    
    // Close the path (back to the start)
    path.close();
    
    return path;
  }

  @override
  bool shouldReclip(CustomClipper<Path> oldClipper) {
    return false;
  }
}

but it is not even close to what I want

2
  • Can you explain more about the behavior you want, what will be inside the list and how exactly should it be scrolled? give as much clear behavior as you can please. Commented Sep 11, 2024 at 16:14
  • @MHMD , I have updated my question which includes more details for scrolling behavior . Commented Sep 11, 2024 at 16:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.