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!