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] Android back button not affecting the SplitView #4

Open
mfrischbutter opened this issue Jul 20, 2023 · 1 comment
Open

[BUG] Android back button not affecting the SplitView #4

mfrischbutter opened this issue Jul 20, 2023 · 1 comment

Comments

@mfrischbutter
Copy link

Issue

Currently if you are pressing the android back button, the action does not pop the context of the SplitView, it would try to pop the context of the Navigator.

Expected Result

If you are currently inside one View after using SplitView.push(), you are pressing the back button, i would expect SplitView.pop() would be called, instead of Navigator.pop().

Hotfix

I already tried to fix it somehow with a WillPopScope, but somehow i am not able to but it inside the child or placeholder of the SplitView Widget. It does not get called. Only if the SplitView is the child, it would be get called, but i dont have the context of the SplitView in this case and can't pop the SplitView.

Solution

Add a controller to be able to control the SplitView outside of context, or try to fix the WillPopScope, so it would automatically choose the right action.

@mfrischbutter
Copy link
Author

Example Code:

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(),
      home: Scaffold(
        body: SafeArea(
          child: SplitView.material(
            breakpoint: 900,
            placeholder: const Text('Placeholder'),
            child: Builder(builder: (context) {
              return ElevatedButton(
                onPressed: () {
                  SplitView.of(context).push(
                    WillPopScope(
                      onWillPop: () async {
                        SplitView.of(context).pop();
                        return false;
                      },
                      child: const Center(
                        child: Text('Next Page'),
                      ),
                    ),
                  );
                },
                child: const Text('Next Page'),
              );
            }),
          ),
        ),
      ),
    );
  }
}

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

1 participant