gpt4 book ai didi

flutter - 方法 'read' 没有为类型 'BuildContext' 定义。?

转载 作者:行者123 更新时间:2023-12-05 01:53:44 33 4
gpt4 key购买 nike

    class MyLoginButton extends StatelessWidget {
final int loginTag;
final Stream<User> stream;

const MyLoginButton({Key? key, required this.loginTag, required this.stream})
: super(key: key);

@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
Navigator.of(context).pop();
},
child: Padding(
padding: const EdgeInsets.all(smallPadding),
child: StreamBuilder<User>(
stream: stream,
builder: (context, snapshot) {
/// this is test mode without firebase auth
if (context.read(loginModeProvider).state) {
SchedulerBinding.instance!
.addPostFrameCallback((timeStamp) async {
/// mock loading
await Future<void>.delayed(const Duration(seconds: 1));
await Navigator.pushReplacement(
context,
MyLoadingRoute<void>(
duration: Duration(milliseconds: 500),
builder: (context) => MainPage(
heroTag: loginTag,
user: null,
)));
});

}

The method 'read' isn't defined for the type 'BuildContext'.

最佳答案

添加提供者导入:

import 'package:provider/provider.dart';

关于flutter - 方法 'read' 没有为类型 'BuildContext' 定义。?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71055341/

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