我正在构建一个网络应用程序,它需要一个获取帖子 ID 的路由,然后它将使用该 ID 获取帖子。
我怎么能有 URL 参数让我们说/post/:idid 是参数
我的应用目前看起来像这样:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
// title: "Paste",
initialRoute: "/",
theme: ThemeData(
primarySwatch: Colors.green,
primaryColor: Colors.blue
),
routes: {
"/": (context) => HomePage(),
"/post": (context) => PastieRoute()
},
debugShowCheckedModeBanner: false
);
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:这是我根据@BloodLoss 尝试过的,出于某种原因,我在访问时没有得到任何东西到控制台 localhost:8080/post?id=123
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
initialRoute: "/",
routes: {
"/": (context) => HomePage(),
"/post": (context) => PastieRoute()
}, …Run Code Online (Sandbox Code Playgroud)