0

My app_router.dart looks like this

GoRoute(
      path: '/',
      name: AppRoute.todoList.name,
      redirect: (context, state) async {
        var initialRoute = await getInitialRoute();
        return initialRoute != AppRoute.todoList.name ? "/$initialRoute" : null;
      },
      builder: (context, state) => TodoListScreen(),
      routes: [
        GoRoute(
            path: 'add',
            name: AppRoute.todoAdd.name,
            builder: (context, state) => TodoAddScreen()),
        GoRoute(
            path: 'edit/:id',
            name: AppRoute.todoEdit.name,
            builder: (context, state) {
              final todoId = state.pathParameters['id']!;
              return TodoEditScreen(todoId: int.parse(todoId));
            })
        ]
    )

The problem I have is that whenever I navigate to add or edit for example, TodoListScreen() builds its entire widget tree again (after the add, edit widget tree has been built). I.e. it builds the TodoListScreen widget again, it does this even when I navigate into child widgets of add and edit This is causing issues for me data retention-wise.

AppRoute is just an enum

Is this by design when using goRouter? If not can someone help me refactor this?

Thanks in advance!

0

1 Answer 1

0

The question was posted a while ago, still I want to deliver the answer. Maybe it is helpful for others. You can set the initialroute as property of the GoRouter directly. Your check in the redirect leads to navigation to the basic route. If you set the initial route property of the GoRouter directly and remove the check your problem is solved.

Sign up to request clarification or add additional context in comments.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.