搜索插件、代码仓与 APP 分类

插件详情v1.0.4

ccp_dialog

CCP Dialog 包用于在对话框和底部表单中显示国家代码、旗帜、货币和货币ISO。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
80
喜欢数
28
Pub 分数
140

安装插件

flutter pub add ccp_dialog

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

CCP Dialog 是一个 Flutter 包,旨在以对话框或底部弹出菜单的形式显示国家信息,如国家代码、国旗、货币和货币 ISO。它简化了在应用程序中集成国家选择功能的过程,为用户提供简洁且可自定义的用户界面来选择国家。适用于需要地区特定数据输入的国际化应用,支持 Android、iOS、Web、macOS、Windows 和 Linux 等多个平台。该包通过在选择过程中提供旗帜和货币详情等视觉提示,提升了用户体验。

适合场景

  • 国际应用入门
  • 带国家选择的电话号码输入
  • 货币感知表单输入
  • 多区域电子商务应用
  • 旅行和物流应用

主要特点

  • 显示国家旗帜和代码
  • 显示货币和货币ISO
  • 支持对话框和底部弹出菜单模式
  • 跨平台兼容性
  • 可自定义的 UI 元素
  • 通过 pub add 轻松集成

适合对象

  • 开发全球应用的开发者
  • 需要国家选择的应用
  • 需要区域数据的表单构建器
  • 具有本地化需求的移动和Web应用
  • 以用户体验为中心的界面

使用建议

  • 需要互联网以获取完整的国家数据(如果为动态)
  • 可能需要针对非英文地区进行自定义
  • 限于预定义的国家列表
  • 大数据集的性能影响
  • 不适用于仅离线使用的情况

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Flutter CCP dialog

Features

Flexible CCP dialog for getting Country code, Calling code, isoCode and Currency in Dialog and Bottom sheet.


# Installation
  1. Add the latest version of package to your pubspec.yaml (and dart pub get):
dart
  dependencies:
    flutter:
      sdk: flutter
    ccp_dialog: any
  1. Import the package and use it in your App.

Usage Example

import 'package:ccp_dialog/country_picker/flutter_country_picker.dart';

Example

import 'package:ccp_dialog/country_picker/flutter_country_picker.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Country Piker Dialog'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String countryCode ="+91";
  Country selectedCountry = Country.IN;

  _updateCountry(Country country){
    selectedCountry = country;
    countryCode = "+${country.dialingCode}";
    setState(() {

    });
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'Select Country',
            ),
            Container(
                height: 45,
                 width: MediaQuery.of(context).size.width/2,
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(30),
                    color: Colors.white),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                   CountryPicker(
                      selectedCountry: selectedCountry,
                      dense: true ,
                       //displays arrow, true by default
                      showLine: true,
                       //displays line, false by default If dense true Line not show
                      showFlag: false,
                       //displays flag, true by default
                         showFlagCircle: true,
                       //displays flagCircle, false by default
                      dialingCodeTextStyle:const TextStyle(fontSize: 18),
                      showDialingCode: true,
                      //displays dialing code, false by default
                      showName: false,
                       //displays Name, true by default
                      withBottomSheet: true,
                      //displays country name, true by default
                      showCurrency: false,
                      //eg. 'British pound'
                      showCurrencyISO: false,
                      onChanged:_updateCountry
                   ),
                   const Text('9876541230',style: TextStyle(fontSize: 20),),
                ]))
          ],
        ),
      ),
    );
  }
}

Using Getx

Example:-

  Rx<Country> selectedCountry = Country.IN.obs;
  var countryCode = "+91".obs;
  updateCountry(Country country)
  {
      selectedCountry.value = country;
      countryCode.value = "+" + country.dialingCode.toString();
  }
  Obx(
  () => CountryPicker(
  selectedCountry: _controller.selectedCountry.value,
  dense: false,
  showFlag: false,
  showFlagCircle: true,
  showDialingCode: true,                                      
  showName: false,
  showCurrency: false,                                         
  showCurrencyISO: false,
  onChanged: _controller.updateCountry
  ),
 )

How to get Default Country

Country? country =  await getCountryByCountryCode(Get.context!, '+91');

Future<Country?> getCountryByCountryCode(BuildContext context, String countryCode) async {
const list = Country.ALL;
return list.firstWhere((element) => element.dialingCode == countryCode);
}

simulator_screenshot_24795F01-DE84-46B5-977D-C23CED7D1EE1

Simulator Screen Shot - iPhone 14 - 2023-05-31 at 15 11 38

Simulator Screen Shot - iPhone 14 - 2023-05-31 at 15 12 12

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

所属分类

源码仓库

使用此插件的项目

暂无相关数据。