mingsnx / animated_digit

A scrolling digit animation widget
MIT License
37 stars 17 forks source link
animated animated-number animation dart flutter number

flutter dart

English | ไธญๆ–‡็ฎ€ไฝ“

animated_digit

Scroll animation numbers widget, any number that need animation effects and easy to use.

Example GIF

Usage

๐Ÿšด๐Ÿป Easy Show

// only show
AnimatedDigitWidget(
  value: 9999
),

๐Ÿš„ Easy Show & State

// simple state control 
int value = 9999;
AnimatedDigitWidget(
  value: value
  textStyle: TextStyle(color: Colors.pink),
),
setState((){
  value = 191919;
});

๐ŸŽก Controller

Built-in accuracy calculation


AnimatedDigitController _controller = AnimatedDigitController(10240.987);

AnimatedDigitWidget( controller: _controller, textStyle: TextStyle(color: Colors.pink), fractionDigits: 2, // number of decimal places reserved, not rounded enableSeparator: true, // like this 10,240.98 ), // UI Result => 10,240.98

// increment _controller.addValue(1314);

// minus _controller.minusValue(1314); // from v3.1.0 added

// times _controller.timesValue(1314); // from v3.1.0 added

// divide _controller.divideValue(1314); // from v3.1.0 added

// reset _controller.resetValue(1314);

// last _controller.dispose();


### ๐Ÿ–ผ UI Effect Image & ๐Ÿ’ป Code Example

[![7Dcj6f.png](https://s4.ax1x.com/2022/01/19/7Dcj6f.png)](https://imgtu.com/i/7Dcj6f)
```dart
AnimatedDigitWidget(
  value: 12531.98, // or use controller
),

7DcznS.png

AnimatedDigitWidget(
  value: 12531.98, // or use controller
  enableSeparator: true,
),

7DcX1P.png

AnimatedDigitWidget(
  value: 12531.98, // or use controller
  fractionDigits: 2,
  enableSeparator: true,
),

7DcOpt.png

SingleDigitProvider(
  data: SingleDigitData(
    useTextSize: true,
    builder: (size, value, isNumber, child) {
      return isNumber ? child : FlutterLogo();
    },
  ),
  child: AnimatedDigitWidget(
    value: 12531.98, // or use controller
    textStyle: TextStyle(color: Colors.pink[200], fontSize: 30),
    separateLength: 1,
    separateSymbol: "#",
    enableSeparator: true,
  ),
),

7DcvX8.png

AnimatedDigitWidget(
  value: 12531.98, // or use controller
  textStyle: TextStyle(color: Colors.orangeAccent.shade700, fontSize: 30),
  fractionDigits: 2,
  enableSeparator: true,
  separateSymbol: "ยท",
  separateLength: 3,
  decimalSeparator: ",",
  prefix: "\$",
  suffix: "โ‚ฌ",
),

โœŒ If you want to change color based on value

The add a ValueColor object to valueColors, which is an array, you can add more ...๏ผŒbut always take the last eligible

int value = 9999; // or use Controller.value
AnimatedDigitWidget(
  value: value,
  textStyle: TextStyle(
    color: Colors.orange[200],
    fontSize: 30,
  ),
  valueColors: [
    ValueColor(
      //When value <= 0 , the color changes to red
      condition: () => value <= 0,
      color: Colors.red,
    ),
    // you can add more ...๏ผŒbut always take the last eligible.
  ],
),

๐Ÿณ Widget Params & Documentation

๐Ÿš€ Required Params

โš ๏ธ value and controller cannot be both null. โš ๏ธ controller has higher priority.

  • controller - digit controller, The displayed number can be controlled via addValue and resetValue.

๐Ÿ‘ TextStyle And BoxStyle Setting

๐Ÿ‡ Int Type(default) Or Decimal Type Setting

The default 0 means an integer, when it is a decimal, if the value is less than the fractionDigits, it will be filled with 0 to the right, and the truncation method is used, so there is no rounding.


๐Ÿ“ Numbers Free Style Setting

๐Ÿฅ Scroll Animation Setting

๐ŸŽ Digital Size Scheme Setting

๐Ÿ’ Number prefix and suffix Setting

Thanks

number_precision