更改ListTile的字幕

时间:2019-11-14 20:40:53

标签: flutter dart

嗨,我尝试获取数据并将其赋予新值后更改ListTile的字幕,但是我在这段代码中遇到了困难:

Widget build(BuildContext context) {
    DateTime dateTime = DateTime.now();
    return Scaffold(
      appBar: AppBar(leading: IconButton(
        icon: Icon(Icons.arrow_back_ios),
        onPressed: () {
          Navigator.pop(context);
        },
      ),
          backgroundColor: CustomColors.newOrange),
      backgroundColor: CustomColors.newCreme,
      body: ListView.builder(itemCount: 7,
          itemBuilder: (BuildContext context, int index) {
            var stringToShow = dateFormat.format(dateTime.add(Duration(days: index))).toString();
            var dateToShow = stringToShow[0].toUpperCase() + stringToShow.substring(1);
            var subtitleText = 'Item';

        return ListTile(
          key: Key(index.toString()),
          title: Text(dateToShow, style: itemsTextStyle(),),
          trailing: IconButton(
            icon: Icon(Icons.control_point, color: CustomColors.violetBlue,),
            iconSize: SizeConfig.blockSizeVertical * 5,
          ),
          subtitle: Text(subtitleText, style: subtitleItemsStyle(),),
          onTap: () async {
            var result = await _showTheItems(context, widget.user.id);
            if (result != null) {
              setState(() {
                subtitleText = 'Item... Etiqueta: ${result[0]}';
                print('HERE TEXT HERE ${'Item... Etiqueta: ${result[0]}'}');
              });
            }
          },
        );
          }
      )
    );
  }

如果我放置subtitleText ='Item';在构建方法之外,它可以工作,但是随后更改了所有ListTiles项的字幕文本。如果我将其放在ListView.builder中,尽管“结果”不为null,但它不会反映更改。 我在做什么错了?

0 个答案:

没有答案