为什么基于索引抓取子项时颤振会抛出无效的参数?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了为什么基于索引抓取子项时颤振会抛出无效的参数?相关的知识,希望对你有一定的参考价值。

好的,所以我目前正在使用PageBuilder,并且我正在做什么,但是我真的不喜欢滑动物理学。我只希望他们点击底部的应用栏进行浏览。

工作码

class Home extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _HomeState();
  }
}

class _HomeState extends State<Home> {
  int selectedIndex = 0;

  PageController controller = PageController();

  List<GButton> tabs = new List();

  final List<Widget> _children = [
    Settings(),
    ListFamily(),
    CameraScreen(),
    SplashAccount(),
    Questions()
  ];

  @override
  void initState() {
    super.initState();

    var padding = EdgeInsets.symmetric(horizontal: 18, vertical: 5);
    double gap = 10;

    tabs.add(GButton(
      gap: gap,
      iconActiveColor: maincolor,
      iconColor: Colors.grey,
      textColor: maincolor,
      iconSize: 24,
      padding: padding,
      icon: Icons.settings,
      // textStyle: t.textStyle,
      text: 'Settings',
    ));

    tabs.add(GButton(
      gap: gap,
      iconActiveColor: maincolor,
      iconColor: Colors.grey,
      textColor: maincolor,
      iconSize: 24,
      padding: padding,
      icon: Icons.wc,
      // textStyle: t.textStyle,
      text: 'Relations',
    ));

    tabs.add(GButton(
      gap: gap,
      iconActiveColor: maincolor,
      iconColor: Colors.grey,
      textColor: maincolor,
      iconSize: 24,
      padding: padding,
      icon: Icons.camera_alt,
      // textStyle: t.textStyle,
      text: 'Camera',
    ));

    tabs.add(GButton(
      gap: gap,
      iconActiveColor: maincolor,
      iconColor: Colors.grey,
      textColor: maincolor,
      iconSize: 24,
      padding: padding,
      icon: Icons.video_library,
      // textStyle: t.textStyle,
      text: 'Videos',
    ));

    tabs.add(GButton(
      gap: gap,
      iconActiveColor: maincolor,
      iconColor: Colors.grey,
      textColor: maincolor,
      iconSize: 24,
      padding: padding,
      icon: Icons.question_answer,
      // textStyle: t.textStyle,
      text: 'Questions',
    ));
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        extendBody: true,
        body: PageView.builder(
          onPageChanged: (page) {
            setState(() {
              selectedIndex = page;
            });
          },
          controller: controller,
          itemBuilder: (context, position) {
            return Column(
              children: <Widget>[
                Expanded(child: _children[position]),
                Container(
                  width: MediaQuery.of(context).size.width,
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.only(
                          topLeft: Radius.circular(12),
                          topRight: Radius.circular(12),
                          bottomLeft: Radius.zero,
                          bottomRight: Radius.zero),
                      boxShadow: [
                        BoxShadow(
                            spreadRadius: -10,
                            blurRadius: 60,
                            color: Colors.black.withOpacity(.20),
                            offset: Offset(0, 15))
                      ]),
                  child: Padding(
                    padding: const EdgeInsets.symmetric(vertical: 20),
                    child: GNav(
                        tabs: tabs,
                        selectedIndex: selectedIndex,
                        onTabChange: (index) {
                          print(index);
                          setState(() {
                            selectedIndex = index;
                          });
                        }),
                  ),
                ),
              ],
            );
          },
          itemCount: tabs.length, // Can be null
        ),
      ),
    );
  }
}

无效的参数代码

class Home extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _HomeState();
  }
}

class _HomeState extends State<Home> {
  int selectedIndex = 0;

  PageController controller = PageController();

  List<GButton> tabs = new List();

  final List<Widget> _children = [
    Settings(),
    Container(),
    Container(),
    Container(),
    Container()
  ];

