Flutter Can';不要读取提供者数据,尽管它存在于Ancessor小部件中。颤振
我刚开始使用flatter的Provider包,我了解到我们必须在父类中提供Provider,这就是我们所做的。但我仍然得到这个错误。我觉得这和路线生成器有关。非常感谢您的帮助 我的主要应用程序代码:Flutter Can';不要读取提供者数据,尽管它存在于Ancessor小部件中。颤振,flutter,dart,flutter-provider,Flutter,Dart,Flutter Provider,我刚开始使用flatter的Provider包,我了解到我们必须在父类中提供Provider,这就是我们所做的。但我仍然得到这个错误。我觉得这和路线生成器有关。非常感谢您的帮助 我的主要应用程序代码: class MyApp extends StatelessWidget { // This widget is the root of your application. final MaterialColor primary = MaterialColor(0xff1A365
class MyApp extends StatelessWidget {
// This widget is the root of your application.
final MaterialColor primary =
MaterialColor(0xff1A365D, <int, Color>{500: Color(0xff1A365D)});
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (_) => AuthInfoProvider(),
child: MaterialApp(
title: 'xxx',
debugShowCheckedModeBanner: false,
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primaryColor: Color(0xff1A365D),
accentColor: Color(0xff4299E1),
buttonColor: Color(0xff1A365D),
floatingActionButtonTheme: FloatingActionButtonThemeData(
backgroundColor: Color(0xff1A365D))),
onGenerateRoute: RouteGenerator.generateRoute,
initialRoute: '/auth/wrapper',
),
);
}
}
我得到的错误是:
我是提供商的新手,如何解决此问题。非常感谢您的帮助
class RouteGenerator {
static Route<dynamic> generateRoute(RouteSettings settings) {
final args = settings.arguments;
switch (settings.name) {
case '/auth/wrapper':
return MaterialPageRoute(builder: (_) => AuthWrapper());
case '/auth/wrapper/login':
return MaterialPageRoute(builder: (_) => Login());
case '/app/activeevents':
return MaterialPageRoute(builder: (_) => PaginatedActiveEvents());
default:
return MaterialPageRoute(builder: (_) => ErrorRoute());
}
}
}
class AuthWrapper extends StatelessWidget {
const AuthWrapper({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final authInfo = Provider.of<AuthInfo>(context);
return authInfo.isFirst ? Landing() : Signup();
}
}
class AuthInfoProvider with ChangeNotifier {
AuthInfo _authInfo = new AuthInfo();
AuthInfo get authInfo => _authInfo;
void setIsFirst() {
_authInfo.isFirst = false;
notifyListeners();
}
}