在Android和iOS平臺都有相應的方法進行字符串的格式化,可是在flutter中卻沒有直接提供bash
在flutter上能夠藉助一個插件來進行格式化:ui
sprintfspa
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);
}
複製代碼