generateName() now returns strings with capitalized words

This commit is contained in:
Tanner Silva 2020-10-24 13:50:12 -05:00
parent 082a5f0b6c
commit cd5426da81

View file

@ -2,17 +2,23 @@ import 'dart:math';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
extension StringExtension on String {
String capitalized() {
return "${this[0].toUpperCase()}${this.substring(1)}";
}
}
Future<String> generateName() async { Future<String> generateName() async {
final randomThing = Random(); final randomThing = Random();
final adjectiveStringRaw = final adjectiveStringRaw =
await rootBundle.loadString('assets/text/Wallet_Adjectives.txt'); await rootBundle.loadString('assets/text/Wallet_Adjectives.txt');
final nounStringRaw = final nounStringRaw =
await rootBundle.loadString('assets/text/Wallet_Nouns.txt'); await rootBundle.loadString('assets/text/Wallet_Nouns.txt');
final adjectives = List<String>.from(adjectiveStringRaw.split('\n')); final adjectives = List<String>.from(adjectiveStringRaw.split('\n'));
final nouns = List<String>.from(nounStringRaw.split('\n')); final nouns = List<String>.from(nounStringRaw.split('\n'));
final chosenAdjective = adjectives[randomThing.nextInt(adjectives.length)]; final chosenAdjective = adjectives[randomThing.nextInt(adjectives.length)];
final chosenNoun = nouns[randomThing.nextInt(nouns.length)]; final chosenNoun = nouns[randomThing.nextInt(nouns.length)];
final returnString = chosenAdjective + ' ' + chosenNoun; final returnString =
chosenAdjective.capitalized() + ' ' + chosenNoun.capitalized();
return returnString; return returnString;
} }