【问题标题】:Choicechip data pass to another widgetChoicechip 数据传递到另一个小部件
【发布时间】:2021-12-31 22:02:05
【问题描述】:

我正在学习 Flutter,但有些东西我在任何地方都找不到。

比如我想把choicechip数据传给listtile

ChoiceChip

https://drive.google.com/file/d/1QmeeZeAAhvMT77_FvQ8XQ5hg8KdGk-d-/view?usp=sharing

但我不知道如何在 listtile 中传递数据。

我怎样才能使它成为可能?

 Wrap(
                      runSpacing: spacing,
                      spacing: spacing,
                      children: goodType
                          // ignore: non_constant_identifier_names
                          .map((GoodTypes) => ChoiceChip(
                                label: Text(GoodTypes.label),
                                labelStyle:
                                    GoogleFonts.ubuntu(color: Colors.white),
                                onSelected: (isSelected) => setState(() {
                                  goodType = goodType.map((otherChip) {
                                    final newChip =
                                        otherChip.copy(isSelected: false);
                                    // print(goodType);
                                    return GoodTypes == newChip
                                        ? newChip.copy(
                                            isSelected: isSelected)
                                        : newChip;
                                  }).toList();
                                  print(GoodTypes.label);
                                }),
                                selected: GoodTypes.goodSelected,
                                selectedColor: AppColor.yellow,
                                backgroundColor: AppColor.blackrussain,
                                shape: StadiumBorder(
                                  side: BorderSide(color: AppColor.yellow),
                                ),
                              ))
                          .toList(),
                    ),

【问题讨论】:

    标签: android flutter flutter-layout


    【解决方案1】:

    我不知道您到底想做什么,但您可以使用小部件构造方法将数据传递给另一个小部件,或者将参数传递给新屏幕,如下所示:

    Navigator.pushNamed(
      context,
      ExtractArgumentsScreen.routeName,
      arguments: ScreenArguments(
        'Some data',
      ),
    )
    

    并像这样进入第二个小部件构建方法:

    final args = ModalRoute.of(context)!.settings.arguments as ScreenArguments;
    

    【讨论】:

    • 不,我需要将数据传递给 listtile
    猜你喜欢
    • 2020-02-22
    • 2021-09-26
    • 2020-08-08
    • 2020-08-20
    • 1970-01-01
    • 2021-06-08
    • 1970-01-01
    • 2018-11-27
    • 2020-02-21
    相关资源
    最近更新 更多