mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-01-15 14:28:40 +00:00
search username
This commit is contained in:
parent
7fd33ab697
commit
d7dcd2ae6b
3 changed files with 58 additions and 10 deletions
|
|
@ -10,6 +10,8 @@
|
||||||
"chatsTitle": "Chats",
|
"chatsTitle": "Chats",
|
||||||
"searchUsernameInput": "Username",
|
"searchUsernameInput": "Username",
|
||||||
"searchUsernameTitle": "Search username",
|
"searchUsernameTitle": "Search username",
|
||||||
|
"searchUsernameNotFound": "Username not found",
|
||||||
|
"searchUsernameNotFoundLong": "\"{username}\" is not a twonly user. Please check the username and try again.",
|
||||||
"errorUnknown": "An unexpected error has occurred. Please try again later.",
|
"errorUnknown": "An unexpected error has occurred. Please try again later.",
|
||||||
"errorBadRequest": "The request could not be understood by the server due to malformed syntax. Please check your input and try again.",
|
"errorBadRequest": "The request could not be understood by the server due to malformed syntax. Please check your input and try again.",
|
||||||
"errorTooManyRequests": "You have made too many requests in a short period. Please wait a moment before trying again.",
|
"errorTooManyRequests": "You have made too many requests in a short period. Please wait a moment before trying again.",
|
||||||
|
|
|
||||||
|
|
@ -61,16 +61,14 @@ Uint8List getRandomUint8List(int length) {
|
||||||
return randomBytes;
|
return randomBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Result> addNewUser(String username) async {
|
Future<bool> addNewUser(String username) async {
|
||||||
final res = await apiProvider.getUserData(username);
|
final res = await apiProvider.getUserData(username);
|
||||||
|
|
||||||
// if (res.isSuccess) {
|
if (res.isSuccess) {
|
||||||
// print("Got user_id ${res.value}");
|
print("Found user: ${res.value}");
|
||||||
// final userData = UserData(
|
}
|
||||||
// userId: res.value.userid, username: username, displayName: username);
|
|
||||||
// }
|
|
||||||
|
|
||||||
return res;
|
return res.isSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Result> createNewUser(String username, String inviteCode) async {
|
Future<Result> createNewUser(String username, String inviteCode) async {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,10 @@
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
import 'package:logging/logging.dart';
|
||||||
|
import 'package:twonly/src/utils.dart';
|
||||||
|
import 'package:twonly/src/views/register_view.dart';
|
||||||
|
|
||||||
class SearchUsernameView extends StatefulWidget {
|
class SearchUsernameView extends StatefulWidget {
|
||||||
const SearchUsernameView({super.key});
|
const SearchUsernameView({super.key});
|
||||||
|
|
@ -11,6 +16,38 @@ class SearchUsernameView extends StatefulWidget {
|
||||||
class _SearchUsernameView extends State<SearchUsernameView> {
|
class _SearchUsernameView extends State<SearchUsernameView> {
|
||||||
final TextEditingController searchUserName = TextEditingController();
|
final TextEditingController searchUserName = TextEditingController();
|
||||||
|
|
||||||
|
bool _isLoading = false;
|
||||||
|
|
||||||
|
Future _addNewUser(BuildContext context) async {
|
||||||
|
Timer timer = Timer(Duration(milliseconds: 500), () {
|
||||||
|
setState(() {
|
||||||
|
_isLoading = true;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
final status = await addNewUser(searchUserName.text);
|
||||||
|
|
||||||
|
timer.cancel();
|
||||||
|
// loaderDelay.timeout(Duration(microseconds: 0));
|
||||||
|
setState(() {
|
||||||
|
_isLoading = false;
|
||||||
|
});
|
||||||
|
Logger("search_user_name").warning("Replace instead of pop");
|
||||||
|
|
||||||
|
if (context.mounted) {
|
||||||
|
if (status) {
|
||||||
|
Navigator.pop(context);
|
||||||
|
} else if (context.mounted) {
|
||||||
|
showAlertDialog(
|
||||||
|
context,
|
||||||
|
AppLocalizations.of(context)!.searchUsernameNotFound,
|
||||||
|
AppLocalizations.of(context)!
|
||||||
|
.searchUsernameNotFoundLong(searchUserName.text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
InputDecoration getInputDecoration(hintText) {
|
InputDecoration getInputDecoration(hintText) {
|
||||||
|
|
@ -42,15 +79,26 @@ class _SearchUsernameView extends State<SearchUsernameView> {
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.symmetric(horizontal: 10),
|
padding: EdgeInsets.symmetric(horizontal: 10),
|
||||||
child: TextField(
|
child: TextField(
|
||||||
onSubmitted: (value) {
|
onSubmitted: (_) {
|
||||||
print(value);
|
_addNewUser(context);
|
||||||
},
|
},
|
||||||
|
controller: searchUserName,
|
||||||
decoration: getInputDecoration(
|
decoration: getInputDecoration(
|
||||||
AppLocalizations.of(context)!.searchUsernameInput))),
|
AppLocalizations.of(context)!.searchUsernameInput))),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 40),
|
||||||
|
if (_isLoading) const Center(child: CircularProgressIndicator())
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
floatingActionButton: Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 30.0),
|
||||||
|
child: FloatingActionButton(
|
||||||
|
onPressed: () {
|
||||||
|
_addNewUser(context);
|
||||||
|
},
|
||||||
|
child: const Icon(Icons.arrow_right_rounded),
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue