gpt4 book ai didi

android - 为什么在 flutter 中的 build 者在这里破裂

转载 作者:行者123 更新时间:2023-12-03 04:57:10 25 4
gpt4 key购买 nike

我已经解决了我的第一组错误,但是现在在这一行代码已中断,我无法弄清楚

这是查询中的错误代码行

builder: (BuildContext context) {... }

这是错误:

Compiler message: lib/main.dart:11:5: Error: No named parameter with the name '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. ChangeNotifierProvider({ ^^^^^^^^^^^^^^^^^^^^^^ Target kernel_snapshot failed: Exception: Errors during snapshot creation: null build failed.



失败:生成失败,发生异常。
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没有builder属性。您要使用create属性:

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

( documentation)

关于android - 为什么在 flutter 中的 build 者在这里破裂,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60385503/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com