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

[BUG] PhotoViewCore throws when changing pages while zoomed in #217

Closed
ghost opened this issue Nov 25, 2019 · 5 comments · Fixed by #254
Closed

[BUG] PhotoViewCore throws when changing pages while zoomed in #217

ghost opened this issue Nov 25, 2019 · 5 comments · Fixed by #254
Labels
bug Something isn't working Gallery P1

Comments

@ghost
Copy link

ghost commented Nov 25, 2019

If you create a PhotoViewGallery and pass a PhotoViewScaleStateController in the PhotoViewGalleryPageOptions defined at the builder, the error The method 'toDouble' was called on null is thrown by PhotoViewCore when changing pages while zoomed in.

You can reproduce this issue by running the code below, zooming in and changing to the second page without zooming out:

import 'package:flutter/material.dart';
import 'package:photo_view/photo_view.dart';
import 'package:photo_view/photo_view_gallery.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(body: Foo()),
    );
  }
}

class Foo extends StatefulWidget {
  @override
  _FooState createState() => _FooState();
}

class _FooState extends State<Foo> {
  static const images = <String>[
    'https://homepages.cae.wisc.edu/~ece533/images/peppers.png',
    'https://homepages.cae.wisc.edu/~ece533/images/baboon.png',
    'https://homepages.cae.wisc.edu/~ece533/images/girl.png',
  ];

  PhotoViewScaleStateController scaleStateController;

  @override
  void initState() {
    super.initState();
    scaleStateController = PhotoViewScaleStateController();
  }

  @override
  void dispose() {
    scaleStateController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return PhotoViewGallery.builder(
      itemCount: images.length,
      builder: (context, index) => PhotoViewGalleryPageOptions(
        imageProvider: NetworkImage(images[index]),
        scaleStateController: scaleStateController,
      ),
    );
  }
}

Not passing scaleStateController makes the issue disappear, so it's definitely related.

Flutter details:

• Flutter version 1.9.1+hotfix.5 at C:\flutter
• Framework revision 1aedbb1835 (6 weeks ago), 2019-10-17 08:37:27 -0700
• Engine revision b863200c37
• Dart version 2.5.0

I believe this is related to the release 0.8.0.

@ghost ghost added the bug Something isn't working label Nov 25, 2019
@renancaraujo
Copy link
Member

This only happens when a scaleStateController with a value different than initial is passed to a brand new PhotoView (every time user changes a page in the gallery, a new PhotoView is created). Fix should arrive on 0.9.1.

@ghost
Copy link
Author

ghost commented Nov 28, 2019

Got it. I believe that PhotoViewScaleState should be reset to initial when changing the page. Previously, it was only possible to change the page when the state was initial? This would explain why no concerns were given to this matter.

@renancaraujo
Copy link
Member

I believe that PhotoViewScaleState should be reset to initial when changing the page.

Two things that make that impossible:

  • We can have at some times two (or more) pages (instances of PhotoView) ate the screen. By the time the page has fully changed, the widget had been instantiated already.
  • We are passing controllers to page options, in theory, the gallery doesn't know the existence of the controller.

Anyway, throwing is never an option, this must be fixed.

A drastic solution is to make the gallery receive the controllers, not pages. But with this approach, package user will not be able to eventually pass different controllers to different pages.

@ghost
Copy link
Author

ghost commented Nov 28, 2019

A drastic solution is to make the gallery receive the controllers, not pages. But with this approach, package user will not be able to eventually pass different controllers to different pages.

Generally, a single controller for each feature is held by the state. From my point of view, to pass a different controller to different pages, the user must have lots of scale-state-controllers in the same state, which is unusual.

Can you think on a practical usage of such feature?

@renancaraujo
Copy link
Member

I can't picture a use case right now but having and application where there are a known amount of pages and the user has different (but exposed) states for each page doesnt sound like something impossible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Gallery P1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant