TerminalStudio / flutter_split_view

Navigator 2.0 based Flutter widget that automatically splits the screen into two views based on available space.
https://pub.dev/packages/flutter_split_view
MIT License
18 stars 5 forks source link

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

Open mfrischbutter opened 1 year ago

mfrischbutter commented 1 year ago

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 commented 1 year ago

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'),
              );
            }),
          ),
        ),
      ),
    );
  }
}