  @override
  void initState() {
    super.initState();

    var padding = EdgeInsets.symmetric(horizontal: 18, vertical: 5);
    double gap = 10;

    tabs.add(GButton(
      gap: gap,
      iconActiveColor: maincolor,
      iconColor: Colors.grey,
      textColor: maincolor,
      iconSize: 24,
      padding: padding,
      icon: Icons.settings,
      // textStyle: t.textStyle,
      text: 'Settings',
    ));

    tabs.add(GButton(
      gap: gap,
      iconActiveColor: maincolor,
      iconColor: Colors.grey,
      textColor: maincolor,
      iconSize: 24,
      padding: padding,
      icon: Icons.wc,
      // textStyle: t.textStyle,
      text: 'Relations',
    ));

    tabs.add(GButton(
      gap: gap,
      iconActiveColor: maincolor,
      iconColor: Colors.grey,
      textColor: maincolor,
      iconSize: 24,
      padding: padding,
      icon: Icons.camera_alt,
      // textStyle: t.textStyle,
      text: 'Camera',
    ));

    tabs.add(GButton(
      gap: gap,
      iconActiveColor: maincolor,
      iconColor: Colors.grey,
      textColor: maincolor,
      iconSize: 24,
      padding: padding,
      icon: Icons.video_library,
      // textStyle: t.textStyle,
      text: 'Videos',
    ));

    tabs.add(GButton(
      gap: gap,
      iconActiveColor: maincolor,
      iconColor: Colors.grey,
      textColor: maincolor,
      iconSize: 24,
      padding: padding,
      icon: Icons.question_answer,
      // textStyle: t.textStyle,
      text: 'Questions',
    ));
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
            extendBody: true,
            body: Column(
              children: <Widget>[
// _children[selectedIndex] will cause the Invalid Argument(s) error here.
                Expanded(child: _children[selectedIndex]),
                Container(
                  width: MediaQuery.of(context).size.width,
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.only(
                          topLeft: Radius.circular(12),
                          topRight: Radius.circular(12),
                          bottomLeft: Radius.zero,
                          bottomRight: Radius.zero),
                      boxShadow: [
                        BoxShadow(
                            spreadRadius: -10,
                            blurRadius: 60,
                            color: Colors.black.withOpacity(.20),
                            offset: Offset(0, 15))
                      ]),
                  child: Padding(
                    padding: const EdgeInsets.symmetric(vertical: 20),
                    child: GNav(
                        tabs: tabs,
                        selectedIndex: selectedIndex,
                        onTabChange: (index) {
                          print(index);
                          setState(() {
                            selectedIndex = index;
                          });
                        }),
                  ),
                ),
              ],
            )));
  }
}

我目前仅使用Flutter的材料库和此插件:https://github.com/sooxt98/google_nav_bar

此外,我也尝试过使用其他底部导航栏进行此操作,但我对此感到困惑”>

工作代码中的孩子是我的其他页面。设置页面代码如下:

class Settings extends StatefulWidget {
  @override
  _SettingsPageState createState() => _SettingsPageState();
}

