Flutter + Get, toNamed() returns RouteSettings() 错误
Flutter + Get, toNamed() returns RouteSettings() error
我是 Flutter 的新手,所以很抱歉不理解所有术语。
我有一个从 FCM 接收数据的应用程序,它显示了一个 SnackBar(使用 Get)。所有这些都运作良好。问题是'onTap'。当我使用 Get.toNamed() 时,它会响应
Could not find a generator for route RouteSettings("/home-screen", null) in the _WidgetsAppState.
这是我现在的 Snackbar
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
你在MaterialApp里面设置routes和onGenerateRoute了吗?这是一个例子 https://flutter.dev/docs/cookbook/navigation/named-routes
我是 Flutter 的新手,所以很抱歉不理解所有术语。
我有一个从 FCM 接收数据的应用程序,它显示了一个 SnackBar(使用 Get)。所有这些都运作良好。问题是'onTap'。当我使用 Get.toNamed() 时,它会响应
Could not find a generator for route RouteSettings("/home-screen", null) in the _WidgetsAppState.
这是我现在的 Snackbar
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
你在MaterialApp里面设置routes和onGenerateRoute了吗?这是一个例子 https://flutter.dev/docs/cookbook/navigation/named-routes