我对 Flutter 很陌生,所以我很抱歉没有理解所有的术语。
我有一个从 FCM 接收数据的应用程序,它显示了一个 SnackBar(使用 Get)。所有这一切都运作良好。问题是'onTap'。当我使用 Get.toNamed() 时,它会响应,
Could not find a generator for route RouteSettings("/home-screen", null) in the _WidgetsAppState.
这是我现在的小吃店
void showDialog(BuildContext context, messageJson) {
print('showDialog');
try {
final data = messageJson['data'];
final notification =
data != null && data.keys.isNotEmpty ? data : messageJson['notification'];
var body = notification['body'];
var title = notification['title'];
Get.snackbar(
title,
body,
icon: Icon(Icons.chat),
shouldIconPulse: true,
onTap: (index) {
Get.toNamed('/home-screen');
//Navigator.of(context).pushNamed('/home-screen'); // <-- Didn't work either
},
isDismissible: true,
duration: Duration(seconds: 4),
);
} catch (e) {
print(e.toString());
}
}
我的路线是这样设置的。
class Routes {
static final Map<String, WidgetBuilder> _routes = {
"/home-screen": (context) => HomeScreen(),
"/home": (context) => MainTabs(),
"/login": (context) => LoginScreen(),
"/register": (context) => RegistrationScreen(),
...VendorRoute.getAll(),
};
static Map<String, WidgetBuilder> getAll() => _routes;
static WidgetBuilder getRouteByName(String name) {
if (_routes.containsKey(name) == false) {
return _routes[RouteList.homeScreen];
}
return _routes[name];
}
static Route<dynamic> generateRoute(RouteSettings settings) {
switch (settings.name) {
case RouteList.storeDetail:
return MaterialPageRoute(
builder: VendorRoute.getRoutesWithSettings(settings)[settings.name],
);
default:
return null;
}
}
}
我在试图弄清楚如何导航到 onTap() 页面时处于停滞状态,我也尝试了所有其他变体。任何帮助将不胜感激。谢谢!
REF:Flutter 获取包,https ://pub.dev/packages/get