turtle-apisit / swiftdynamics_test

0 stars 0 forks source link

Comment #1

Open natchaSWD opened 1 year ago

natchaSWD commented 1 year ago

BUG ทดลองเทสดูแล้วมีบัคครับ ทำให้เทสต่อไม่ได้ ต้องรันใหม่

State สังเกตว่าในโปรเจคมีการใช้ setState อันนี้ไม่ค่อยแนะนำให้ใช้ครับ ถ้าไม่จำเป็นจริงๆ หรือ widget ตัวนั้นไม่ได้มีโลจิคซับซ้อน ข้อเสียของ setState คือ เวลา call setState มันจะ run คำสั่ง build ใหม่ทำให้เกิดการ re render ui โดยไม่จำเป็น

Clean code

  1. ยังต้องปรับปรุงเรื่องการจัด fomat โค้ด มีหลายจุดที่มีการเว้นบรรทัด

  2. เข้าใจว่ามันมี duplicate code เลยแยกมาเป็น function อันนี้ดีแล้วครับแนะนำให้พยายามทำบ่อยๆ

    Screen Shot 2566-06-07 at 14 25 44
  1. มีโลจิคปนอยู่กับส่วนแสดงผล (UI) อาจจะแก้โดยการแยกเป็น function หรือเอา Design Pattern เข้ามาช่วยจะทำให้โค้ดอ่านง่ายและมีประสิทธิภาพมากขึ้น

ยกตัวอย่าง มีการ sort List ใน widget ListView อันนี้คิดว่าควรย้ายไปคำนวนใน BLOC หรือแยกออกมาเป็นฟังก์ชั่นครับ

                ListView.separated(
                  separatorBuilder: (context, index) {
                    return Divider(height: 5, color: Colors.grey);
                  },
                  itemCount: userState.userList.length,
                  itemBuilder: (context, index) {
                    final sortedList = userState.userList.toList()
                      ..sort((a, b) => a.province.compareTo(b.province));

                    final user = sortedList[index];

                    return ListTile(
                      title: Text("${user.fullName}"),
                      subtitle: Text("${user.province}"),
                      leading: Icon(Icons.person, size: 60),
                      trailing: Icon(Icons.arrow_forward_ios),
                      onTap: () => Navigator.push(
                        context,
                        MaterialPageRoute(
                          builder: (context) => DetailPage(numUser: index),
                        ),
                      ),
                    );
                  },
                ),
turtle-apisit commented 1 year ago

ขอบคุณสำหรับคำแนะนำครับ

ในวันที่ พ. 7 มิ.ย. 2023 เวลา 15:06 natchaSWD @.***> เขียนว่า:

BUG ทดลองเทสดูแล้วมีบัคครับ ทำให้เทสต่อไม่ได้ ต้องรันใหม่

State สังเกตว่าในโปรเจคมีการใช้ setState อันนี้ไม่ค่อยแนะนำให้ใช้ครับ ถ้าไม่จำเป็นจริงๆ หรือ widget ตัวนั้นไม่ได้มีโลจิคซับซ้อน ข้อเสียของ setState คือ เวลา call setState มันจะ run คำสั่ง build ใหม่ทำให้เกิดการ re render ui โดยไม่จำเป็น

Clean code

1.

ยังต้องปรับปรุงเรื่องการจัด fomat โค้ด มีหลายจุดที่มีการเว้นบรรทัด 2.

เข้าใจว่ามันมี duplicate code เลยแยกมาเป็น function อันนี้ดีแล้วครับแนะนำให้พยายามทำบ่อยๆ

[image: Screen Shot 2566-06-07 at 14 25 44] https://user-images.githubusercontent.com/112603678/243958754-c3728d29-ef8c-457c-9aff-3c1b8a5c9753.png

  1. มีโลจิคปนอยู่กับส่วนแสดงผล (UI) อาจจะแก้โดยการแยกเป็น function หรือเอา Design Pattern เข้ามาช่วยจะทำให้โค้ดอ่านง่ายและมีประสิทธิภาพมากขึ้น

ยกตัวอย่าง มีการ sort List ใน widget ListView อันนี้คิดว่าควรย้ายไปคำนวนใน BLOC หรือแยกออกมาเป็นฟังก์ชั่นครับ

            ListView.separated(
              separatorBuilder: (context, index) {
                return Divider(height: 5, color: Colors.grey);
              },
              itemCount: userState.userList.length,
              itemBuilder: (context, index) {
                final sortedList = userState.userList.toList()
                  ..sort((a, b) => a.province.compareTo(b.province));

                final user = sortedList[index];

                return ListTile(
                  title: Text("${user.fullName}"),
                  subtitle: Text("${user.province}"),
                  leading: Icon(Icons.person, size: 60),
                  trailing: Icon(Icons.arrow_forward_ios),
                  onTap: () => Navigator.push(
                    context,
                    MaterialPageRoute(
                      builder: (context) => DetailPage(numUser: index),
                    ),
                  ),
                );
              },
            ),

— Reply to this email directly, view it on GitHub https://github.com/s6252410001/swiftdynamics_test/issues/1, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVLYKN2XZX4DWY5S4NXSXD3XKAY7BANCNFSM6AAAAAAY5PIB4Q . You are receiving this because you are subscribed to this thread.Message ID: @.***>