You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何禁用intl_phone_number_input的国家选择功能,禁止切换国家?

解决方案

要实现点击国旗不弹出国家选择面板、无法切换其他国家的效果,只需对InternationalPhoneNumberInput组件做两处关键修改:


1. 禁用国家选择器的交互能力

在selectorConfig中添加enabled: false,直接关闭选择器的点击响应:

selectorConfig: const SelectorConfig(
  selectorType: PhoneInputSelectorType.BOTTOM_SHEET,
  enabled: false, // 关闭选择器交互
),

2. 锁定国家值不可修改

设置ignoreBlank: false,并确保initialValue是固定的目标国家号码对象,彻底阻断修改国家的路径:


修改后的完整代码:

Stack(
  children: [
    InternationalPhoneNumberInput(
      onInputChanged: (value) {},
      cursorColor: ColorConstants.blackColor,
      formatInput: false,
      initialValue: number, // 确保此处为固定的目标国家号码实例
      textFieldController: controller,
      ignoreBlank: false, // 锁定国家值不可变更
      selectorConfig: const SelectorConfig(
        selectorType: PhoneInputSelectorType.BOTTOM_SHEET,
        enabled: false, // 禁用选择器点击
      ),
      inputDecoration: InputDecoration(
          contentPadding: EdgeInsets.only(
            bottom: 15.h,
          ),
          border: InputBorder.none,
          hintText: TextConstants.phoneNumber,
          hintStyle: TextStyle(color: ColorConstants.customGreyColor, fontSize: 16.sp)),
    ),
    Positioned(
        left: 92.w,
        top: 5.h,
        child: Container(
          height: 40.h,
          width: 1.w,
          color: Colors.grey.shade400,
        ))
  ],
),

最终效果

  • 点击国旗区域无任何响应,国家选择弹窗不会弹出
  • 国旗与国家代码将固定为initialValue设置的内容,无法切换到其他国家

内容的提问来源于stack exchange,提问作者Atakan Sever

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 13:37:15