Flutter + Get, toNamed() возвращает ошибку RouteSettings()
Я новичок во 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(). Я пробовал и все другие варианты. Любая помощь будет оценена здесь. Благодарность!
ССЫЛКА: пакет Flutter Get, https://pub.dev/packages/get
1 ответ
Решение
Вы установили маршруты и onGenerateRoute внутри MaterialApp? Вот пример https://flutter.dev/docs/cookbook/navigation/named-routes