简体   繁体   English

为什么颤振中的构建器在这里中断

[英]why is builder in flutter breaking here

I have fixed my first set of errors today, but now on this line the code breaks, and I can't figure this out我今天已经修复了我的第一组错误,但是现在在这一行代码中断了,我无法弄清楚这一点

here is the bad line of code in queestion这是问题中的错误代码行

builder: (BuildContext context) {... }

Here is the error:这是错误:

Compiler message: lib/main.dart:11:5: Error: No named parameter with the name 'builder'.编译器消息:lib/main.dart:11:5:错误:没有名为“builder”的命名参数。 builder: (BuildContext context) { ^^^^^^^ ../../Downloads/flutter_windows_v1.12.13+hotfix.8-stable/src/flutter/.pub-cache/hosted/pub.dartlang.org/provider-4.0.4/lib/src/change_notifier_provider.dart:107:3: Context: Found this candidate, but the arguments don't match. builder: (BuildContext context) { ^^^^^^^ ../../Downloads/flutter_windows_v1.12.13+hotfix.8-stable/src/flutter/.pub-cache/hosted/pub.dartlang.org/provider -4.0.4/lib/src/change_notifier_provider.dart:107:3: 上下文:找到这个候选,但参数不匹配。 ChangeNotifierProvider({ ^^^^^^^^^^^^^^^^^^^^^^ Target kernel_snapshot failed: Exception: Errors during snapshot creation: null build failed. ChangeNotifierProvider({ ^^^^^^^^^^^^^^^^^^^^^^ 目标 kernel_snapshot 失败:异常:快照创建过程中出错:空构建失败。

FAILURE: Build failed with an exception. FAILURE:构建失败,出现异常。

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

void main() => runApp(
  ChangeNotifierProvider<AuthService>(
    child: MyApp(),
    builder: (BuildContext context) {
      return AuthService();
    },
  ),
);

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: FutureBuilder<FirebaseUser>(
        future: Provider.of<AuthService>(context).getUser(),
        builder: (context, AsyncSnapshot<FirebaseUser> snapshot) {
          if (snapshot.connectionState == ConnectionState.done) {
            // log error to console
            if (snapshot.error != null) {
              print("error");
              return Text(snapshot.error.toString());
            }

            // redirect to the proper page
            return snapshot.hasData ? HomePage(snapshot.data) : LoginPage();
          } else {
            // show loading indicator
            return LoadingCircle();
          }
        },
      ),
    );
  }
}

class LoadingCircle extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Container(
        child: CircularProgressIndicator(),
        alignment: Alignment(0.0, 0.0),
      ),
    );
  }

ChangeNotifierProvider does not have a builder property. ChangeNotifierProvider没有builder属性。 You want to use the create property:您想使用create属性:

ChangeNotifierProvider<AuthService>(
  create: (context) => AuthService(),
  child: MyApp(),
},

( documentation ) ( 文档)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM