1.custom class widget

main.dart

 1 import 'package:flutter/material.dart';
2 import './pages/custom.dart';
3
4 void main() {
5 runApp(new Application());
6 }
7 class Application extends StatelessWidget {
8 @override
9 Widget build(BuildContext context) {
10 return new MaterialApp(
11 title: 'custom',
12 home: new Scaffold(
13 body: new customWidgets()
14 )
15 );
16 }
17 }

custom.dart

 1 import 'package:flutter/material.dart';
2
3 class customWidgets extends StatelessWidget {
4 @override
5 Widget build(BuildContext context) {
6 return new Container(
7 color: Colors.pink,
8 child: new Container(
9 color: Colors.purple,
10 margin: const EdgeInsets.all(10.0),
11 child: new Container(
12 color: Colors.orange,
13 margin: const EdgeInsets.all(10.0),
14 child: new Container(
15 color: Colors.yellow,
16 margin: const EdgeInsets.all(10.0),
17 ),
18 ),
19 ),
20 );
21 }
22 }

2.radio单选按钮

import 'package:flutter/material.dart';

void main() {
runApp(new Application());
}
class Application extends StatefulWidget {
@override
_ApplicationState createState() => _ApplicationState();
} class _ApplicationState extends State<Application> {
int rvalue = 0;
void method1(value) {
setState(() {
rvalue = value;
});
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'a',
home: new Scaffold(
appBar: new AppBar(
title: new Text("a"),
backgroundColor: Colors.green,
),
body: new Center(
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Radio(value: 1, groupValue: rvalue, onChanged: (int rval){method1(rval);}),
new Radio(value: 2, groupValue: rvalue, onChanged: (int rval){method1(rval);}),
new Radio(value: 3, groupValue: rvalue, onChanged: (int rval){method1(rval);}),
],
),
),
)
);
}
}

3.checkbox复选框

import 'package:flutter/material.dart';

void main() {
runApp(new Application());
}
class Application extends StatefulWidget {
@override
_ApplicationState createState() => _ApplicationState();
} class _ApplicationState extends State<Application> {
bool select = false;
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'a',
home: new Scaffold(
appBar: new AppBar(
title: new Text("a"),
backgroundColor: Colors.green,
),
body: new Center(
child: new Checkbox(
value: select,
onChanged: (bool cb) {
setState(() {
select = cb;
print(select);
});
}),
),
)
);
}
}

4.snackBar通知条

import 'package:flutter/material.dart';
import './pages/OtherPage.dart'; void main() {
runApp(new Application());
}
class Application extends StatefulWidget {
@override
_ApplicationState createState() => _ApplicationState();
} class _ApplicationState extends State<Application> {
bool bval = false;
void method1(value) {
setState(() {
bval = value;
});
}
@override
Widget build(BuildContext context) {
final GlobalKey<ScaffoldState> _skey = new GlobalKey<ScaffoldState>();
void method1() {
_skey.currentState.showSnackBar(new SnackBar(
content: new Text('Activated snack bar'),
backgroundColor: Colors.blue,
));
}
return new MaterialApp(
title: 'a',
home: new Scaffold(
key: _skey,
body: new Center(
child: new RaisedButton(
onPressed: () {method1();},
child: new Text('raisebtn'),
),
), )
);
}
}

5.drawer,类似qq侧边划出的效果

 1 import 'package:flutter/material.dart';
