【问题标题】:How to set Country code before the phone number with flutter?如何在颤振的电话号码前设置国家代码?
【发布时间】:2019-08-12 07:18:15
【问题描述】:

我正在尝试将国家/地区代码放在电话号码之前。 我使用了country_pickers 包,但我的代码出了点问题, 我的 TextField 的 hintText 可见性消失了,什么也没有显示

这是我的小部件

 Padding(
                      padding: const EdgeInsets.only(top: 5.0),
                        child:  new Container(
                          padding: const EdgeInsets.only(left: 10.0),
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.all(Radius.circular(5.0)),
                          border: Border.all(color: Colors.blue)
                        ),  
                        child: TextField(

                          keyboardType: TextInputType.phone,
                          decoration: InputDecoration(
                            border: InputBorder.none,
                            hintText: "Phone Number",
                            prefix:  CountryPickerDropdown(
                              initialValue: 'in',
                              itemBuilder: _buildDropdownItem,
                              onValuePicked: (Country country) {
                                print("${country.name}");
                              },
                            ),
                          ),
                          onChanged: (value){
                            this.phoneNo=value;
                          },

                        ),  
                      ),
                    ),

这里是国家代码的小部件方法

Widget _buildDropdownItem(Country country) => Container(
        child: Row(
          children: <Widget>[
            CountryPickerUtils.getDefaultFlagImage(country),
            SizedBox(
              width: 8.0,
            ),
            Text("+${country.phoneCode}(${country.isoCode})"),
          ],
        ),
      );

【问题讨论】:

    标签: flutter dart flutter-layout country


    【解决方案1】:

    使用它的正确方法是在 Row 小部件中。前缀在这里不起作用。

               Row(
                   children: <Widget>[
                          Expanded(
                            child: CountryPickerDropdown(
                              initialValue: 'in',
                              itemBuilder: _buildDropdownItem,
                              onValuePicked: (Country country) {
                                print("${country.name}");
                              },
                            ),
                          ),
                          Expanded(
                            child: TextField(
                              keyboardType: TextInputType.phone,
                              decoration: InputDecoration(
                                border: InputBorder.none,
                                hintText: "Phone Number",
                              ),
                              onChanged: (value) {
                                // this.phoneNo=value;
                                print(value);
                              },
                            ),
                          ),
                        ],
                      ),
    

    【讨论】:

      猜你喜欢
      • 2021-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-19
      • 1970-01-01
      • 2015-06-27
      • 2017-11-22
      相关资源
      最近更新 更多