Flutter / UI Elements / Widgets
Widget
-
Code
Widget are reusable components
import 'package:flutter/material.dart'; void main() { runApp( MaterialApp( home: Scaffold( appBar: AppBar( title: Text('Functional Widget Example'), ), body: myFunctionalWidget(), ), ), ); } Widget myFunctionalWidget() { return Container( color: Colors.blue, child: Center( child: Text( 'Hello, Stateless Functional Widget!', style: TextStyle( fontSize: 18, color: Colors.white, ), ), ), ); } Example
//widget 1 Widget circleRow() { return Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ circleIcon(), circleIcon(), ], ); } //widget 2 Widget circleIcon() { return Icon( Icons.circle, color: Colors.white.withOpacity(.5), size: 10, ); } //widget 3 Widget customDrawer() { return Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Card( elevation: 20, color: Colors.white.withOpacity(.1), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)), child: Container( height: 40, width: 40, padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10), decoration: BoxDecoration( color: Colors.white.withOpacity(.1), borderRadius: BorderRadius.circular(10)), child: Column( children: [circleRow(), circleRow()], ), ), ), ClipRRect( borderRadius: BorderRadius.circular(20), child: Card( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), ), child: const FlutterLogo( size: 35, ), ), ), ], ); } //widget 4 Widget specialCard(AssetImage asset) { return Card( color: Colors.white.withOpacity(.1), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(15), ), child: Container( margin: const EdgeInsets.all(10), height: 120, width: double.infinity, child: Row( children: [ ClipRRect( borderRadius: BorderRadius.circular(20), child: Container( height: double.infinity, width: 120, decoration: BoxDecoration( image: DecorationImage(image: asset, fit: BoxFit.cover)), ), ), const SizedBox( width: 20, ), const Column( children: [ Text( "5 Coffee Beans You\nMust try!", style: TextStyle( color: Colors.white, fontSize: 17, fontWeight: FontWeight.bold), ) ], ) ], ), ), ); } } Usage
Column( children: [circleRow(), circleRow()], ),