简体   繁体   English

错误:找不到正确的提供者<User>在此方向器小部件上方

[英]Error: Could not find the correct Provider<User> above this Directioner Widget

I'm getting this error when running my Flutter app and I have no clue about how to fix it.运行我的 Flutter 应用程序时出现此错误,我不知道如何修复它。 I suspect that the file that produces this error is 'directioner.dart' which shows Login screen or Home instead if there's no loged in user.我怀疑产生此错误的文件是“directioner.dart”,如果没有登录用户,它会显示登录屏幕或主页。 Any clue?有什么线索吗? Thanks.谢谢。

在此处输入图片说明

This is my 'directioner.dart' file:这是我的“directioner.dart”文件:

import 'package:empirica_qaqc/pages/home_page.dart';
import 'package:empirica_qaqc/pages/login_page.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class Directioner extends StatelessWidget {
  const Directioner({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final user = Provider.of<User>(context);
    return user == null ? LoginPage() : HomePage();
  }
}

and this is my main.dart file这是我的 main.dart 文件

import 'package:empirica_qaqc/pages/directioner.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      theme: ThemeData(
        primaryColor: Color(0xff1e8735),
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: Directioner(),
    );
  }
}

My 'flutter doctor -v' output:我的“颤振医生 -v”输出:

[✓] Flutter (Channel stable, 1.22.1, on Mac OS X 10.15.6 19G2021, locale es-CL)
    • Flutter version 1.22.1 at /Users/ben/flutter
    • Framework revision f30b7f4db9 (13 days ago), 2020-10-08 10:06:30 -0700
    • Engine revision 75bef9f6c8
    • Dart version 2.10.1

 
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at /Users/ben/Library/Android/sdk
    • Platform android-30, build-tools 30.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.6)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.6, Build version 11E708
    • CocoaPods version 1.9.1

[✓] Android Studio (version 4.0)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 50.0.1
    • Dart plugin version 193.7547
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] VS Code (version 1.50.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.15.1

[✓] Connected device (1 available)
    • sdk gphone x86 arm (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator)

• No issues found!

Seems like you forgot to "provide" the User object in your widget tree.似乎您忘记在小部件树中“提供” User对象。

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      theme: ThemeData(
        primaryColor: Color(0xff1e8735),
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      // expose an object to be available down the widget tree
      home: Provider( 
        create: (_) => User(),
        child: Directioner(),
      ),
    );
  }
}

The error screen typically gives hints to solve this type of issues.错误屏幕通常会提供解决此类问题的提示。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:找不到正确的提供者<studyjios>在这个 StudyjiosList Widget 上方</studyjios> - Error: Could not find the correct Provider<Studyjios> above this StudyjiosList Widget 错误:找不到正确的提供者<list<planner> > 在这个 Planner Widget 上方</list<planner> - Error: Could not find the correct Provider<List<Planner>> above this Planner Widget 错误:找不到正确的提供者<list<parking> > 在这个停车列表小部件上方</list<parking> - Error: could not find the correct Provider<List<Parking>> above this ParkingList Widget 未处理的异常:错误:找不到正确的提供者<User>在此 MyApp 小部件上方 - Unhandled Exception: Error: Could not find the correct Provider<User> above this MyApp Widget Flutter 错误:找不到正确的提供程序<MyUser>在这个 SettingsForm 小部件上方 - Flutter Error: Could not find the correct Provider<MyUser> above this SettingsForm Widget Flutter:找不到正确的提供程序<entryprovider>在此页面小部件上方</entryprovider> - Flutter : Could not find the correct Provider<EntryProvider> above this Page Widget Flutter/Dart 在这个 Widget 上方找不到正确的 Provider&lt;&gt; - Flutter/Dart Could not find correct Provider<> above this Widget 错误:云找不到正确的提供者<List<Brew> &gt; 在此 BrewList 小部件上方 - Error: Cloud not find the correct Provider<List<Brew>> above this BrewList Widget 如何使用 bloc 监听 stream 变量 | 找不到正确的提供者<statestreamable<.> > 在这个 BlocBuilder 之上<statestreamable<.> , <.>> </statestreamable<.></statestreamable<.> - How to listen to stream variable using bloc | Could not find the correct Provider<StateStreamable<.>> above this BlocBuilder<StateStreamable<.>, <.>> 在 flutter 应用程序中找不到正确的提供程序 - Could not find the correct provider in flutter application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM