Skip to content

Commit

Permalink
generate a random name for new user
Browse files Browse the repository at this point in the history
  • Loading branch information
tangenta committed Jul 28, 2023
1 parent f4b0c5b commit ca92b30
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 14 additions & 2 deletions lib/controller/settings.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:math';

import 'package:dart_openai/dart_openai.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -191,10 +193,20 @@ class SettingsController extends GetxController {
setServerlessCmd(cmd);
}

String generateRandomNickname() {
var random = Random();
var index = random.nextInt(999999);
final indexStr = index.toString().padLeft(6, '0');
return "Moyu-$indexStr";
}

getNicknameFromPreferences() async {
GetStorage _box = GetStorage();
String nickname = _box.read('nickname') ?? "Moyu";
setNickname(nickname);
var name = _box.read('nickname');
if (name == null || name.isEmpty) {
name = generateRandomNickname();
}
setNickname(name);
}

void setOpenAiBaseUrl(String baseUrl) {
Expand Down
2 changes: 0 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ import 'package:Moyubie/components/setting.dart';
import 'package:Moyubie/repository/tags.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'package:Moyubie/repository/tags.dart';
import 'package:Moyubie/utils/tag_collector.dart';
import 'package:sqflite_common_ffi_web/sqflite_ffi_web.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
import 'package:flutter/foundation.dart' show kIsWeb;
import 'dart:io' show Platform;
import 'package:path/path.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';

Expand Down

0 comments on commit ca92b30

Please sign in to comment.