Olá, recentemente estava fazendo o curso de Flutter e estava conseguindo acessar a aplicação normalmente, a partir da aula 8 de navegação conforme eu mudei a aplicação para as rotas serem do tipo nomeada o seguinte erro apareceu:
lib/main.dart:21:21: Error: The getter 'home' isn't defined for the class 'MyApp'.
- 'MyApp' is from 'package:proj/main.dart' ('lib/main.dart'). Try correcting the name to the name of an existing getter, or defining a getter or field named 'home'. initialRoute: home, ^^^^
Failed to compile application.
RouteGenerator:
class RouteGenerator {
static Route<dynamic> generateRoute(RouteSettings settings) {
final args = settings.arguments;
switch (settings.name) {
case 'home':
return MaterialPageRoute(builder: (_) => HomeScreen());
case 'login':
return MaterialPageRoute(builder: (_) => LoginScreen());
case 'sing-up':
return MaterialPageRoute(builder: (_) => SingupScreen());
case 'favorites':
return MaterialPageRoute(builder: (_) => FavoritesScreen());
case 'profile':
return MaterialPageRoute(builder: (_) => ProfileScreen());
case 'payment':
return MaterialPageRoute(builder: (_) => PaymentScreen());
case 'producer_details':
if (args is Producer) {
return MaterialPageRoute(
builder: (_) => ProducerDetailsScreen(producer: args));
}
return _errorRoute();
case 'package_details':
if (args is Package) {
return MaterialPageRoute(
builder: (_) => PackageDetailsScreen(
package: args));
}
return _errorRoute();
default:
_errorRoute();
}
}
static Route<dynamic> _errorRoute() {
return MaterialPageRoute(builder: (_) {
return Scaffold(
appBar: AppBar(
backgroundColor: AppColors.green,
title: Text('Erro'),
),
body: Center(child: Text('ERRO, rota não encontrada')),
);
});
}
}
Main:
`import 'package:flutter/material.dart';
import 'package:proj/route_generator.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
fontFamily: 'Montserrat',
),
initialRoute: home,
onGenerateRoute: RouteGenerator.generateRoute,
);
} }`