|
|
@@ -9,20 +9,18 @@ class AddFriend extends StatefulWidget {
|
|
|
}
|
|
|
|
|
|
class _AddFriendState extends State<AddFriend> {
|
|
|
- String _friendSharedId = "";
|
|
|
+ late final TextEditingController _controller;
|
|
|
|
|
|
- void _onTextUpdate(String newFriendSharedId) {
|
|
|
- setState(() {
|
|
|
- _friendSharedId = newFriendSharedId;
|
|
|
- });
|
|
|
+ @override
|
|
|
+ void initState() {
|
|
|
+ _controller = TextEditingController();
|
|
|
+ super.initState();
|
|
|
}
|
|
|
|
|
|
void _addFriend() async {
|
|
|
try {
|
|
|
- await FriendsService.addFriend(_friendSharedId);
|
|
|
- setState(() {
|
|
|
- _friendSharedId = "";
|
|
|
- });
|
|
|
+ await FriendsService.addFriend(_controller.text);
|
|
|
+ _controller.clear();
|
|
|
_showSnackBar("Friend request sent!", Colors.green);
|
|
|
} catch (error) {
|
|
|
_showSnackBar(error.toString(), Colors.red);
|
|
|
@@ -44,7 +42,7 @@ class _AddFriendState extends State<AddFriend> {
|
|
|
children: [
|
|
|
TextField(
|
|
|
onSubmitted: (_) => _addFriend(),
|
|
|
- onChanged: _onTextUpdate,
|
|
|
+ controller: _controller,
|
|
|
decoration: const InputDecoration(
|
|
|
border: OutlineInputBorder(),
|
|
|
hintText: "Enter a friend's ID to add them",
|