ソースを参照

fix: reset shared id text when adding friend

Léo Salé 3 年 前
コミット
74a9910592
1 ファイル変更8 行追加10 行削除
  1. 8 10
      app/lib/friends/widgets/add_friend.dart

+ 8 - 10
app/lib/friends/widgets/add_friend.dart

@@ -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",