以阿拉伯语格式显示数字 dart

uqjltbpv  于 2023-06-19  发布在  其他
关注(0)|答案(4)|浏览(164)

如何在Flutter应用程序中显示阿拉伯语格式的数字?
而不是显示数字为1,2,3我需要显示它们为,,
我尝试使用NumberFormat类,但它不起作用。
Flutter医生:

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel dev, v0.8.2, on Microsoft Windows [Version 10.0.17134.345], locale ar-SA)
[√] Android toolchain - develop for Android devices (Android SDK 28.0.2)
[√] Android Studio (version 3.1)
[√] IntelliJ IDEA Community Edition (version 2018.2)
[!] VS Code, 64-bit edition (version 1.27.2)
[√] Connected devices (2 available)

! Doctor found issues in 1 category.

示例:

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

import 'package:intl/intl.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      locale: Locale("ar"),
      home: new Scaffold(
        body: new Center(
          child: new Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              new Text(NumberFormat().format(1)),
              new Text(NumberFormat().format(2)),
              new Text(NumberFormat().format(3)),
            ],
          ),
        ),
      ),
    );
  }
}

dsf9zpds

dsf9zpds1#

Adding支持阿拉伯数字的font解决了这个问题。

y53ybaqx

y53ybaqx2#

String convertToArabicNumber(String number) {
  String res = '';

  final arabics = ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'];
  number.characters.forEach((element) {
     res += arabics[int.parse(element)];
  });

/*   final latins = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; */
  return res;
}
cigdeys3

cigdeys33#

此软件包将为您执行此操作arabic_numbershttps://pub.dev/packages/arabic_numbers

dz6r00yl

dz6r00yl4#

在intl包中使用EG(埃及)作为国家代码可以解决这个问题,而无需添加新字体。

import 'package:intl/intl.dart';

void main() {
   print(NumberFormat('#.##', 'ar_EG').format(25.46));
}

输出:٢٥٫٤٦

相关问题