class _SettingsPageState extends State<Settings> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              // Logo + Container
              Container(
                color: thirdcolor,
                child: Center(
                  child: SafeArea(
                    child: Container(
                      decoration: BoxDecoration(
                          image: DecorationImage(
                              image: AssetImage(
                                  "assets/mvvdesign/Solid/White/horizontal/logo.png"),
                              fit: BoxFit.fitWidth)),
                    ),
                  ),
                ),
              ),
              // Container for Questions bar

              Container(
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    Container(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: <Widget>[
                          Text(
                            "SETTINGS",
                            style: TextStyle(
                                color: Colors.white,
                                fontSize: fontsize,
                                fontFamily: fontfamily,
                                fontWeight: FontWeight.w300),
                          ),
                          Container(
                            margin: const EdgeInsets.only(top: 10.0),
                            color: Colors.white,
                            child: Divider(
                              height: 5.0,
                              thickness: 3.0,
                              endIndent: 100.0,
                              indent: 100.0,
                              color: Colors.white,
                            ),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),

              Container(
                margin: const EdgeInsets.only(top: 20.0),
                child: Column(
                  children: <Widget>[
                    Container(
                      height: 60,
                      width: MediaQuery.of(context).size.width - 50,
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(15.0),
                          border: Border.all(color: Colors.white, width: 2.0)),
                      child: Center(
                        child: SingleChildScrollView(
                          scrollDirection: Axis.horizontal,
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: <Widget>[
                              Text(
                                "Hey, ",
                                style: TextStyle(
                                  fontSize: 24.0,
                                  color: Colors.white,
                                ),
                              ),
                              Text(
                                "Alyssa Thurman",
                                style: TextStyle(
                                    fontSize: 24.0,
                                    color: Colors.green,
                                    fontWeight: FontWeight.bold),
                              ),
                            ],
                          ),
                        ),
                      ),
                      margin: const EdgeInsets.only(bottom: 10.0),
                    ),
                  ],
                ),
              ),

              Expanded(
                child: SingleChildScrollView(
                  child: Column(
                    children: <Widget>[
                      Container(
                        width: 360.0,
                        height: 56.0,
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(10.0),
                            color: Colors.white),
                        margin: const EdgeInsets.only(top: 20.0),
                        child: Center(
                            child: Text(
                          "Update Account Information",
                          style: TextStyle(fontSize: 24.0, color: maincolor),
                        )),
                      ),
                      Container(
                        width: 360.0,
                        height: 56.0,
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(10.0),
                            color: Colors.white),
                        margin: const EdgeInsets.only(top: 40.0),
                        child: Center(
                            child: Text(
                          "Terms and Conditions",
                          style: TextStyle(fontSize: 24.0, color: maincolor),
                        )),
                      ),
                      Container(
                        width: 360.0,
                        height: 56.0,
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(10.0),
                            color: Colors.white),
                        margin: const EdgeInsets.only(top: 40.0),
                        child: Center(
                            child: Text(
                          "Privacy Policy",
                          style: TextStyle(fontSize: 24.0, color: maincolor),
                        )),
                      ),
                      Container(
                        width: 360.0,
                        height: 56.0,
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(10.0),
                            color: Colors.white),
                        margin: const EdgeInsets.only(top: 40.0),
                        child: Center(
                            child: Text(
                          "Manage Membership",
                          style: TextStyle(fontSize: 24.0, color: maincolor),
                        )),
                      ),
                      Container(
                        width: 360.0,
                        height: 56.0,
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(10.0),
                            color: Colors.red),
                        margin: const EdgeInsets.only(top: 40.0, bottom: 40.0),
                        child: InkWell(
                          onTap: () async {
                            await OneSignal.shared.logoutEmail();
                            SharedPreferences prefs =
                                await SharedPreferences.getInstance();
                            prefs.remove('accesstoken');
                            prefs.remove('refreshtoken');
                            prefs.remove('email');
                            Navigator.push(
                              context,
                              MaterialPageRoute(builder: (context) => First()),
                            );
                          },
                          child: Center(
                              child: Text(
                            "LOGOUT",
                            style:
                                TextStyle(fontSize: 24.0, color: Colors.white),
                          )),
                        ),
                      ),
                    ],
                  ),
                ),
              )
            ],
          ),
        ),
      ),
      resizeToAvoidBottomPadding: false,
      backgroundColor: thirdcolor,
    );
  }
}

错误日志:https://pastebin.com/raw/Regkgcqk

好的,所以我目前正在使用PageBuilder,并且我正在做什么,但是我真的不喜欢滑动物理学。我宁愿让他们点击bottomappbar进行导航。工作代码:类Home ...

答案

所以我并没有真正弄清楚为什么它会弄乱,但我想出了如何禁用tabview的滚动物理特性。

以上是关于为什么基于索引抓取子项时颤振会抛出无效的参数?的主要内容,如果未能解决你的问题,请参考以下文章

错误:Facebook 身份验证对此用户无效。使用 Back4App 进行颤振

颤振:RangeError(索引):无效值:不在包含范围内0..27:28

为啥当客户端断开连接时这个简单的 websocket 代码会抛出?

为啥当参数为null时,postgres会抛出异常?

动态对象变量的 C# 索引在方法中有效,但在返回时无效,错误 C50021

10.异常处理自定义异常断言