7/15/19

Create widget in flutter | Flutter



Entire flutter app builds up in widgets.

maybe we should start using such a widget. So for that, we actually create our own root widget. this is how you typically start.

we will use another dart feature classes with the class keyword. a dart is an object-oriented programming language. the object is simply meant data structure.

class MyApp{

}

a flutter, of course, doesn't know if a class created by us is something it can use as a widget. because as you will learn, it needs certain features in a class to be able to use it as a widget, so to draw it to the screen and therefore, outclasses has to extend something.

we important another feature of imports. we write our own code but we want to use code which is exposed to the flutter SDK and framework. third party package. such as,

import 'package:flutter/material.dart';

that we can extend a feature which is exposed from that package and that is so-called StatelessWidget class. there also is another widget, the StatefulWidget.

class MyApp extends StatelessWidget{

}

this class based on the stateless widget and therefore, we can almost use it as a widget to draw it onto the screen.

Missing concrete implementation of StatelessWidget.build. Try implementing the missing method, or make the class abstract

build method is required because if we tell flutter to use an object based on this class as a widget it can draw onto the screen. it of needs to really this being drawable you could say and fluter will try to draw something. by calling build method on an object where you tell it that it's a widget. So if you pass an object to flutter to draw it onto the screen, flutter will always call a build method on that object. which is why need to edit to your own widgets. build method means actually takes one argument, data which will get passed into it by flutter. because will be the one calling the build method. build method has one argument. which is the context, context is basically an object with some meta information about your app and the position where this widget is grown in and for example will contain information about the theme, colors used in the app. build method needs to return something which you do by adding the return keyword.

flutter will execute the build method and then it needs to know what to draw into the screen. and that something needs to be returned.
that will widget such as 'MaterialApp()' widget. this is a special widget which is used to wrap our entire app. So this will actually give you abilities to set up the theming for that app. it will also add a navigator which allows you to switch between different pages and so on. So this is your core root widget which you use in every flutter app you create.

you turn it in your own widget which will be the topmost widget. therefore and now the material app widget can be configured to do something to really draw something onto the screen.we can pass the data into MaterialApp();

MaterialApp without parethases is a class imported from the fluter material package.MaterialApp() with parethases we create an object on the class. you could say we construct the an object. we call also constructor of a class. this gives us is a new object based on the material app class. you might also see the syntax where you add a new keyword in front of that as of dart version to easier we use here and which is the feature of the dart, you don't need that anymore.

No comments:

Post a Comment

About

Hi, I'm Najathi.
I've started entrepreneurial company, Twin Brothers.Inc.
One is self-funded & the other is venture backed. I also send a weekly. where I share relevent, curated links.

Every Week I Publish a short post on writing, publishing, or content of IT Related

Contact Form

Name

Email *

Message *