簡體   English   中英

Choicechip 數據傳遞到另一個小部件

[英]Choicechip data pass to another widget

我正在學習 flutter 但有些東西我在任何地方都找不到。

例如,我想將選擇芯片數據傳遞給 listtile

選擇芯片

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(),
                    ),

我不知道您到底想做什么,但您可以使用小部件構造方法將數據傳遞給另一個小部件,或者將 arguments 傳遞給一個新屏幕,如下所示:

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

並像這樣進入第二個小部件構建方法:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM