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上 左滑返回有几率会出发两次 #183

Closed
WHAYL opened this issue Apr 7, 2024 · 1 comment
Closed

visibility_detector 在iOS上 左滑返回有几率会出发两次 #183

WHAYL opened this issue Apr 7, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@WHAYL
Copy link

WHAYL commented Apr 7, 2024

版本信息

  • Flutter版本:[举例:v3.19.2]
  • flutter_smart_dialog版本:[举例:v4.9.6]
  • visibility_detector: ^0.4.0+2

描述bug/需求

onVisibilityChanged 在iOS上 左滑返回有几率会出发两次
VisibilityDetector(
key: Key("reca"),
onVisibilityChanged: (VisibilityInfo visibilityInfo) {
var visiblePercentage =
visibilityInfo.visibleFraction * 100;
if (visiblePercentage == 100.0) {
print("首页首页"); ///在iOS上 左滑返回有几率会出发两次
}
},
child:***)

问题demo

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

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

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
      builder: FlutterSmartDialog.init(), //这里注释掉就不会有问题
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    Navigator.push(
      context,
      MaterialPageRoute(builder: (context) => Page1()),
    );
  }

  @override
  Widget build(BuildContext context) {
    print("rebuild");
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // TRY THIS: Try changing the color here to a specific color (to
        // Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
        // change color while the other colors stay the same.
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Container(
        child: Column(
          children: [
            Expanded(
              child: VisibilityDetector(
                key: Key("rec"),
                onVisibilityChanged: (VisibilityInfo visibilityInfo) {
                  var visiblePercentage = visibilityInfo.visibleFraction * 100;
                  if (visiblePercentage == 100.0) {
                    print("推荐页面111");
                  }
                },
                child: PageView(
                  physics: NeverScrollableScrollPhysics(),
                  children: <Widget>[
                    VisibilityDetector(
                      key: Key("reca"),
                      onVisibilityChanged: (VisibilityInfo visibilityInfo) {
                        var visiblePercentage =
                            visibilityInfo.visibleFraction * 100;
                        if (visiblePercentage == 100.0) {
                          print("首页首页");
                        }
                      },
                      child: Container(
                        width: 300,
                        // color: Colors.red,
                        child: Column(
                          children: [
                            const Text(
                              'You have pushed the button this many times:',
                            ),
                            InkWell(
                              onTap: () {
                                _incrementCounter();
                              },
                              child: Text("dfdfd"),
                            )
                          ],
                        ),
                      ),
                    ),
                    Text(
                      '$_counter',
                      style: Theme.of(context).textTheme.headlineMedium,
                    ),
                  ],
                ),
              ),
            ),
            Container(width: 200, height: 40, color: Colors.red)
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

class Page1 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return PageView(
      children: [
        Center(
          child: Text(
            "page1",
            style: TextStyle(color: Colors.red),
          ),
        )
      ],
    );
  }
}
@xdd666t
Copy link
Member

xdd666t commented May 19, 2024

  • 这个问题解决了,试下新版本吧
dependencies:
  flutter_smart_dialog: ^4.9.7+2

@xdd666t xdd666t added the bug Something isn't working label May 20, 2024
@xdd666t xdd666t self-assigned this May 20, 2024
@xdd666t xdd666t closed this as completed May 22, 2024
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