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

Multiple calls to ExprollablePageController.animateViewportOffsetTo during the animation can cause it to become stuck. #25

Closed
khoadng opened this issue May 4, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@khoadng
Copy link
Contributor

khoadng commented May 4, 2023

Video:

Screen.Recording.2023-05-04.at.22.40.56.mov
import 'package:example/src/common.dart';
import 'package:exprollable_page_view/exprollable_page_view.dart';
import 'package:flutter/material.dart';

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

  @override
  State<SimpleExample> createState() => _SimpleExampleState();
}

class _SimpleExampleState extends State<SimpleExample> {
  late final controller = ExprollablePageController(
    initialPage: 0,
    maxViewportOffset: ViewportOffset.shrunk,
    minViewportFraction: 0.8,
    snapViewportOffsets: [
      ViewportOffset.expanded,
      ViewportOffset.shrunk,
    ],
  );
  var expanded = false;
  var title = "";

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(title),
        actions: [
          if (expanded)
            IconButton(
                onPressed: () {
                  setState(() {
                    title = "animate to shrunk";
                  });
                  controller.animateViewportOffsetTo(ViewportOffset.shrunk,
                      curve: Curves.easeOut,
                      duration: Duration(milliseconds: 150));
                },
                icon: Icon(Icons.keyboard_double_arrow_up))
          else
            IconButton(
                onPressed: () {
                  setState(() {
                    title = "animate to expanded";
                  });
                  controller.animateViewportOffsetTo(ViewportOffset.expanded,
                      curve: Curves.easeOut,
                      duration: Duration(milliseconds: 150));
                },
                icon: Icon(Icons.keyboard_double_arrow_down))
        ],
      ),
      bottomNavigationBar: const ExampleBottomAppBar(),
      body: ExprollablePageView(
        onViewportChanged: (metrics) => setState(() {
          expanded = metrics.isExpanded;
        }),
        controller: controller,
        itemCount: 5,
        itemBuilder: (context, page) {
          return ExampleListView(
            controller: PageContentScrollController.of(context),
            page: page,
          );
        },
      ),
    );
  }
}
@fujidaiti
Copy link
Owner

Seems like a bug related to floating point precision. I'll work on it.

@fujidaiti fujidaiti self-assigned this May 5, 2023
@fujidaiti fujidaiti added the bug Something isn't working label May 5, 2023
This was referenced May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants