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

Losing page state when navigating to another #577

Open
GlaucoMendes opened this issue Oct 18, 2022 · 0 comments
Open

Losing page state when navigating to another #577

GlaucoMendes opened this issue Oct 18, 2022 · 0 comments

Comments

@GlaucoMendes
Copy link

Description
When navigating from page 1 to page 2, everything goes perfectly.
When navigating from page 2 to page 3, everything goes perfectly.

When going back from page 3 to page 2, page 2 loses state, no transition occurs.

The only solution I found was to use the '/page2/page3/' route instead of '/page3'. But it is not a good solution for my case.

Minimum reproduction:

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

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

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

  final routerDelegate = BeamerDelegate(
    locationBuilder: RoutesLocationBuilder(
      routes: {
        '/': (context, state, data) {
          return const BeamPage(
            key: ValueKey('page1-key'),
            child: Page1(),
          );
        },
        '/page2': (context, state, data) {
          return const BeamPage(
            key: ValueKey('page2-key'),
            child: Material(
              child: Page2(),
            ),
          );
        },
        '/page3': (context, state, data) {
          return const BeamPage(
            key: ValueKey('page3-key'),
            child: Material(
              child: Page3(),
            ),
          );
        },
      },
    ),
  );

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      routerDelegate: routerDelegate,
      routeInformationParser: BeamerParser(),
      backButtonDispatcher: BeamerBackButtonDispatcher(
        delegate: routerDelegate,
        alwaysBeamBack: true,
        fallbackToBeamBack: true,
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: InkWell(
        onTap: () {
          Beamer.of(context).beamToNamed('/page2');
        },
        child: const Text('Page 1'),
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: SingleChildScrollView(
        child: Column(
          children: [
            const SizedBox(height: 100),
            InkWell(
              onTap: () {
                Beamer.of(context).beamToNamed('/page3', beamBackOnPop: true);
              },
              child: const Text('Page 2'),
            ),
            const SizedBox(height: 1000),
          ],
        ),
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: const Text('Page 3'),
    );
  }
}

Can someone help me? Thank you very much!

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