Flutter Create Custom New Widget in Android iOS Example Tutorial

In flutter we would use Widget keyword along with widget name to create custom widgets. Flutter gives us functionality to make designing easier using custom widgets. Using custom widgets we can easily existing widgets and also make new widgets by modifying current widgets. Custom widgets has return area which would return us complete widget pass in it. Widget is the center of development in flutter framework. So in this tutorial we would Flutter Create Custom New Widget in Android iOS Example Tutorial.

Contents in this project Flutter Create Custom New Widget in Android iOS Example Tutorial:

1. Import material.dart package in your app’s main.dart file.

2. Create void main runApp() method and here we would pass our main MyApp class. This class is our main screen class in current tutorial.

3. Create our main class named as MyApp extends with StatelessWidget.

4. Create a Custom widget named as customTextWidget() with 4 different properties. This is our custom widget. In this widget we would requiring 4 values from user at widget calling time.

  1. text : Text used to print on screen in Text widget.
  2. Color : Text Color pass by user to set Text color.
  3. fONTSize : Require double value to set Text font size.
  4. fONTStyle : Used to set font style like bold or Italic.;

5. Create Widget Build area in MyApp. Now we would make the Scaffold widget -> Center widget -> Column widget.

6. Now we would call our custom widget customTextWidget() with all 4 parameter values.

7. Complete source code for main.dart file:

Screenshot:

Flutter Create Custom New Widget in Android iOS Example Tutorial

One Comment

  1. there is one text widget on each screen, let’s call it “title”, while it has a different color on the screens, how to make it reusable with its own styles that look like this

    /// Headline 1 Bold White
    static final TextStyle headline1White = TextStyle(
    fontFamily: Assets.fonts.gilroyBold,
    fontSize: 24,
    height: 32 / 24,
    fontWeight: FontWeight.w700,
    color: AppColors.textFFFFFF,
    );

    /// Headline 1 Bold Pink
    static final TextStyle headline1Pink = TextStyle(
    fontFamily: Assets.fonts.gilroyBold,
    fontSize: 24,
    height: 32 / 24,
    fontWeight: FontWeight.w700,
    color: AppColors.textFF3C60,
    );

Leave a Reply

Your email address will not be published. Required fields are marked *