class NotfoundView extends StatelessWidget { const NotfoundView({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("路由没有找到"), ), body: ListTile( title: Text("返回首页"), subtitle: Text('Get.offAllNamed(AppRoutes.Home)'), onTap: () => Get.offAllNamed(AppRoutes.Home), ), ); } }
static const NotFound = '/notfound'; static final unknownRoute = GetPage( name: AppRoutes.NotFound, page: () => NotfoundView(), ); // main.dart @override Widget build(BuildContext context) { return GetMaterialApp( ... unknownRoute: AppPages.unknownRoute, ); }