问题描述
当我运行这个时,我不断收到同样的错误,请帮忙。
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(App());
}
class App extends StatelessWidget {
final Color primaryColor = Color(0xff18203d);
@override
Widget build(BuildContext context) {
// ignore: todo
// Todo: implement build
return MultiProvider(
providers: [
Provider<AuthenticationService>(
create: (_) => AuthenticationService(FirebaseAuth.instance),),StreamProvider(
create: (_context) =>
_context.read<AuthenticationService>().authStateChanges,initialData: null,],child: MaterialApp(
title: 'Mboka Horticulture',theme: ThemeData(
primaryColor: primaryColor,visualDensity: VisualDensity.adaptivePlatformDensity,home: AuthenticationWrapper(),));
}
}
class AuthenticationWrapper extends StatelessWidget {
const AuthenticationWrapper({
Key? key,}) : super(key: key);
@override
Widget build(BuildContext context) {
// ignore: todo
// Todo: implement build
final firebaseuser = context.watch<User>();
if (firebaseuser != null) {
return Dashboard();
}
return Login();
}
}
这是我不断收到的错误,我不明白。
**提供者是“有范围的”。因此,如果您将 provider 插入到一个 路线,然后 其他路由将无法访问该提供程序。
- You used a `BuildContext` that is an ancestor of the provider you are trying to read.
Make sure that AuthenticationWrapper is under your MultiProvider/Provider<User>.
This usually happens when you are creating a provider and trying to read it immediately.
For example,instead of:**
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)