Buscar pacotes, repositórios e categorias de apps

Detalhes do pacotev3.0.0

number_display

Para exibir dados em um componente com largura limitada, esta função ajudará inteligentemente a converter números para um determinado comprimento de gráfico. Simples, direto, flexível e preciso.

AndroidiOSWebmacOSWindowsLinux
Downloads em 30 dias
17,4 mil
Curtidas
77
Pontos Pub
160

Instalar pacote

flutter pub add number_display

Visão geral do pacote

Orientação gerada a partir de informações públicas. Apenas para referência.

O pacote number_display fornece uma maneira inteligente e flexível de formatar e exibir números em componentes de interface com largura limitada. Ele ajusta automaticamente a representação numérica — como usar abreviações (por exemplo, K, M) ou truncar decimais — para caber em espaços restritos, mantendo legibilidade e precisão. Projetado para simplicidade e precisão, é ideal para painéis, cartões de dados e qualquer interface onde o espaço seja limitado, mas a clareza seja essencial. O pacote funciona em todas as principais plataformas e se integra perfeitamente aos aplicativos Flutter.

Casos de uso

  • Exibindo números grandes em interfaces compactas
  • Formatar métricas em painéis
  • Otimizando espaço em cartões de dados
  • Atualizações em tempo real de números em áreas limitadas
  • Criando rótulos numéricos responsivos

Principais recursos

  • Abreviação inteligente de números (K, M, B)
  • Retirada automática de casas decimais
  • formatação com base na largura
  • Compatibilidade multiplataforma
  • Integração simples da API
  • Precisão configurável

Indicado para

  • Aplicativos de visualização de dados
  • Interfaces de painel
  • Ferramentas de análise para mobile e web
  • UIs críticas para desempenho
  • Desenvolvedores em busca de formatação numérica minimalista

Considerações

  • Pode exigir ajustes para restrições exatas de layout
  • Limitado à formatação de valores numéricos
  • Não adequado para dados não numéricos
  • Depende da largura de tela disponível
  • Melhor usado em contextos de layout estático ou previsível

README original

Snapshot do README original do repositório-fonte vinculado. Consulte o repositório para o conteúdo mais recente.

number_display

Display number smartly within a certain length.

final display = createDisplay(length: 8);

display(-254623933.876)    // result: -254.62M

The conversion follow this rules:

  • result char length will never overflow length
  • replace null, nan or infinity to placeholder
  • use locale string with commas ( 1,234,222 ) as possible ( configurable )
  • trim number with units ( 1.23k ) when length is limited
  • convert scientific notation ( 1.23e+4 ) to friendly form
  • when omitting decimals, you can change the rounding type, default to 'round'
  • no decimal tailing zeros
  • no float error

It also has a JavaScript version

Install

Add this to your package's pubspec.yaml file:

dependencies:
  number_display: # latest version

Details see pub.dev

Usage

In version 2.* we only export a createDisplay function for users to custom their display function. So the real display function has only one input: value . This separates the configuration and usage, which is more simple and clear.

import 'package:number_display/number_display.dart';

final display = createDisplay(
  length: 8,
  decimal: 0,
);

print(display(data));

The complete configuration params are listed in the next section .

If the length overflow, the trimming rules in order are:

  • omit the locale commas
  • slice the decimal by the room left
  • trim the integer with number units ( k, M, G, T, P )
  • if the length is >= 5, any number can be trimmed within it. If it's less than 5 and input number is too long, display will throw an exception.

Conversion examples:

createDisplay();

null => ''
double.nan => ''

-123456789.123456789 => '-123.457M'
'123456' => '123,456'
-1.2345e+5 => '-123,450'

With some configs:

createDisplay(
  separator: false,
  placeholder: '--'
);

null => '--'
123456 => '123456'

Locale

By setting the seperator and decimalPoint , numbers can be any locale form: '4.623.933,8'.

Configurations

length

( default: 9 )

The max length the result would be. length should no less then 5 so that any number can display ( say -123000 ) after trim.

decimal

( default: equals to length )

The max decimal length. Note that this is only a constraint. The final precision will be calculated by length, and less than this param. This param is the same as 'length' by default, witch means no additional limit. There will be no decimal trailing zeros.

placeholder

( default: '' )

The result when the input is neither string nor number, or the input is NaN, Infinity or -Infinity. It will be sliced if longer than length param.

separator

( default: ',' )

Set the locale string separators ( 1,234,222 ), if there are rooms. Set it to null if you don't need any. Only the first char is kept.

decimalPoint

( default: '.' )

Set the locale string decimal point. Only the first char is kept.

roundingType

( default: RoundingType.round )

The rounding type when omitting decimals, enum in RoundingType.round, RoundingType.floor or RoundingType.ceil.

units

( default: ['k', 'M', 'G', 'T', 'P'] )

The digit units to use. Only the first char is kept for each unit. If the property is set to null or too short, it will fallback to the default.

Blogs

Displaying Numbers in Frontend

Categorias

Repositório-fonte

Projetos que usam este pacote

Ainda não há dados.