What is the difference between builder and pageBuilder in the Go Router package?
Asked Answered
M

1

28

In the Flutter go_router package, there are apparently two ways of creating a new page, with either a builder or a pageBuilder:

GoRoute(
  name: 'Route',
  path: '/route',
  builder: (BuildContext context, GoRouterState state) =>
    const RouteView(...),
  pageBuilder: (BuildContext context, GoRouterState state) => 
    MaterialPage(
      child: const RouteView(...),
    ),
),

But what is the difference between them? They seem to do the same thing, only pageBuilder has a wrapper of MaterialPage on it, is that all? By the way, is a MaterialPage that useful?

Mellow answered 8/11, 2022 at 21:22 Comment(0)
M
35

I've had this same question. From GoRouter's documentation this is all that I found:

The builder is responsible for building the Widget to display on screen. Alternatively, you can use pageBuilder to customize the transition animation when that route becomes active. The default transition is used between pages depending on the app at the top of its widget tree, e.g. the use of MaterialApp will cause go_router to use the MaterialPage transitions. Consider using pageBuilder for custom Page class.

So I suppose the only useful difference I can deduce is that pageBuilder allows you to have a custom transition animation. Hope that helps.

Metaphysical answered 9/11, 2022 at 0:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.