我正在尝试在我的路由上go-router。第一次它工作,但一旦我刷新它工作。
final GoRouter _router = GoRouter(
debugLogDiagnostics: true,
initialLocation: '/',
routes: [
GoRoute(
path: '/',
builder: (BuildContext context, GoRouterState state) {
return const MainPage();
},
),
GoRoute(
path: '/product/:id',
name: 'product',
builder: (context, state){
final id = state.params['id']!;
return DetailsView(id:id);
},
),
GoRoute(
path: '/homepage',
builder: (BuildContext context, GoRouterState state) {
return const HomePage();
},
),
],
);
即使传递任何值也不起作用
onTap: () {
context.pushNamed("product", params: {'id':"dsadklaskld"});
},
下面是我导航到的有状态小部件。detailsView.dart
class DetailsView extends StatefulWidget {
final String id;
/// Constructs a [DetailsScreen]
const DetailsView({super.key, required this.id});
@override
State<DetailsView> createState() => _DetailsViewState();
}
class _DetailsViewState extends State<DetailsView> {
....
late String id = widget.id;
}
1条答案
按热度按时间2ledvvac1#
id的值为null,所以我不得不把它放在initializedata()函数中。