Flutter String格式化

任玉刚 2019-07-01

请看原文: http://tryenough.com/flutter-stringformat

在Android和iOS平台都有相应的方法进行字符串的格式化,但是在flutter中却没有直接提供

在flutter上可以借助一个插件来进行格式化:

sprintf

import 'package:sprintf/sprintf.dart';

例子

import 'package:sprintf/sprintf.dart';

void main() {
    print(sprintf("%04i", [-42]));
    print(sprintf("%s %s", ["Hello", "World"]));
    print(sprintf("%#04x", [10]));

    double seconds = 5.0;
    String name = 'Dilki';
    List<String> pets = ['Cats', 'Dogs'];

    String sentence1 = sprintf('Sends %2.2f seconds ago.', [seconds]);
    String sentence2 = sprintf('Harry likes %s, I think %s likes %s.', [pets[0], name, pets[1]]);

    print(sentence1);
    print(sentence2);

  }

请看原文: http://tryenough.com/flutter-stringformat

相关推荐