visit
The following tutorial builds upon the Startup Name Generator app outlined in the Write your first Flutter app tutorial on . If you haven’t yet, it is recommended to follow that tutorial first.
flutter pub add statsig
void main() async { // <- added async
final user = StatsigUser(userId: "a-user");
final options = StatsigOptions(initTimeout: 1);
await Statsig.initialize("client-xxxx", user, options);
runApp(const MyApp());
}
final name = _suggestions[index].asPascalCase; // moved out of title: Text(
return ListTile(
// -- New
onTap: () {
Statsig.logEvent("selected_name", stringValue: name);
},
// --
title: Text(
name,
style: _biggerFont,
),
trailing: trailing,
);
class _RandomWordsState extends State<RandomWords> {
final _suggestions = <WordPair>[];
final _emojis = <String>[]; // <-- New
...
Widget build(BuildContext context) {
return ListView.builder(
padding: const EdgeInsets.all(16.0),
itemBuilder: (context, i) {
...
// -- New
Text? trailing;
var emoji = "";
var experiment = Statsig.getExperiment("emoji_logos_experiment");
if (experiment.get("should_display_emojis", false) == true) {
while (_emojis.length <= i) {
const minHex = 0x1F300;
const maxHex = 0x1F3F0;
var random = (Random().nextInt((maxHex - minHex).abs() + 1) +
min(minHex, maxHex))
.toInt();
_emojis.add(String.fromCharCode(random));
}
emoji = _emojis[i];
trailing = Text(
emoji,
style: _massiveFont,
);
}
// --
final name = _suggestions[index].asPascalCase;
return ListTile(
title: Text(
name,
style: _biggerFont,
),
trailing: trailing, // <-- New
);
},
);
}