<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Bikash Katwal</title>
    <description>The latest articles on DEV Community by Bikash Katwal (@bikashkatwal).</description>
    <link>https://dev.to/bikashkatwal</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F196058%2Fd3a55e54-6ec1-49a6-a26d-f2245439dc4e.jpeg</url>
      <title>DEV Community: Bikash Katwal</title>
      <link>https://dev.to/bikashkatwal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bikashkatwal"/>
    <language>en</language>
    <item>
      <title>Flutter custom widget creation Text, Icon, Icon Button, Drawer</title>
      <dc:creator>Bikash Katwal</dc:creator>
      <pubDate>Fri, 24 Jan 2020 11:06:49 +0000</pubDate>
      <link>https://dev.to/bikashkatwal/flutter-custom-widget-creation-text-icon-icon-button-drawer-j41</link>
      <guid>https://dev.to/bikashkatwal/flutter-custom-widget-creation-text-icon-icon-button-drawer-j41</guid>
      <description>&lt;p&gt;Creating custom widgets helps in minimizing time while development. I have added a few custom widgets that might help you in the development process.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create constants.dart. Anywhere you see kRed, kWhite then that is from this constants.dart class. You can add any constants.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:flutter/material.dart';
const kRed = Colors.red;
const kWhite = Colors.white;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Create a custom_text.dart. Any attributes you want to add can be added as final and add it to the constructor.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:flutter/material.dart';
class CustomText extends StatelessWidget {
  final String text;
  final double fontSize;
  final FontWeight fontWeight;
  final Color color;
const CustomText(
      {@required this.text, this.fontSize, this.fontWeight, this.color});
  @override
  Widget build(BuildContext context) {
    return Text(
      text,
      style: TextStyle(
        color: color,
        fontSize: fontSize,
        fontWeight: fontWeight,
      ),
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Create custom_icon.dart. Any attributes you want to add can be added as final and add it to the constructor.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:flutter/material.dart';
class CustomIcon extends StatelessWidget {
  final IconData iconData;
  final Color color;
  final double size;
const CustomIcon({@required this.iconData, this.color, this.size});
@override
  Widget build(BuildContext context) {
    return Icon(
      iconData,
      color: color,
      size: size,
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Create custom_icon_button.dart. In this stateless class, I have added CustomIcon as an argument.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:flutter/material.dart';
import 'package:flutter_ecom/widgets/custom_icon.dart';
class CustomIconButton extends StatelessWidget {
  final CustomIcon customIcon;
  final Function onIconPressed;
const CustomIconButton(
      {@required this.customIcon, @required this.onIconPressed});
@override
  Widget build(BuildContext context) {
    return IconButton(
      icon: customIcon,
      onPressed: onIconPressed,
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Create custom_drawer.dart with ListView.builder/ListView.separated
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:flutter/material.dart';
import 'package:flutter_ecom/commons/constants.dart';
import 'package:flutter_ecom/commons/custom_icon.dart';
import 'package:flutter_ecom/commons/custom_text.dart';
import 'package:flutter_ecom/commons/images.dart';

class CustomDrawer extends StatefulWidget {
  @override
  _CustomDrawerState createState() =&amp;gt; _CustomDrawerState();
}

class _CustomDrawerState extends State&amp;lt;CustomDrawer&amp;gt; {
  List _drawerItems = [
    {"icon": Icons.home, "name": "Home"},
    {"icon": Icons.account_circle, "name": "My account"},
    {"icon": Icons.shopping_basket, "name": "Shopping"},
    {"icon": Icons.dashboard, "name": "My orders"},
    {"icon": Icons.favorite, "name": "Favourites"},
    {"icon": Icons.settings, "name": "Settings"},
    {"icon": Icons.help, "name": "About"},
  ];

  _iconColor(int i) {
    int _count = _drawerItems.length;
    if (_count - 1 == i) {
      return kBlue;
    }
  }

  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: ListView(
        padding: EdgeInsets.zero,
        children: &amp;lt;Widget&amp;gt;[
          UserAccountsDrawerHeader(
            accountName: CustomText(
              text: 'John Doe',
            ),
            accountEmail: CustomText(
              text: 'xyz@gmail.com',
            ),
            currentAccountPicture: GestureDetector(
              child: CircleAvatar(
                backgroundImage: AssetImage(Images.profileImage),
              ),
            ),
            decoration: BoxDecoration(
              color: kRed,
            ),
          ),
          ListView.separated(
            physics: NeverScrollableScrollPhysics(),
            shrinkWrap: true,
            itemCount: _drawerItems.length,
            separatorBuilder: (_, index) {
              return (_drawerItems.length - 3 == index)
                  ? Divider(
                      color: kBlack,
                    )
                  : Container();
            },
            itemBuilder: (_, index) {
              Map item = _drawerItems[index];
              return InkWell(
                onTap: () {},
                child: ListTile(
                  leading: CustomIcon(
                    iconData: item['icon'],
                    color: _iconColor(index),
                  ),
                  title: CustomText(
                    text: item['name'],
                  ),
                ),
              );
            },
          ),
        ],
      ),
    );
  }
}

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>flutter</category>
      <category>customwidgets</category>
      <category>drawer</category>
      <category>dart</category>
    </item>
  </channel>
</rss>