2
3 void main() {
4 runApp(new Application());
5 }
6 class Application extends StatefulWidget {
7 @override
8 _ApplicationState createState() => _ApplicationState();
9 }
10
11 class _ApplicationState extends State<Application> {
12 bool bval = false;
13 void method1(value) {
14 setState(() {
15 bval = value;
16 });
17 }
18 @override
19 Widget build(BuildContext context) {
20 return new MaterialApp(
21 title: 'a',
22 home: new Scaffold(
23 appBar: new AppBar(
24 title: new Text("a"),
25 backgroundColor: Colors.green,
26 ),
27 drawer: new Drawer(
28 child: new ListView(
29 children: <Widget>[
30 new UserAccountsDrawerHeader(
31 accountName: new Text('pengjinlong'),
32 accountEmail: new Text('pengjinlong43@gmail.com'),
33 currentAccountPicture: new CircleAvatar(
34 backgroundColor: Colors.black26,
35 child: new Text('Peng'),
36 ),
37 decoration: new BoxDecoration(color: Colors.blueAccent),
38 otherAccountsPictures: <Widget>[
39 new CircleAvatar(
40 backgroundColor: Colors.black26,
41 child: new Text('jin'),
42 ),
43 new CircleAvatar(
44 backgroundColor: Colors.black26,
45 child: new Text('long'),
46 ),
47 ],
48 ),
49 new ListTile(
50 title: new Text('d1'),
51 trailing: new Icon(Icons.accessibility),
52 onTap: () {
53 Navigator.pop(context);
54 },
55 ),
56 new ListTile(
57 title: new Text('d1'),
58 trailing: new Icon(Icons.accessibility),
59 ),
60 new ListTile(
61 title: new Text('d1'),
62 trailing: new Icon(Icons.accessibility),
63 )
64 ],
65 ),
66 ),
67 )
68 );
69 }
70 }

6.switch按钮

 1 import 'package:flutter/material.dart';
2
3 void main() {
4 runApp(new Application());
5 }
6 class Application extends StatefulWidget {
7 @override
8 _ApplicationState createState() => _ApplicationState();
9 }
10
11 class _ApplicationState extends State<Application> {
12 bool bval = false;
13 void method1(value) {
14 setState(() {
15 bval = value;
16 });
17 }
18 @override
19 Widget build(BuildContext context) {
20 return new MaterialApp(
21 title: 'a',
22 home: new Scaffold(
23 appBar: new AppBar(
24 title: new Text("a"),
25 backgroundColor: Colors.green,
26 ),
27 body: new Center(
28 child: new Column(
29 mainAxisAlignment: MainAxisAlignment.center,
30 children: <Widget>[
31 new Switch(
32 value: bval,
33 onChanged: (bool val) {
34 method1(val);
35 },
36 )
37 ],
38 ),
39 ),
40 )
41 );
42 }
43 }

7.listView

class _ApplicationState extends State<Application> {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'dummy application',
home: new Scaffold(
appBar: new AppBar(
title: new Text('List widget'),
),
body: new ListView(
children: <Widget>[
new ListTile(
title: new Text('item 1dd'),
trailing: new Icon(Icons.arrow_forward),
),
new ListTile(
title: new Text('item 2'),
trailing: new Icon(Icons.arrow_forward),
),
new ListTile(
title: new Text('item 3'),
trailing: new Icon(Icons.arrow_forward),
),
],
),
)
);
}
}

tips: listview的title属性可以设置InputFiled实现登录框

