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

[visibility_detector] iOS swipe back - Unexpected visibleFraction behaviour. It is just 1.0 or 0.0. #534

Open
HappyMakadiyaS opened this issue Jun 3, 2024 · 2 comments

Comments

@HappyMakadiyaS
Copy link

Problem description

Steps to reproduce

  1. Push new screen having Visibility Detector.
  2. on onVisibilityChanged print value of visibleFraction
  3. Using swipe Back gesture in iOS observe the printted value.

Expected behavior

While doing Swipe Back Gesture - Should get fraction values e.g. 0.74342, 0. 89294, etc

Actual behavior

But Getting just 1.0 or 0.0 in any state of visibility.

Environment

Device: iOS 17.4.1
Flutter Version: Flutter 3.22.1 • channel stable

Additional details

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.22.1, on macOS 14.4.1 23E224 darwin-arm64, locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
[✓] Android Studio (version 2023.2)
[✓] VS Code (version 1.89.1)
[✓] Connected device (2 available)
[✓] Network resources

• No issues found!

Code Snippest

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

void main() {
  runApp(MaterialApp(
    title: 'Flutter Demo',
    theme: ThemeData(
      colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      useMaterial3: true,
    ),
    home: const MyHomePage(),
  ));
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Visibility Detector"),
      ),
      body: Center(
        child: GestureDetector(
          onTap: () {
            Navigator.of(context).push(MaterialPageRoute(builder: (_) {
              return Scaffold(
                backgroundColor: Colors.grey,
                body: Center(
                  child: SizedBox(
                    height: 300,
                    child: PageView(
                      children: [
                        VisibilityDetector(
                          onVisibilityChanged: (info) {
                            print(info.visibleFraction);
                          },
                          key: const ValueKey("value"),
                          child: const ColoredBox(
                            color: Colors.yellow,
                            child: Text('Page 1'),
                          ),
                        ),
                        const ColoredBox(
                          color: Colors.red,
                          child: Text('Page 2'),
                        ),
                        const ColoredBox(
                          color: Colors.blue,
                          child: Text('Page 3'),
                        ),
                      ],
                    ),
                  ),
                ),
              );
            }));
          },
          child: const Text(
            'Push to Next Screen',
          ),
        ),
      ),
    );
  }
}

screen-recording-2024-06-03-at-70901-pm_5kd4253u.mp4
@HappyMakadiyaS HappyMakadiyaS changed the title [visibility_detector] iOS swipe back - Unexpected visibleFraction is just 1.0 or 0.0. [visibility_detector] iOS swipe back - Unexpected visibleFraction behaviour. It is just 1.0 or 0.0. Jun 3, 2024
@BetaPundit
Copy link

Facing the same issue. Did you find any fix/workaround @HappyMakadiyaS?

@HappyMakadiyaS
Copy link
Author

@BetaPundit For now this version worked for me
visibility_detector: 0.3.3

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

2 participants