Flutter Widgets
  Nhts4LcX4RvQ 2023年11月02日 49 0

Learn the basic concept of Flutter widgets and different ways of use it to make user interface.
In Flutter, almost everything is a widget. In this tutorial, you will learn the concept of the widget, methods to use and create it, and types of widgets in the Flutter framework.

If you are building a user interface in Flutter, it will be using widgets. There are different kinds of widgets available on Flutter which has a different kind of purpose, you have to build an app out of those widgets.

In an app, widgets are nested inside one another, even the outermost parent component of the app is also a widget and all inside the app are also widgets. See the tree diagram and the code below to understand the structure of the app using widgets.

Flutter Widgets_sed


The above tree of widgets will look like below on code:

import 'package:flutter/material.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget{
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}

class HomePage extends StatelessWidget{
@override
Widget build(BuildContext context) {
return Scaffold(

appBar: AppBar( //appbar widget inside Scaffold
title: Text("Welcome to Flutter")
),

drawer: Drawer(), //drawer widget inside scaffold

floatingActionButton: FloatingActionButton( //floating action button widget
child: Icon(Icons.add), //Icon widget inside Floating action button widget
onPressed: (){
//gesture listiner action
},
),
body: Container( //container widget on body of scaffold
child: Column( //multi chidl widget
children: [
Text("Column 1"),
Text("Column 2"),
],)
)
);
}
}

Types of Widgets:
There are two types of widgets in flutter according to their nature.

Visible Widgets (Input and Output)
Invisible Widgets (Layout and Control)
Visible Widgets:

Visible widgets are those widgets that are easily visible whenever we put them inside the widget tree. They are used for displaying information or to take information/input from users. Some of the visible widgets are Text, Button, Image, Icon, etc.

Invisible Widgets:

Invisible widgets are those widgets that are not visible in the widget tree but are used to format, sizing, and locating the visible widgets. Some of the invisible widgets are Scaffold, Row, Column, Padding, SizedBox, etc.

Flutter Widgets_sed_02

作者:​​我北漂沪漂的这几年​​



【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

上一篇: ukyo's flutter practice 下一篇: Flutter Gestures
  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  b1UHV4WKBb2S   2023年11月13日   40   0   0 ide抗锯齿
  b1UHV4WKBb2S   2023年11月13日   37   0   0 裁剪ideflutter
  zSWNgACtCQuP   2023年11月13日   32   0   0 ide
Nhts4LcX4RvQ