我正试图找到问题,我甚至做了一个热重启,但它不工作,我被卡住了,有人请看看它
创建MessageList(dirty, state: MessageListState#24cda)时抛出以下ProviderNotFoundException:错误:无法在此MessageList小部件上方找到正确的提供程序出现这种情况是因为您使用了不包含提供者的BuildContext
Main.dart
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(const App());
}
class App extends StatelessWidget {
const App({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider<UserDao>(
lazy: false,
create: (_) => UserDao(),
),
],
child: Builder(builder: (context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'RayChat',
theme: ThemeData(primaryColor: const Color(0xFF3D814A)),
home: Consumer<UserDao>(builder: (context, userDao, child) {
if (userDao.isLoggedIn()) {
return const MessageList();
} else {
return const Login();
}
}),
);
}),
);
}
}
我发现我缺少messagedao的提供程序,所以我在UserDao下添加了一个提供程序
Provider<MessageDao>(
create: (_) => MessageDao(),
lazy: false,
)