这是使用Navigator Route的三个文件的代码段。 路由到下一页时,输出只是空白屏幕。
main.dart
我已在此处初始化路由名称
import 'package:flutter/material.dart';
import './homepage.dart';
import './itemdetails.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(............
.................................
.................................
routes: {
'/': (ctx) => HomePage(),
DetailsScreen.routname: (ctx) => DetailsScreen()
},
);
}
}
homepage.dart
..........................
..............................
..............................
class CardDesign extends StatelessWidget {
void itemDetails(BuildContext context) {
Navigator.of(context).pushNamed(
DetailsScreen.routname,
);
}
Widget build(BuildContext context) {
return InkWell(
onTap: () => itemDetails(context),
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20))),
elevation: 3,..........
.....................
.................
itemdetails.dart
最后一页显示空白屏幕
import 'package:flutter/material.dart';
class DetailsScreen extends StatelessWidget {
static const String routname = '/DetailsScreen';
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Text("hlooo"),
),
);
}
}