We create Custom Widgets when we choose a customized seem and experience to our app, and we comprehend that there will be a repetition of a precise widget. We can create the customized widget in a new dart file with all the codes and defining the parameters that we want in the constructor.Here we will be discussing an instance of how to construct a easy app through making use of customized property to the widgets and making them separate from their personal properties. We will be making a BMI Calculator App that takes top and weight to calculate the BMI of a person. To exhibit how to use customized widgets we have additionally described positive greater matters on the screen.
Let us start by cleaning up the main.dart file as:
Code:
import 'package:custom_widget_demo/home.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'GFG Custom Widget Demo',
theme: ThemeData.dark(),
home: Home(),
);
}
}