slovnicki / beamer

A routing package built on top of Router and Navigator's pages API, supporting arbitrary nested navigation, guards and more.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Navigation history does not clear even after popping the page

jeslinjacob1995 opened this issue · comments

Describe the bug
Navigation history does not clear even after popping the page . If I pop from one page it will navigate correctly , but if i press browser back button it will take me to same page which i already popped

Beamer version: (e.g. v0.14.1, master, ...)
beamer: ^1.5.6

To Reproduce
Steps to reproduce the behavior:

import 'package:beamer/beamer.dart';
import 'package:example_beamer/home_location.dart';
import 'package:flutter/material.dart';

import 'account_listing_page.dart';
import 'home_page.dart';

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

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

  final routerDelegate = BeamerDelegate(
    initialPath: '/home',
    locationBuilder: RoutesLocationBuilder(
      routes: {
        '*' : (context, state, data) => const HomePage(),
        // '/account' : (context, state, data) => const AccountListingPage(),
    },
    ),
  );

  @override
  Widget build(BuildContext context) {
    return  WillPopScope(
      onWillPop: () async{
        return false;
      },
      child: MaterialApp.router(
        debugShowCheckedModeBanner: false,
        routerDelegate: routerDelegate,
        routeInformationParser: BeamerParser(),
        theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
        ),
      ),
    );
  }
}
import 'package:beamer/beamer.dart';
import 'package:example_beamer/account_locations.dart';
import 'package:flutter/material.dart';

import 'account_details.dart';
import 'account_listing_page.dart';


class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {

  int selectedIndex = 0;
  final key = GlobalKey<BeamerState>();

  final routeDelegates = [
      BeamerDelegate(
          // initialPath: 'account',
          locationBuilder: (routeInfo,_){
          return AccountLocations(routeInfo);
      },


      ),
      BeamerDelegate(locationBuilder: (routeInfo,_){
        return AccountLocations(routeInfo);
      })
  ];



  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Container(
              width: 500,
              height: MediaQuery.of(context).size.height,
              color: Colors.blue,
              child: Column(
                children: [
                  ListTile(
                    title: const Text("Accounts",),
                    onTap: (){
                      setState(() {
                        selectedIndex = 0;
                      });
                    },
                    selected: selectedIndex == 0,
                  ),
                  ListTile(
                    title: const Text("Profile"),
                    onTap: (){
                      setState(() {
                        selectedIndex = 1;
                      });
                    },
                    selected: selectedIndex == 1,
                  ),
                ],
              ),
            ),
            Expanded(child: Container(
              color: Colors.white,
              child: Beamer(
                key: key,
                backButtonDispatcher: BeamerBackButtonDispatcher(
                  delegate: routeDelegates[0],
                  fallbackToBeamBack: false,
                ),
                routerDelegate: routeDelegates[0],
              ),
            ))

          ],
        ),
      ),
    );
  }
}
import 'package:beamer/beamer.dart';
import 'package:example_beamer/account_details.dart';
import 'package:example_beamer/account_listing_page.dart';
import 'package:flutter/material.dart';

class AccountLocations extends BeamLocation<BeamState>{

  AccountLocations(RouteInformation routerInformation) : super(routerInformation);

  @override
  List<BeamPage> buildPages(BuildContext context, BeamState state) => [
    const BeamPage(
      key: ValueKey('/account'),
      title: 'Account Listing',
      type: BeamPageType.noTransition,
      child: AccountListingPage(),
    ),
    if(state.uri.path.contains('/details'))
    const BeamPage(
      key: ValueKey('/details'),
      title: 'Account Details',
      type: BeamPageType.noTransition,
      child: AccountDetails(),
    ),
    if(state.uri.path.contains('/statement'))
    const BeamPage(
      key: ValueKey('/statement'),
      title: 'Account Statement',
      type: BeamPageType.noTransition,
      child: AccountStatement(),
    ),
  ];

  @override
  List<Pattern> get pathPatterns => ["/account"];

}

from account statement page if i call Navigator.of(context).maybePop(); it pops to correct page , but again if i press on browser back button it will take me to account statement page

Expected behavior
I am expecting that i should not go to the page which it already popped

I am running the code from flutter web with chrome browser