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?
CodePudding user response:
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.