Flutter dart create random strings
Create a string util file with the following, StringUtil.dart
import 'dart:math'; const _chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890'; Random _rnd = Random(); String getRandomString(int length) => String.fromCharCodes( Iterable.generate( length, (_) => _chars.codeUnitAt(_rnd.nextInt(_chars.length)) ) );
Use the getRandomString in other dart files like the following. This creates 20 random strings, each string with a length of at least 5 and at most 20.
import 'StringUtil.dart'; final randomStringList = List.generate(20, (i) => getRandomString(5 + Random().nextInt(15)));
Search within Codexpedia
Custom Search
Search the entire web
Custom Search
Related Posts