Lines pre-filled with spaces in Dart

A fairly simple question:

I would like to create a line initialized with a dynamically resolved number of spaces in the dart. Here is something that worked:

String spaces(n) { var result = new List<int>.filled(n+1,32); return new String.fromCharCodes(result); } 

Is there a better way?

+4
source share
2 answers

Well, you can always fill in the list with spaces and join them:

 String spaces(n) => new List.filled(n + 1, ' ').join(); 
+2
source

This seems rather concise and easy to interpret:

 ''.padRight(32, ' ') 

Try it in DartPad

0
source

Source: https://habr.com/ru/post/1493906/


All Articles