颤振错误 Null 检查运算符用于空值

时间:2021-06-01 22:35:35

标签: android flutter android-studio dart

我是 flutter 新手,我有一个错误,无论我怎么尝试都无法修复, 试图隔离导致它但没有成功的代码 我收到的错误是

> > ======== Exception caught by Flutter framework ===================================================== The following _CastError was thrown during a service extension callback for "ext.flutter.inspector.getRootWidgetSummaryTree": Null check operator
> used on a null value
> 
> When the exception was thrown, this was the stack: 
> #0      WidgetInspectorService._registerObjectGroupServiceExtension.<anonymous
> closure> (package:flutter/src/widgets/widget_inspector.dart:793:84)
> #1      WidgetInspectorService._registerObjectGroupServiceExtension.<anonymous
> closure> (package:flutter/src/widgets/widget_inspector.dart:792:17)
> #2      BindingBase.registerServiceExtension.<anonymous closure> (package:flutter/src/foundation/binding.dart:597:32) <asynchronous
> suspension>
> ====================================================================================================

滚动时出现错误,我安装了最新的稳定版 flutter (2.2.1) 我的 2 个小部件是: 首页

class Home extends StatelessWidget {
  const Home({Key key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      drawer: Drawer(
        child: ListView(
          children: <Widget>[DrawerHeader(child: Text("sadsa"))],
        ),
      ),
      body: NestedScrollView(
          floatHeaderSlivers: true,
          scrollDirection: Axis.vertical,
          clipBehavior: Clip.antiAlias,
          headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
            return <Widget>[
              MyAppBar(),
            ];
          },
          body: ListView.separated(
            itemBuilder: (context, i) {
              return Container(
                height: 100,
                width: 200.0,
                color:
                    Colors.primaries[Random().nextInt(Colors.primaries.length)],
              );
            },
            separatorBuilder: (context, i) => Divider(height: 1.0),
            itemCount: 30,
          )),
      bottomNavigationBar: BottomNavigationBar(
        items: <BottomNavigationBarItem>[
          BottomNavigationBarItem(icon: Icon(Icons.arrow_back), label: "asdsa"),
          BottomNavigationBarItem(icon: Icon(Icons.arrow_back), label: "asdsa"),
        ],
        currentIndex: 0,
        onTap: (int i) {},
      ),
    );
  }
}

和另一个名为 MyAppBar 的小部件,它是我构建的自定义 silverAppBar

    class MyAppBar extends StatefulWidget {
  const MyAppBar({Key key}) : super(key: key);

  @override
  _MyAppBarState createState() => _MyAppBarState();
}

class _MyAppBarState extends State<MyAppBar> {
  @override
  void initState() {
    super.initState();
  }

  Widget build(BuildContext context) {
      return SliverAppBar(
        title: Text("my App"),
        floating: true,
        snap: true,

        actions: [
          GestureDetector(
            onTap: () {},
            child: Container(
              padding: EdgeInsets.symmetric(horizontal: 10.0),
              child: IconButton(
                icon: Icon(Icons.search_rounded),
                onPressed: () {},
                iconSize: 35.0,
              ),
            ),
          ),
          GestureDetector(
            onTap: () {},
            child: CircleAvatar(
              radius: 20.0,
              child: Text("asdsa"),
            ),
          )
        ],
        bottom: PreferredSize(
            preferredSize: Size.fromHeight(70.0),
            child: Container(
              height: 70.0,
              child: ListView(
                  scrollDirection: Axis.horizontal,
                  children: List.generate(10, (index) {
                    return Padding(
                        padding: EdgeInsets.symmetric(horizontal: 7.0, vertical: 10.0),
                        child: Chip(label: Text('$index')));
                  })
              ),
            )
        ),
      );
  }
}

0 个答案:

没有答案