Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unepected item reveal while calling jump or animate to specific item #73

Open
dhyash-simform opened this issue Nov 14, 2024 · 0 comments

Comments

@dhyash-simform
Copy link

Steps to reproduce:

  • Use SuperListView.separated
  • Call jumpToItem or animateToItem function

Expected results:

  • Should jump to a particular item based on the index of the item builder

Actual results:

  • Jumps on the item considering item builder + separator builder index

More Information:

  • if I want to navigate on the specific item of the item builder I will have to pass index * 2 to reveal it. For example, if I want to jump to 2nd item of my data list, then I would need to pass 4 as index instead of 2 due to the addition/consideration of separators in between.

Code Sample:


import 'package:flutter/material.dart';
import 'package:super_sliver_list/super_sliver_list.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  static const dummyText =
      """Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc gravida eros eu massa porttitor maximus. Donec vestibulum iaculis justo, a convallis purus pharetra vel. Aliquam finibus ex vitae quam molestie, sit amet suscipit dui blandit. Vivamus mattis vitae lectus quis tristique. Suspendisse et consectetur tortor. Duis accumsan ut massa quis iaculis. Aliquam vestibulum, tellus in accumsan congue, sem lacus lobortis augue, sed venenatis risus enim et arcu. Sed non rhoncus felis.
  Phasellus id pretium turpis. Donec et pellentesque urna, mattis facilisis turpis. Nullam sit amet suscipit tortor. Sed ut elit neque. Cras euismod euismod arcu lacinia commodo. In id enim non justo blandit consequat. Nullam quis mattis orci, vitae vulputate sem. Nam interdum lectus ac lorem rutrum, in tristique lectus pellentesque.
  """;

  final listController = ListController();
  final scrollController = ScrollController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: const Text('Super Sliver List Demo'),
      ),
      body: SuperListView.separated(
        itemCount: 100,
        controller: scrollController,
        listController: listController,
        itemBuilder: (_, index) => RichText(
          text: TextSpan(
            text: '$index \n',
            children: const [
              TextSpan(
                text: dummyText,
                style: TextStyle(
                  fontSize: 12,
                  fontWeight: FontWeight.normal,
                  color: Colors.black,
                ),
              ),
            ],
            style: const TextStyle(
              fontSize: 16,
              color: Colors.black,
              fontWeight: FontWeight.bold,
            ),
          ),
        ),
        separatorBuilder: (_, __) => const Divider(),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () => listController.jumpToItem(
          index: 50,
          scrollController: scrollController,
          alignment: 0.5,
        ),
        child: const Icon(Icons.arrow_downward),
      ),
    );
  }
}


Screenshots or Video:

Simulator.Screen.Recording.-.iPhone.15.-.2024-11-14.at.15.21.50.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant