Basic Flutter Widgets Every Developer Should Know

This basic flutter widgets is posted by seven.srikanth at 5/2/2025 11:40:55 PM



<h1 id="basic-flutter-widgets-every-developer-should-know">Basic Flutter Widgets Every Developer Should Know</h1> <p>Understanding basic widgets is crucial for Flutter development. Let's explore the fundamental widgets that you'll use in almost every Flutter application.</p> <h2 id="text-and-display-widgets">1. Text and Display Widgets</h2> <h3 id="text-widget">Text Widget</h3> <pre>Text( &#39;Hello, Flutter!&#39;, style: TextStyle( fontSize: 24, fontWeight: FontWeight.bold, color: Colors.blue, ), ) </pre> <h3 id="richtext-widget">RichText Widget</h3> <pre>RichText( text: TextSpan( text: &#39;Hello &#39;, style: TextStyle(color: Colors.black), children: [ TextSpan( text: &#39;Flutter&#39;, style: TextStyle( color: Colors.blue, fontWeight: FontWeight.bold, ), ), ], ), ) </pre> <h2 id="layout-widgets">2. Layout Widgets</h2> <h3 id="container-widget">Container Widget</h3> <pre>Container( width: 200, height: 100, padding: EdgeInsets.all(16), margin: EdgeInsets.all(8), decoration: BoxDecoration( color: Colors.blue, borderRadius: BorderRadius.circular(8), ), child: Text(&#39;Container&#39;), ) </pre> <h3 id="row-and-column-widgets">Row and Column Widgets</h3> <pre>Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Container(color: Colors.red, width: 50, height: 50), Container(color: Colors.green, width: 50, height: 50), Container(color: Colors.blue, width: 50, height: 50), ], )

Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Container(color: Colors.red, width: 50, height: 50), Container(color: Colors.green, width: 50, height: 50), Container(color: Colors.blue, width: 50, height: 50), ], ) </pre> <h2 id="input-widgets">3. Input Widgets</h2> <h3 id="textfield-widget">TextField Widget</h3> <pre>TextField( decoration: InputDecoration( labelText: &#39;Enter text&#39;, hintText: &#39;Type something...&#39;, border: OutlineInputBorder(), ), onChanged: (value) { print(&#39;Text changed: $value&#39;); }, ) </pre> <h3 id="elevatedbutton-widget">ElevatedButton Widget</h3> <pre>ElevatedButton( onPressed: () { print(&#39;Button pressed&#39;); }, child: Text(&#39;Click Me&#39;), style: ElevatedButton.styleFrom( padding: EdgeInsets.symmetric(horizontal: 32, vertical: 16), ), ) </pre> <h2 id="list-widgets">4. List Widgets</h2> <h3 id="listview-widget">ListView Widget</h3> <pre>ListView( children: [ ListTile( leading: Icon(Icons.star), title: Text(&#39;Item 1&#39;), subtitle: Text(&#39;Description 1&#39;), ), ListTile( leading: Icon(Icons.star), title: Text(&#39;Item 2&#39;), subtitle: Text(&#39;Description 2&#39;), ), ListTile( leading: Icon(Icons.star), title: Text(&#39;Item 3&#39;), subtitle: Text(&#39;Description 3&#39;), ), ], ) </pre> <h3 id="gridview-widget">GridView Widget</h3> <pre>GridView.count( crossAxisCount: 2, children: List.generate( 6, (index) =&gt; Container( color: Colors.blue, margin: EdgeInsets.all(8), child: Center( child: Text(&#39;Item $index&#39;), ), ), ), ) </pre> <h2 id="navigation-widgets">5. Navigation Widgets</h2> <h3 id="appbar-widget">AppBar Widget</h3> <pre>AppBar( title: Text(&#39;My App&#39;), actions: [ IconButton( icon: Icon(Icons.search), onPressed: () { print(&#39;Search pressed&#39;); }, ), IconButton( icon: Icon(Icons.more_vert), onPressed: () { print(&#39;More pressed&#39;); }, ), ], ) </pre> <h3 id="bottomnavigationbar-widget">BottomNavigationBar Widget</h3> <pre>BottomNavigationBar( currentIndex: 0, items: [ BottomNavigationBarItem( icon: Icon(Icons.home), label: &#39;Home&#39;, ), BottomNavigationBarItem( icon: Icon(Icons.business), label: &#39;Business&#39;, ), BottomNavigationBarItem( icon: Icon(Icons.school), label: &#39;School&#39;, ), ], onTap: (index) { print(&#39;Selected index: $index&#39;); }, ) </pre>


Tags: flutter,markdown,generated








0 Comments
Login to comment.
Recent Comments