dart 打开应用程序时,RenderCustomMultiChildLayoutBox的每个子级必须在其父级数据错误中具有ID

pepwfjgg  于 2023-09-28  发布在  其他
关注(0)|答案(1)|浏览(80)

我正在尝试制作一个具有侧边栏的小部件,我有以下代码

Widget build(BuildContext context) {
    return Scaffold(
      body: Expanded(
        child: Row(
          children: [
            SafeArea(
                child: NavigationRail(
              selectedIndex: 0,
              onDestinationSelected: (int index) {
                print('Test');
              },
              destinations: [
                NavigationRailDestination(
                  icon: Icon(Icons.home),
                  label: Text("Home"),
                ),
                NavigationRailDestination(
                  icon: Icon(Icons.home),
                  label: Text("a"),
                ),
              ],
            )),
            SignUpPage(),
          ],
        ),
      ),
    );
  }

在调试模式下打开应用程序时出现错误Every child of a RenderCustomMultiChildLayoutBox must have an ID in its parent data.
下面是SignUpPage的代码,但不确定是否需要它,而且它有点长:https://pastebin.com/j1knyKFw
已经看过the other stack overflow thread about this error了,但在我的情况下没有帮助
尝试使用BingGPT进行调试,但没有任何结果。

juzqafwq

juzqafwq1#

下面是开始的示例代码。
首先,看看下面提到的源代码的输出:View
现在,将下面提到的源代码复制并粘贴到main.dart文件中。
原始程式码:

import "package:flutter/material.dart";

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "Flutter Demo",
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
      debugShowCheckedModeBanner: false,
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Row(
          children: <Widget>[
            NavigationRail(
              selectedIndex: currentIndex,
              labelType: NavigationRailLabelType.all,
              destinations: const <NavigationRailDestination>[
                NavigationRailDestination(
                  icon: Icon(Icons.looks_one),
                  label: Text("One"),
                ),
                NavigationRailDestination(
                  icon: Icon(Icons.looks_two),
                  label: Text("Two"),
                ),
              ],
              onDestinationSelected: (int index) {
                currentIndex = index;
                setState(() {});
              },
            ),
            const VerticalDivider(),
            Expanded(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Icon(currentIndex == 0 ? Icons.looks_one : Icons.looks_two),
                  Text(currentIndex == 0 ? "One" : "Two"),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}

相关问题