【问题标题】:Can i use if statement to switch between locations?我可以使用 if 语句在位置之间切换吗?
【发布时间】:2019-11-24 00:43:48
【问题描述】:

我希望这能满足所有 Flutter 开发者的需求。

我正在开发一个应用程序,我遇到了几个问题。这是我的问题。

我想在 selectedLocations 之间切换,它会显示与该位置相关的表格供用户填写。

以下是图片中的位置,代码如下。

    void switchSelectedCountry(selection) {
    events = selection;
    scoops = selection;
    setState(() {
      _selectedLocation = selection;
    });
  }

formField: FixDropdownButtonFormField(
                      value: _selectedLocation,
                      hint: Text('Select'),
                      items: <String>['Scoops', 'Events',].map((String value) {
                        return new FixDropdownMenuItem<String>(
                          value: value,
                          child: new Text(value),
                        );
                      }).toList(),
                      onChanged: (newValue) {
                        setState(() {
                          _selectedLocation = newValue;
                        });
                      },
                    ),
                  ),

【问题讨论】:

  • 在您的 build 方法中放置一个 if 块。
  • 告诉我,我一直在尝试不工作,也许我做错了
  • 展示你的尝试。

标签: if-statement flutter dart switch-statement mobile-development


【解决方案1】:

您可以检查在下拉列表中选择了哪个值,并根据该值显示特定的表格, 例如,

if(dropdownValue == 'events') Column(
                  children: <Widget>[
                    TextFormField(
                      controller: yearController,
                      decoration: InputDecoration(
                        labelText: AppLocalizations.of(context).translate(
                            'year'),
                        hintStyle: TextStyle(fontSize: 10),
                        filled: true,
                      ),
                      keyboardType: TextInputType.number,
                    ),
                  ],
                ),
if(dropdownValue == 'Scoops') Sizebox(RETURN YOU WIDGET)

【讨论】:

    猜你喜欢
    • 2011-08-06
    • 1970-01-01
    • 1970-01-01
    • 2015-01-08
    • 2017-08-20
    • 1970-01-01
    • 1970-01-01
    • 2020-11-09
    • 2021-07-22
    相关资源
    最近更新 更多