首页 > 解决方案 > Flutter:前导字母而不是 ListTile 的图标

问题描述

我认为这张图片对我想要存档的内容是不言自明的:

在此处输入图像描述

ListTile(
              // leading: Icon(Icons.attach_money), <-- this works but I need the currency icon dynamic
              leading: Text(
                "€&quot;,
                style: TextStyle(
                  fontSize: 20,
                ),
              ),
              title: Text(translate('options.currency')),
              subtitle: Text(translate('options.currency_help')),
              onTap: () {
                showCurrencyPicker(
                  context: context,
                  searchHint: translate('options.search_currency'),
                  showFlag: true,
                  showCurrencyName: true,
                  showCurrencyCode: true,
                  onSelect: (Currency currency) {
                    print('Select currency: ${currency.name}');
                  },
                  favorite: [_options['currency']],
                );
              },
            ),

我可以展示它,但我不确定如何正确居中

标签: flutterflutter-layout

解决方案


您可以添加一个 SizedBox,并像这样放置文本

ListTile(
            leading: SizedBox(
              height: 100.0, //desired height
              width: 100.0, //desired width
              child: Text("£", //any currency you want
              style: TextStyle(
                fontSize: 20,
                ),
                ),
              ),

            title: ...,
            subtitle: ...
        ),

推荐阅读