flutter 常用视图组件的更多相关文章

  1. Flutter常用布局组件

    Flutter控件本身通常由许多小型.单用途的控件组成,结合起来产生强大的效果,例如,Container是一种常用的控件,由负责布局.绘画.定位和大小调整的几个控件组成,具体来说,Container是 ...

  2. Flutter 常用组件

    无状态组件(StatelessWidget)是不可变的,这意味着它的属性不能改变,所有的值都是最终的. 有状态组件(StatefulWidget)持有的状态可能在Widget生命周期中发生变化.实现一 ...

  3. [译]ASP.NET Core 2.0 视图组件

    问题 如何在ASP.NET Core 2.0中使用视图组件? 答案 新建一个空项目,修改Startup类并添加MVC服务和中间件: public void ConfigureServices(ISer ...

  4. DjangoRestFramework学习二之序列化组件、视图组件 serializer modelserializer

      DjangoRestFramework学习二之序列化组件.视图组件   本节目录 一 序列化组件 二 视图组件 三 xxx 四 xxx 五 xxx 六 xxx 七 xxx 八 xxx 一 序列化组 ...

  5. 前后端分离djangorestframework——视图组件

    CBV与FBV CBV之前说过就是在view.py里写视图类,在序列化时用过,FBV就是常用的视图函数,两者的功能都可以实现功能,但是在restful规范方面的话,CBV更方便,FBV还要用reque ...

  6. $Django patch与put,视图组件,路由控制,响应器

    1 patch与put(幂等?回顾) PATCH 与 PUT 属性上的一个重要区别还在于:PUT 是幂等的,而 PATCH 不是幂等的.幂等是一个数学和计算机学概念,在计算机范畴内表示一个操作执行任意 ...

  7. React Native常用第三方组件汇总--史上最全 之一

    React Native 项目常用第三方组件汇总: react-native-animatable 动画 react-native-carousel 轮播 react-native-countdown ...

  8. React Native常用第三方组件汇总--史上最全[转]

    本文出处: http://blog.csdn.net/chichengjunma/article/details/52920137 React Native 项目常用第三方组件汇总: react-na ...

  9. sencha touch 入门系列 (九)sencha touch 视图组件简介

    对于一个普通用户来说,你的项目就是一组简单的视图集合,用户直接通过跟视图进行交互来操作你的应用,对于一个开发人员来说,视图是一个项目的入口,虽然大部分时候最有价值的部分是在model层和control ...

随机推荐

  1. python03篇 字符串常用方法和文件操作(一)

    一.字符串常用方法 s1 = ' abcsfsfaadfdd ' s = s1.strip() print(s) print(len(s.strip())) print(s.count('a')) # ...

  2. VRRP概述作用及配置

    文章目录 VRRP的概述 VRRP的作用 虚拟路由器 Master报文的发送 VRRP状态机 VRRP华为命令配置 VRRP的概述1.利用VRRP,一组路由器(同一个LAN中的接口),协同工作,但是只 ...

  3. 短信链接点击跳转到微信小程序

    短信轰炸的时代,之前链接都是跳转到网页的,后来发现粘性不强,再次唤醒用户成本较高,但小程序的订阅功能,再次唤醒成本较低,还便于给用户通知结果.所以现在链接都改跳转到小程序了.废话不多说,现在就看看是如 ...

  4. 【LeetCode】217.存在重复元素

    217. 存在重复元素 知识点:数组:Set: 题目描述 给定一个整数数组,判断是否存在重复元素. 如果存在一值在数组中出现至少两次,函数返回 true .如果数组中每个元素都不相同,则返回 fals ...

  5. Apache HBase 1.7.1 发布,分布式数据库

    Apache HBase 是一个开源的.分布式的.版本化的.非关系的数据库.Apache HBase 提供对数十亿个数据的低延迟随机访问在非专用硬件上有数百万列的行. 关于 HBase更多内容,请参阅 ...

  6. PAT甲级:1025 PAT Ranking (25分)

    PAT甲级:1025 PAT Ranking (25分) 题干 Programming Ability Test (PAT) is organized by the College of Comput ...

  7. JavaScript实现拖放效果

    JavaScript实现拖放效果 笔者实现该效果也是套用别人的轮子的.传送门 然后厚颜无耻的贴别人的readme~,笔者为了方便查阅就直接贴了,有不想移步的可以看这篇.不过还是最好请到原作者的GitH ...

  8. Pycharm关联gitlab(http方式)

    Pycharm支持关联gitlab仓库,关联后对远端项目的克隆和提交都很方便.当初笔者在关联时遇到了很多坑,网上也没找到相关解决办法,所以在这里分享下完整的关联过程. 一.安装git 下载地址http ...

  9. 开机时自动启动的AutoHotkey脚本 2019年07月08日19时06分

    ;;; 开机时自动启动的AutoHotkey脚本;; 此脚本修改时间 2019年06月18日20时48分;; 计时器创建代码段 ------------------------------------ ...

  10. Maven项目思考&实战

    参考了网络上很多文章, 特此感谢. Maven项目规范 同一项目中所有模块版本保持一致 子模块统一继承父模块的版本 统一在顶层模块Pom的节中定义所有子模块的依赖版本号,子模块中添加依赖时不要添加版本 ...