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

插件详情v1.3.0

message_segment_calculator

高效计算支持 GSM 和 UCS-2 编码的消息段数。适用于需要精确管理短信长度和成本的应用程序。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
299
喜欢数
8
Pub 分数
160

安装插件

flutter pub add message_segment_calculator

插件介绍

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

message_segment_calculator 包能够高效地确定给定消息所需的短信段数,支持 GSM 和 UCS-2 字符编码。它可精确控制消息长度,并通过准确计算消息将占用的段数来帮助管理短信成本。适用于发送短信通知、警报或营销消息的应用程序,其中交付效率和成本至关重要。该包轻量且兼容多个平台,包括 Android、iOS、Web、macOS、Windows 和 Linux。

适合场景

  • 短信费用估算
  • 消息长度验证
  • 批量短信管理
  • 通知系统
  • 遵守短信限制
  • 跨平台短信应用

主要特点

  • 支持 GSM 和 UCS-2 编码
  • 准确的分段计数
  • 跨平台兼容性
  • 轻便且快速
  • 实时长度计算
  • 正确处理特殊字符

适合对象

  • 消息应用
  • 电信工具
  • 营销平台
  • 企业通知系统
  • 需要短信费用控制的应用

使用建议

  • 需要手动处理长消息
  • 不发送消息——仅计算分段
  • 编码选择必须根据内容来确定
  • 不适用于MMS或多媒体消息
  • 仅限短信特定用例

原始 README

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

SMS Segment Calculator

The SMS Segment Calculator is a Dart package designed to help developers accurately calculate the number of SMS segments required for messages. It supports both GSM-7 and UCS-2 encoding standards, providing a robust solution for applications that involve SMS messaging. The package ensures cost-effective messaging by optimizing message segmentation and encoding.

Key Features

  • Accurate SMS Segmentation: Automatically calculates the number of segments needed for a given SMS message based on its content and required encoding (GSM-7 or UCS-2).
  • Support for Special Characters and Emojis: Detects texts containing emojis or special characters and switches to UCS-2 encoding when necessary.
  • Comprehensive Encoding Management: Handles the encoding of individual characters and manages their conversion to the appropriate encoding format.
  • Cost Management: Provides precise segment counts for budgeting and planning SMS costs effectively.
  • Line Break Handling: Identifies different line break styles and issues warnings if incompatible styles are detected.

Installation

To integrate the SMS Segment Calculator into your Dart or Flutter project, add the following dependency to your pubspec.yaml file:

dependencies:
  message_segment_calculator: ^1.1.0



## Usage

import 'package:flutter/material.dart';
import 'package:message_segment_calculator/src/segmented_message.dart';

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

/// The root widget of the application.
class App extends StatelessWidget {
  const App({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: MessageSegmentCalculatorWidget(),
    );
  }
}

/// A stateful widget that provides a UI for calculating message segments.
class MessageSegmentCalculatorWidget extends StatefulWidget {
  const MessageSegmentCalculatorWidget({super.key});

  @override
  State<MessageSegmentCalculatorWidget> createState() =>
      _MessageSegmentCalculatorWidgetState();
}

/// The state class for [MessageSegmentCalculatorWidget].
class _MessageSegmentCalculatorWidgetState
    extends State<MessageSegmentCalculatorWidget> {
  final textEditingController = TextEditingController();
  SegmentedMessage? segmentedMessage;

  @override
  void dispose() {
    textEditingController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Message Segment Calculator'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(10),
        child: Column(
          children: [
            const Text('Enter text'),
            const SizedBox(height: 10),
            TextFormField(
              decoration: const InputDecoration(),
              controller: textEditingController,
              onChanged: (value) {
                setState(() {
                  segmentedMessage = SegmentedMessage(value);
                });
              },
            ),
            const SizedBox(height: 10),
            Text('Number of characters: ${segmentedMessage?.numberOfCharacters}'),
            Text('Number of segments: ${segmentedMessage?.segmentsCount}'),
            Text('Number of Unicode scalars: ${segmentedMessage?.numberOfUnicodeScalars}'),
            Text('Message size in bits: ${segmentedMessage?.messageSize}'),
            Text('Total size in bits: ${segmentedMessage?.totalSize}'),
          ],
        ),
      ),
    );
  }
}




### Key Additions:
- **Detailed Descriptions**: Each class is explained to clarify its role in the package.
- **Usage Example**: Shows a practical example to help developers quickly understand how to use the package.
- **Installation Instructions**: Guides users on how to add the package to their project.
- **Contribution Guidelines**: Encourages contributions and provides a link to the issues page.

This README provides a comprehensive overview, making it easier for users to understand and use the package effectively.

所属分类

源码仓库

使用此插件的项目

暂无相关数据。