logo icon
Taninut.com

140

 
 
 
Content ID140
Category ID3
Writer ID(not set)
User ID(not set)
Lang Modeth
Content Nameตัวอย่างการใช้ Widget ใน Flutter
Content Urlตัวอย่างการใช้-Widget-ใน-Flutter
Content Desc<p>Widget คือส่วนประกอบพื้นฐานใน Flutter ซึ่งใช้สร้างแอปพลิเคชัน ดังนั้น ส่วนมากจะต้องใช้ Widget ต่างๆ เพื่อสร้าง UI/UX ของแอปพลิเคชัน ดังนี้</p>
<ol>
<li>
<p>MaterialApp: ใช้สร้างแอปพลิเคชันตามหลักการ Material Design ของ Google ซึ่งมี Widget ส่วนย่อยอื่นๆ เช่น Scaffold, AppBar, BottomNavigationBar ฯลฯ เพื่อช่วยในการสร้าง UI ของแอปพลิเคชัน</p>
</li>
<li>
<p>Container: ใช้สร้างพื้นที่หรือกรอบของ Widget อื่นๆ ซึ่งสามารถกำหนดสีพื้นหลัง ขนาด และระยะห่างได้ตามต้องการ</p>
</li>
<li>
<p>Row และ Column: ใช้สร้าง Layout แบบแถวและคอลัมน์ เพื่อจัดวาง Widget ให้เรียงกันได้อย่างเหมาะสม</p>
</li>
<li>
<p>Text: ใช้สร้างข้อความแสดงผลบนหน้าจอ</p>
</li>
<li>
<p>Image: ใช้แสดงรูปภาพบนหน้าจอ</p>
</li>
<li>
<p>ListView: ใช้สร้างลิสต์ของ Widget อื่นๆ เพื่อแสดงผลบนหน้าจอ เช่น รายการสินค้า หรือรายชื่อผู้ใช้งาน</p>
</li>
<li>
<p>Button: ใช้สร้างปุ่มที่สามารถกดได้ เพื่อใช้ในการทำงานต่างๆ ซึ่งแต่ละปุ่มสามารถกำหนดรูปแบบและสีได้ตามต้องการ</p>
</li>
</ol>
<p>ตัวอย่างการใช้ Widget ใน Flutter:</p>
<p style="padding-left: 80px;"><code>MaterialApp(</code><br><code>&nbsp; title: 'My App',</code><br><code>&nbsp; home: Scaffold(</code><br><code>&nbsp; &nbsp; appBar: AppBar(</code><br><code>&nbsp; &nbsp; &nbsp; title: Text('Welcome to My App'),</code><br><code>&nbsp; &nbsp; ),</code><br><code>&nbsp; &nbsp; body: Container(</code><br><code>&nbsp; &nbsp; &nbsp; child: Row(</code><br><code>&nbsp; &nbsp; &nbsp; &nbsp; children: &lt;Widget&gt;[</code><br><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Expanded(</code><br><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; child: Image.asset('assets/images/logo.png'),</code><br><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ),</code><br><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Expanded(</code><br><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; child: Column(</code><br><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; children: &lt;Widget&gt;[</code><br><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Text('Welcome to My App'),</code><br><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RaisedButton(</code><br><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; child: Text('Click Me'),</code><br><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; onPressed: () {</code><br><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // do something</code><br><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },</code><br><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ),</code><br><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ],</code><br><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ),</code><br><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ),</code><br><code>&nbsp; &nbsp; &nbsp; &nbsp; ],</code><br><code>&nbsp; &nbsp; &nbsp; ),</code><br><code>&nbsp; &nbsp; ),</code><br><code>&nbsp; ),</code><br><code>);</code></p>
<p>&nbsp;</p>
Content Short
Content View3648
Content Thumb Highlight
Content Thumb
Content Img Altตัวอย่างการใช้ Widget ใน Flutter
Content TagWidget ใน Flutter,Flutter
Content Date(not set)
Active Status1
Sort99999
Meta Titleตัวอย่างการใช้ Widget ใน Flutter
Meta Descตัวอย่างการใช้ Widget ใน Flutter
Meta KeywordWidget ใน Flutter,Flutter
Og Titleตัวอย่างการใช้ Widget ใน Flutter
Og Descตัวอย่างการใช้ Widget ใน Flutter
Status1
Create Date Time2023-03-29 10:53:51
Update Date Time2023-03-29 10:53:51
Create By
Update By