class MyPage extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return DefaultTabController(
          length: 2,
          child: new Scaffold(
            appBar: TabBar(
              tabs: [
                Tab(child: Text("MY INFORMATION",style: TextStyle(color: Colors.black54),)),
                Tab(child: Text("WEB CALENDER",style: TextStyle(color: Colors.black54),)),
              ],
            ),
            body:PersonalInformationBlocProvider(
              movieBloc: PersonalInformationBloc(),
              child: TabBarView(
                children: [
                  MyInformation(),
                  new SmallCalendarExample(),
                ],
              ),
            ),
          ),
        );
      }
    }
    
    class MyInformation extends StatelessWidget{
      // TODO: implement build
      var deviceSize;
    
      //Column1
      Widget profileColumn(PersonalInformation snapshot) => Container(
        height: deviceSize.height * 0.24,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: <Widget>[
                Container(
                  decoration: BoxDecoration(
                    borderRadius:
                    new BorderRadius.all(new Radius.circular(50.0)),
                    border: new Border.all(
                      color: Colors.black,
                      width: 4.0,
                    ),
                  ),
                  child: CircleAvatar(
                    backgroundImage: NetworkImage(
                        "http://www.binaythapa.com.np/img/me.jpg"),
                    foregroundColor: Colors.white,
                    backgroundColor: Colors.white,
                    radius: 40.0,
                  ),
                ),
                ProfileTile(
                  title: snapshot.firstName,
                  subtitle: "Developer",
                ),
                SizedBox(
                  height: 10.0,
                ),
              ],
            )
          ],
        ),
      );
      Widget bodyData(PersonalInformation snapshot) {
        return SingleChildScrollView(
            child: Column(
              children: <Widget>[
                profileColumn(snapshot)
              ],
            ),
        );
      }
    
    
      @override
      Widget build(BuildContext context) {
        final personalInformationBloc = PersonalInformationBlocProvider.of(context);
    
        deviceSize = MediaQuery.of(context).size;
        return StreamBuilder(
            stream: personalInformationBloc.results,
            builder: (context,snapshot){
              if (!snapshot.hasData)
                return Center(
                  child: CircularProgressIndicator(),
                );
              return bodyData(snapshot.data);
            }
        );
      }
    }
   

我使用Bloc模式从Rest API检索数据(仅从JSON调用整个对象,并仅解析用户名).该页面由两个选项卡MyInformation和SmallCalendar组成.当应用程序运行时,数据被正确提取,一切正常.当我转到选项卡2并返回选项卡1时,选项卡1中的整个屏幕将变为红色,显示错误:

推荐答案

问题是由于没有将控制器集中处理.

  void dispose() {
    monthChangedController.close();
    dayPressedController.close();
    resultController.close();
  }

Flutter相关问答推荐

使用Bg晃动背景图像边界

为什么小部件会在其父文件中重建,但放在单独文件中时却不会重建?

flutter:如何将字体大小设置得更大(更大)

在Flutter 中压缩图片返回空

Fighter:基于ChangeNotifier状态动态更新AppBar中的图标

Flutter 中的多页表现

如何在扩展其他小部件时访问Ref

出现异常.RangeError(RangeError(index):无效值:有效值范围为空:0).分度误差

当 Dart SDK 版本范围不匹配时,为什么依赖解析器不会抛出错误?

Flutter Riverpod 没有捕获 List 的嵌套值变化

Flutter屏幕适配 - 在模拟器和真实手机上文本尺寸不同

Flutter 3.10 - 'window' 已弃用,不应使用

在 Flutter 中,SpinEdit 叫什么?

使用堆栈的自定义按钮

Freezed+BLoc 如何从 BLoc Listener 查看当前状态和特定状态的变量

我在弹出框中编辑后无法保存日期

无效的 depfile: C:\xxx\xxx\Flutter\project_name\.dart_tool\flutter_build\df4b308df1ee4bce22c56c71751554d1\kernel_snapshot.d 无效

Flutter 错误:正文可能正常完成,导致返回null

Flutter - 检测手指何时进入容器

Flutter Desktop,如何获取windows用户配置文件名称?