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

onPoppedInvoked not working when swiping back #964

Open
GeorgeZoiade opened this issue Aug 5, 2024 · 2 comments
Open

onPoppedInvoked not working when swiping back #964

GeorgeZoiade opened this issue Aug 5, 2024 · 2 comments
Labels
new New issue request attention question Questions about using some feature or general working of the package

Comments

@GeorgeZoiade
Copy link

GeorgeZoiade commented Aug 5, 2024

When using the modular package and pushing to a new route, when swiping back to previous screen, the screen is wrapped in a PopScope widget, but the onPopInvoked method is not working.

Expected behavior
When swiping back, onPopInvoked should handle the callback.

This is my code:

void main() {
  runApp(
    ModularApp(module: AppModule(), child: const MyApp()),
  );
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      routerConfig: Modular.routerConfig,
    );
  }
}

class AppModule extends Module {
  @override
  void binds(i) {}

  @override
  void routes(r) {
    r.child('/', child: (context) => const HomeScreen());
    r.child('/swipe', child: (context) => const SwipeScreen());
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Home'),
      ),
      body: GestureDetector(
        onTap: () => Modular.to.pushNamed('/swipe'),
        child: const Center(
          child: Text('Home'),
        ),
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return PopScope(
      onPopInvoked: (didPop) {
        if (didPop) {
          print('should handle some callback after popping the route');
        }
      },
      child: Scaffold(
        appBar: AppBar(
          title: const Text('Swipe'),
        ),
        body: const Center(
          child: Text('Swipe'),
        ),
      ),
    );
  }
}
@GeorgeZoiade GeorgeZoiade added new New issue request attention question Questions about using some feature or general working of the package labels Aug 5, 2024
@edugemini
Copy link
Contributor

Flutter Web???

@ramon-bernardo
Copy link

ramon-bernardo commented Sep 10, 2024

I attempted to reproduce the issue on the latest versions of Flutter and f_modular but couldn't replicate it. It's worth noting that onPopInvoked has been replaced by onPopInvokedWithResult.

I navigated to the home screen and after click, moved to the swipe screen. When I click on back button, I received the following message in the console: 'should handle some callback after popping the route'.

image

Flutter 3.24.2 (stable)
Dart SDK 3.5.2
Flutter modular 6.3.4 (and current master)

// deprecated
onPopInvoked: (didPop) {
  if (didPop) {
    print('should handle some callback after popping the route');
  }
}

// new
onPopInvokedWithResult: (didPop, result) {
  if (didPop) {
    print('should handle some callback after popping the route');
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new New issue request attention question Questions about using some feature or general working of the package
Projects
None yet
Development

No branches or pull requests

3 participants