New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Text format support for example 10.000 => 10k #7
Comments
Hi,@RoyalCoder88 last, set |
Thanks a lot @mingsnx I really understand and appreciate your time, and I will give it a try, and I will be appreciated it if you will post a short real example, thanks in advance! |
Hi, @RoyalCoder88 import 'dart:math';
import 'package:animated_digit/animated_digit.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int fractionDigits = 0;
String suffix = "";
late num value = 0;
void _incrementCounter() {
setState(() {
format(Random().nextInt(4294967296));
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
AnimatedDigitWidget(
value: value,
suffix: suffix,
fractionDigits: fractionDigits,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
void format(val) {
if (val < 1000) {
value = val;
fractionDigits = 0;
suffix = "";
} else if (val >= 1000 && val < 1000000) {
// less than 1 million
value = val / 1000;
fractionDigits = 2;
suffix = " K";
} else if (val >= 1000000 && val < (1000000 * 10 * 100)) {
// less than 100 million
value = val / 1000000;
fractionDigits = 2;
suffix = " M";
} else if (val >= (1000000 * 10 * 100) &&
val < (1000000 * 10 * 100 * 100)) {
// less than 100 billion
value = val / (1000000 * 10 * 100);
fractionDigits = 2;
suffix = " G";
} else if (val >= (1000000 * 10 * 100 * 100) &&
val < (1000000 * 10 * 100 * 100 * 100)) {
// less than 100 trillion
value = val / (1000000 * 10 * 100 * 100);
fractionDigits = 2;
suffix = " T";
} else {
value = val;
fractionDigits = 0;
suffix = "";
}
}
}
|
Thanks a lot, @mingsnx works like a charm❤️ |
Hi @mingsnx,
Thanks for your great package, can you please add support for formatting the text numbers for example like this:
or guide me please how to achieve this, thanks in advance!
The text was updated successfully, but these errors were encountered: