程序入口
import 'package:flutter/material.dart' ;
void main ( ) {
runApp (
MaterialApp (
home: Scaffold (
appBar: AppBar ( title: const Text ( "你好Flutter" ) ) ,
body: const MyApp ( ) ,
) ,
) ,
) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return const Center (
child: Text (
"你好Flutter 我是一个自定义组件" ,
textDirection: TextDirection . ltr,
style: TextStyle (
color: Colors . red,
fontSize: 40 ) ,
) ,
) ;
}
}
Container 和 Text 组件 import 'package:flutter/material.dart' ;
void main ( ) {
runApp ( MaterialApp (
home: Scaffold (
appBar: AppBar ( title: const Text ( "你好Flutter" ) ) ,
body: Column ( children: const [ MyApp ( ) , MyButton ( ) , MyText ( ) ] ) ) ,
) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return Center (
child: Container (
margin: const EdgeInsets . fromLTRB ( 0 , 60 , 0 , 0 ) ,
alignment: Alignment . center,
width: 200 ,
height: 200 ,
transform: Matrix4 . skewY ( .2 ) ,
decoration: BoxDecoration (
color: Colors . yellow,
border: Border . all (
color: Colors . red,
width: 2 ) ,
borderRadius: BorderRadius . circular ( 10 ) ,
boxShadow: const [
BoxShadow ( color: Colors . blue, blurRadius: 20.0 )
] ,
gradient:
const LinearGradient ( colors: [ Colors . red, Colors . yellow] ) ) ,
child: const Text (
"你好Flutter" ,
style: TextStyle ( color: Colors . black, fontSize: 20 ) ,
) ,
) ,
) ;
}
}
class MyButton extends StatelessWidget {
const MyButton ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return Container (
alignment: Alignment . center,
width: 200 ,
height: 40 ,
margin: const EdgeInsets . fromLTRB ( 0 , 40 , 0 , 0 ) ,
decoration: BoxDecoration (
color: Colors . blue, borderRadius: BorderRadius . circular ( 20 ) ) ,
child:
const Text ( "按钮" , style: TextStyle ( color: Colors . white, fontSize: 20 ) ) ,
) ;
}
}
class MyText extends StatelessWidget {
const MyText ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return Container (
width: 200 ,
height: 200 ,
margin: const EdgeInsets . fromLTRB ( 0 , 40 , 0 , 0 ) ,
decoration: const BoxDecoration ( color: Colors . yellow) ,
child: const Text (
"你好我是Flutter你好我是Flutter你好我是Flutter你好我是Flutter你好我是Flutter" ,
textAlign: TextAlign . left,
overflow: TextOverflow . ellipsis,
maxLines: 1 ,
style: TextStyle (
fontSize: 20 ,
fontWeight: FontWeight . w900,
color: Colors . red,
fontStyle: FontStyle . italic,
letterSpacing: 2 ,
decoration: TextDecoration . underline,
decorationColor: Colors . black,
decorationStyle: TextDecorationStyle . dashed) ,
) ,
) ;
}
}
Image 组件 import 'package:flutter/material.dart' ;
void main ( ) {
runApp ( MaterialApp (
home: Scaffold (
appBar: AppBar ( title: const Text ( "你好Flutter" ) ) ,
body: Column (
children: const [
MyApp ( ) ,
SizedBox ( height: 10 , ) ,
Circular ( ) ,
SizedBox ( height: 10 ) ,
ClipImage ( ) ,
SizedBox ( height: 10 ) ,
LoaclImage ( )
] ,
)
) ,
) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return Center (
child: Container (
margin: const EdgeInsets . fromLTRB ( 0 , 20 , 0 , 0 ) ,
height: 150 ,
width: 150 ,
decoration: const BoxDecoration (
color: Colors . yellow
) ,
child: Image . network (
"https://www.itying.com/themes/itying/images/ionic4.png" ,
) ,
)
) ;
}
}
class Circular extends StatelessWidget {
const Circular ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return Container (
height: 150 ,
width: 150 ,
decoration: BoxDecoration (
color: Colors . yellow,
borderRadius: BorderRadius . circular ( 75 ) ,
image: const DecorationImage (
image: NetworkImage ( "https://www.itying.com/themes/itying/images/ionic4.png" ) ,
fit: BoxFit . cover
)
) ,
) ;
}
}
class ClipImage extends StatelessWidget {
const ClipImage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return ClipOval (
child: Image . network (
"https://www.itying.com/images/201906/goods_img/1120_P_1560842352183.png" ,
width: 150 ,
height: 150 ,
fit: BoxFit . cover,
) ,
) ;
}
}
class LoaclImage extends StatelessWidget {
const LoaclImage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return Container (
height: 150 ,
width: 150 ,
decoration: const BoxDecoration (
color: Colors . yellow,
) ,
child: Image . asset ( "images/a.jpeg" , fit: BoxFit . cover, ) ,
) ;
}
}
Icon 组件 与 自定义图标 import 'package:flutter/material.dart' ;
import './ityingFont.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
theme: ThemeData (
primarySwatch: Colors . yellow,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter ICON" ) ) ,
body: const MyHomePage ( ) ,
) ,
) ;
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return Column (
children: const [
SizedBox ( height: 20 ) ,
Icon (
Icons . home,
size: 40 ,
color: Colors . red,
) ,
SizedBox ( height: 20 ) ,
Icon ( Icons . settings) ,
SizedBox ( height: 20 ) ,
Icon ( Icons . search) ,
SizedBox ( height: 20 ) ,
Icon ( Icons . personal_injury_outlined) ,
SizedBox ( height: 20 ) ,
Icon (
Icons . category,
size: 60 ,
color: Colors . blue,
) ,
Icon (
Icons . category,
size: 60 ,
color: Colors . blue,
) ,
Icon (
Icons . shop,
size: 60 ,
color: Colors . red,
) ,
SizedBox ( height: 40 ) ,
Icon (
ItyingIcon . book,
size: 40 ,
color: Colors . orange,
) ,
SizedBox ( height: 20 ) ,
Icon (
ItyingIcon . weixin,
size: 40 ,
color: Colors . green,
) ,
SizedBox ( height: 20 ) ,
Icon (
ItyingIcon . yonghu,
size: 30 ,
color: Colors . black,
) ,
SizedBox ( height: 20 ) ,
Icon (
ItyingIcon . address
) ,
SizedBox ( height: 20 ) ,
Icon (
ItyingIcon . category
) ,
] ,
) ;
}
}
import 'package:flutter/material.dart' ;
class ItyingIcon {
static const IconData book= IconData (
0x3447 ,
fontFamily: "ityingIcon" ,
matchTextDirection: true
) ;
static const IconData weixin= IconData (
0xf0106 ,
fontFamily: "ityingIcon" ,
matchTextDirection: true
) ;
static const IconData cart= IconData (
0xf0179 ,
fontFamily: "ityingIcon" ,
matchTextDirection: true
) ;
static const IconData yonghu= IconData (
0xe633 ,
fontFamily: "flutterIcon" ,
matchTextDirection: true
) ;
static const IconData address= IconData (
0xe64e ,
fontFamily: "flutterIcon" ,
matchTextDirection: true
) ;
static const IconData category= IconData (
0xe71b ,
fontFamily: "flutterIcon" ,
matchTextDirection: true
) ;
}
ListView 组件 main01.dart main02.dart main03.dart main04.dart main05.dart main06.dart main.dart import 'package:flutter/material.dart' ;
import './ityingFont.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
theme: ThemeData (
primarySwatch: Colors . yellow,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter ICON" ) ) ,
body: const MyHomePage ( ) ,
) ,
) ;
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return ListView (
children: const [
SizedBox ( height: 20 ) ,
Icon (
Icons . home,
size: 40 ,
color: Colors . red,
) ,
SizedBox ( height: 20 ) ,
Icon ( Icons . settings) ,
SizedBox ( height: 20 ) ,
Icon ( Icons . search) ,
SizedBox ( height: 20 ) ,
Icon ( Icons . personal_injury_outlined) ,
SizedBox ( height: 20 ) ,
Icon (
Icons . category,
size: 60 ,
color: Colors . blue,
) ,
Icon (
Icons . category,
size: 60 ,
color: Colors . blue,
) ,
Icon (
Icons . shop,
size: 60 ,
color: Colors . red,
) ,
SizedBox ( height: 40 ) ,
Icon (
ItyingIcon . book,
size: 40 ,
color: Colors . orange,
) ,
SizedBox ( height: 20 ) ,
Icon (
ItyingIcon . weixin,
size: 40 ,
color: Colors . green,
) ,
SizedBox ( height: 20 ) ,
Icon (
ItyingIcon . yonghu,
size: 30 ,
color: Colors . black,
) ,
SizedBox ( height: 20 ) ,
Icon (
ItyingIcon . address
) ,
SizedBox ( height: 20 ) ,
Icon (
ItyingIcon . category
) ,
SizedBox ( height: 20 ) ,
Icon (
ItyingIcon . weixin,
size: 40 ,
color: Colors . green,
) ,
SizedBox ( height: 20 ) ,
Icon (
ItyingIcon . yonghu,
size: 30 ,
color: Colors . black,
) ,
SizedBox ( height: 20 ) ,
Icon (
ItyingIcon . address
) ,
SizedBox ( height: 20 ) ,
Icon (
ItyingIcon . category
) ,
] ,
) ;
}
}
import 'package:flutter/material.dart' ;
import './ityingFont.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
theme: ThemeData (
primarySwatch: Colors . yellow,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter ICON" ) ) ,
body: const MyHomePage ( ) ,
) ,
) ;
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return ListView (
children: const < Widget > [
ListTile ( title: Text ( "我是一个列表" ) ) ,
Divider ( ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
Divider ( ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
Divider ( ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
Divider ( ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
Divider ( ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
Divider ( ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
Divider ( ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
Divider ( ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
Divider ( ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
Divider ( ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
Divider ( ) ,
] ,
) ;
}
}
import 'package:flutter/material.dart' ;
import './ityingFont.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
theme: ThemeData (
primarySwatch: Colors . yellow,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter ICON" ) ) ,
body: const MyHomePage ( ) ,
) ,
) ;
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return ListView (
children: const < Widget > [
ListTile ( leading: Icon ( Icons . home) , title: Text ( "首页" ) ) ,
Divider ( ) ,
ListTile (
leading: Icon ( Icons . assignment, color: Colors . red) ,
title: Text ( "全部订单" ) ,
) ,
Divider ( ) ,
ListTile (
leading: Icon ( Icons . payment, color: Colors . green) ,
title: Text ( "待付款" ) ,
) ,
ListTile (
leading: Icon ( Icons . favorite, color: Colors . lightGreen) ,
title: Text ( "我的收藏" ) ,
trailing: Icon ( Icons . chevron_right_sharp) ,
) ,
Divider ( ) ,
ListTile (
leading: Icon ( Icons . people, color: Colors . black54) ,
title: Text ( "在线客服" ) ,
trailing: Icon ( Icons . chevron_right_sharp) ,
) ,
Divider ( ) ,
] ,
) ;
}
}
import 'package:flutter/material.dart' ;
import './ityingFont.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
theme: ThemeData (
primarySwatch: Colors . yellow,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter ICON" ) ) ,
body: const MyHomePage ( ) ,
) ,
) ;
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return ListView (
padding: const EdgeInsets . fromLTRB ( 0 , 10 , 0 , 0 ) ,
children: < Widget > [
ListTile (
leading: Image . network ( "https://www.itying.com/images/flutter/1.png" ) ,
title: const Text ( "国铁集团:保障重点物资运输 新华述评 研讨会举行" ) ,
) ,
const Divider ( ) ,
ListTile (
leading: Image . network ( "https://www.itying.com/images/flutter/1.png" ) ,
title: const Text ( "国铁集团:保障重点物资运输 新华述评 研讨会举行" ) ,
) ,
ListTile (
leading: Image . network ( "https://www.itying.com/images/flutter/2.png" ) ,
title: const Text ( '保监局50天开32罚单 “断供”违规资金为房市降温' ) ,
subtitle: const Text ( "中国天气网讯 保监局50天开32罚单 “断供”违规资金为房市降 温" ) ,
) ,
const Divider ( ) ,
ListTile (
leading: Image . network ( "https://www.itying.com/images/flutter/4.png" ) ,
title: const Text ( '普京现身俄海军节阅兵:乘艇检阅军舰' ) ,
) ,
ListTile (
leading:
Image . network ( "https://www.itying.com/images/flutter/2.png" ) ,
title: const Text ( '保监局50天开32罚单 “断供”违规资金为房市降温' ) ,
subtitle: const Text ( "中国天气网讯 保监局50天开32罚单 “断供”违规资金为房市降 温" ) ,
trailing:
Image . network ( "https://www.itying.com/images/flutter/4.png" ) ) ,
ListTile (
title: const Text ( '保监局50天开32罚单 “断供”违规资金为房市降温' ) ,
subtitle: const Text ( "中国天气网讯 保监局50天开32罚单 “断供”违规资金为房市降 温" ) ,
trailing:
Image . network ( "https://www.itying.com/images/flutter/5.png" ) ) ,
] ,
) ;
}
}
import 'package:flutter/material.dart' ;
import './ityingFont.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
theme: ThemeData (
primarySwatch: Colors . yellow,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter ICON" ) ) ,
body: const MyHomePage ( ) ,
) ,
) ;
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return ListView (
padding: const EdgeInsets . all ( 10 ) ,
children: < Widget > [
Image . network ( "https://www.itying.com/images/flutter/1.png" ) ,
Container (
padding: const EdgeInsets . fromLTRB ( 0 , 6 , 0 , 0 ) ,
height: 44 ,
child: const Text (
"我是一个标题" ,
textAlign: TextAlign . center,
style: TextStyle ( fontSize: 22 ) ) ,
) ,
Image . network ( "https://www.itying.com/images/flutter/3.png" ) ,
Container (
padding: const EdgeInsets . fromLTRB ( 0 , 6 , 0 , 0 ) ,
height: 44 ,
child: const Text (
"我是一个标题" ,
textAlign: TextAlign . center,
style: TextStyle ( fontSize: 22 ) ) ,
) ,
Image . network ( "https://www.itying.com/images/flutter/2.png" ) ,
Container (
padding: const EdgeInsets . fromLTRB ( 0 , 6 , 0 , 0 ) ,
height: 44 ,
child: const Text (
"我是一个标题" ,
textAlign: TextAlign . center,
style: TextStyle ( fontSize: 22 ) ) ,
) ,
Image . network ( "https://www.itying.com/images/flutter/4.png" ) ,
Container (
padding: const EdgeInsets . fromLTRB ( 0 , 6 , 0 , 0 ) ,
height: 44 ,
child: const Text (
"我是一个标题" ,
textAlign: TextAlign . center,
style: TextStyle ( fontSize: 22 ) ) ,
) ,
Image . network ( "https://www.itying.com/images/flutter/5.png" ) ,
Container (
padding: const EdgeInsets . fromLTRB ( 0 , 6 , 0 , 0 ) ,
height: 44 ,
child: const Text (
"我是一个标题" ,
textAlign: TextAlign . center,
style: TextStyle ( fontSize: 22 ) ) ,
) ,
Image . network ( "https://www.itying.com/images/flutter/6.png" ) ,
] ,
) ;
}
}
import 'package:flutter/material.dart' ;
import './ityingFont.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
theme: ThemeData (
primarySwatch: Colors . yellow,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter ICON" ) ) ,
body: const MyHomePage ( ) ,
) ,
) ;
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return ListView (
padding: const EdgeInsets . all ( 10 ) ,
children: < Widget > [
Container (
height: 120 ,
width: 120 ,
decoration: const BoxDecoration (
color: Colors . red
) ,
) ,
Container (
height: 120 ,
width: 120 ,
decoration: const BoxDecoration (
color: Colors . yellow
) ,
) ,
Container (
height: 120 ,
decoration: const BoxDecoration (
color: Colors . orange
) ,
) , Container (
height: 120 ,
decoration: const BoxDecoration (
color: Colors . black
) ,
) , Container (
height: 120 ,
decoration: const BoxDecoration (
color: Colors . blue
) ,
) , Container (
height: 120 ,
decoration: const BoxDecoration (
color: Colors . red
) ,
) , Container (
height: 120 ,
decoration: const BoxDecoration (
color: Colors . pink
) ,
) , Container (
height: 120 ,
decoration: const BoxDecoration (
color: Colors . blueGrey
) ,
) ,
] ,
) ;
}
}
import 'package:flutter/material.dart' ;
import './ityingFont.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
theme: ThemeData (
primarySwatch: Colors . yellow,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter ICON" ) ) ,
body: const MyHomePage ( ) ,
) ,
) ;
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return SizedBox (
height: 120 ,
child: ListView (
scrollDirection: Axis . horizontal,
padding: const EdgeInsets . all ( 10 ) ,
children: < Widget > [
Container (
width: 120 ,
decoration: const BoxDecoration ( color: Colors . white) ,
child: Column (
children: [
SizedBox (
height: 80 ,
child: Image . network ( "https://www.itying.com/images/flutter/1.png" , fit: BoxFit . cover, ) ,
) ,
const Text ( "文字" )
] ,
) ,
) ,
Container (
width: 120 ,
decoration: const BoxDecoration ( color: Colors . yellow) ,
) ,
Container (
height: 120 ,
width: 120 ,
decoration: const BoxDecoration ( color: Colors . orange) ,
) ,
Container (
width: 120 ,
decoration: const BoxDecoration ( color: Colors . black) ,
) ,
Container (
width: 120 ,
decoration: const BoxDecoration ( color: Colors . blue) ,
) ,
Container (
width: 120 ,
decoration: const BoxDecoration ( color: Colors . red) ,
) ,
Container (
width: 120 ,
decoration: const BoxDecoration ( color: Colors . pink) ,
) ,
Container (
width: 120 ,
decoration: const BoxDecoration ( color: Colors . blueGrey) ,
) ,
] ,
) ,
) ;
}
}
ListView 动态数据 main01.dart listData.dart main02.dart main03.dart import 'package:flutter/material.dart' ;
import "./res/listData.dart" ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter List" ) ) ,
body: MyHomePage ( ) ,
) ,
) ;
}
}
class MyHomePage extends StatelessWidget {
MyHomePage ( { Key ? key} ) : super ( key: key) {
print ( listData) ;
}
List < Widget > _initListData ( ) {
var tempList = listData. map ( ( value) {
return ListTile (
leading: Image . network ( "${value[" imageUrl"]}" ) ,
title: Text ( "${value[" title"]}" ) ,
subtitle: Text ( "${value[" author"]}" ) ,
) ;
} ) ;
return tempList. toList ( ) ;
}
@override
Widget build ( BuildContext context) {
return ListView (
children: _initListData ( ) ,
) ;
}
}
List listData= [
{
"title" : 'Candy Shop' ,
"author" : 'Mohamed Chahin' ,
"imageUrl" : 'https://www.itying.com/images/flutter/1.png' ,
} ,
{
"title" : 'Childhood in a picture' ,
"author" : 'Google' ,
"imageUrl" : 'https://www.itying.com/images/flutter/2.png' ,
} ,
{
"title" : 'Alibaba Shop' ,
"author" : 'Alibaba' ,
"imageUrl" : 'https://www.itying.com/images/flutter/3.png' ,
} ,
{
"title" : 'Candy Shop' ,
"author" : 'Mohamed Chahin' ,
"imageUrl" : 'https://www.itying.com/images/flutter/4.png' ,
} ,
{
"title" : 'Tornado' ,
"author" : 'Mohamed Chahin' ,
"imageUrl" : 'https://www.itying.com/images/flutter/5.png' ,
} ,
{
"title" : 'Undo' ,
"author" : 'Mohamed Chahin' ,
"imageUrl" : 'https://www.itying.com/images/flutter/6.png' ,
} ,
{
"title" : 'white-dragon' ,
"author" : 'Mohamed Chahin' ,
"imageUrl" : 'https://www.itying.com/images/flutter/7.png' ,
}
] ;
import 'package:flutter/material.dart' ;
import "./res/listData.dart" ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter List" ) ) ,
body: MyHomePage ( ) ,
) ,
) ;
}
}
class MyHomePage extends StatelessWidget {
List < String > list= [ ] ;
MyHomePage ( { Key ? key} ) : super ( key: key) {
for ( var i = 0 ; i < 20 ; i++ ) {
list. add ( "我是第 ${ i } 条数据" ) ;
}
}
@override
Widget build ( BuildContext context) {
return ListView . builder (
itemCount: list. length ,
itemBuilder: ( context, index) {
return ListTile (
title: Text ( list[ index] ) ,
) ;
}
) ;
}
}
import 'package:flutter/material.dart' ;
import "./res/listData.dart" ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter List" ) ) ,
body: const MyHomePage ( ) ,
) ,
) ;
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return ListView . builder (
itemCount: listData. length,
itemBuilder: ( context, i) {
return ListTile (
leading: Image . network ( listData[ i] [ "imageUrl" ] ) ,
title: Text ( listData[ i] [ "title" ] ) ,
subtitle: Text ( listData[ i] [ "author" ] ) ,
) ;
}
) ;
}
}
GridView 组件 main01.dart main02.dart main03.dart main04.dart main05.dart main06.dart main07.dart main.dart import 'package:flutter/material.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const HomePage ( ) ,
) ,
) ;
}
}
class HomePage extends StatelessWidget {
const HomePage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return GridView . count (
crossAxisCount: 5 ,
children: const [
Icon ( Icons . pedal_bike) ,
Icon ( Icons . home) ,
Icon ( Icons . ac_unit) ,
Icon ( Icons . search) ,
Icon ( Icons . settings) ,
Icon ( Icons . airport_shuttle) ,
Icon ( Icons . all_inclusive) ,
Icon ( Icons . beach_access) ,
Icon ( Icons . cake) ,
Icon ( Icons . circle) ,
] ,
) ;
}
}
import 'package:flutter/material.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const HomePage ( ) ,
) ,
) ;
}
}
class HomePage extends StatelessWidget {
const HomePage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return GridView . extent (
maxCrossAxisExtent: 180 ,
children: const [
Icon ( Icons . pedal_bike) ,
Icon ( Icons . home) ,
Icon ( Icons . ac_unit) ,
Icon ( Icons . search) ,
Icon ( Icons . settings) ,
Icon ( Icons . airport_shuttle) ,
Icon ( Icons . all_inclusive) ,
Icon ( Icons . beach_access) ,
Icon ( Icons . cake) ,
Icon ( Icons . circle) ,
] ,
) ;
}
}
import 'package:flutter/material.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const HomePage ( ) ,
) ,
) ;
}
}
class HomePage extends StatelessWidget {
const HomePage ( { Key ? key} ) : super ( key: key) ;
List < Widget > _initGridViewData ( ) {
List < Widget > tempList= [ ] ;
for ( var i = 0 ; i < 12 ; i++ ) {
tempList. add (
Container (
alignment: Alignment . center,
decoration: const BoxDecoration (
color: Colors . blue
) ,
child: Text ( "第 ${ i } 个元素" , style: const TextStyle (
fontSize: 20
) )
)
) ;
}
return tempList;
}
@override
Widget build ( BuildContext context) {
return GridView . count (
padding: const EdgeInsets . all ( 10 ) ,
crossAxisSpacing: 10 ,
mainAxisSpacing: 10 ,
crossAxisCount: 3 ,
childAspectRatio: 1.2 ,
children: _initGridViewData ( ) ,
) ;
}
}
import 'package:flutter/material.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const HomePage ( ) ,
) ,
) ;
}
}
class HomePage extends StatelessWidget {
const HomePage ( { Key ? key} ) : super ( key: key) ;
List < Widget > _initGridViewData ( ) {
List < Widget > tempList= [ ] ;
for ( var i = 0 ; i < 12 ; i++ ) {
tempList. add (
Container (
alignment: Alignment . center,
decoration: const BoxDecoration (
color: Colors . blue
) ,
child: Text ( "第 ${ i } 个元素" , style: const TextStyle (
fontSize: 20
) )
)
) ;
}
return tempList;
}
@override
Widget build ( BuildContext context) {
return GridView . extent (
padding: const EdgeInsets . all ( 10 ) ,
crossAxisSpacing: 10 ,
mainAxisSpacing: 10 ,
maxCrossAxisExtent: 250 ,
childAspectRatio: 0.7 ,
children: _initGridViewData ( ) ,
) ;
}
}
import 'package:flutter/material.dart' ;
import './res/listData.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const HomePage ( ) ,
) ,
) ;
}
}
class HomePage extends StatelessWidget {
const HomePage ( { Key ? key} ) : super ( key: key) ;
List < Widget > _initGridViewData ( ) {
var tempList= listData. map ( ( value) {
return Container (
decoration: BoxDecoration (
border: Border . all (
color: Colors . black26
)
) ,
child: Column (
children: [
Image . network ( value[ "imageUrl" ] ) ,
const SizedBox ( height: 10 ) ,
Text ( value[ "title" ] , style: const TextStyle (
fontSize: 18
) )
] ,
) ,
) ;
} ) ;
return tempList. toList ( ) ;
}
@override
Widget build ( BuildContext context) {
return GridView . count (
padding: const EdgeInsets . all ( 10 ) ,
crossAxisSpacing: 10 ,
mainAxisSpacing: 10 ,
crossAxisCount: 2 ,
childAspectRatio: 1 ,
children: _initGridViewData ( ) ,
) ;
}
}
import 'package:flutter/material.dart' ;
import './res/listData.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const HomePage ( ) ,
) ,
) ;
}
}
class HomePage extends StatelessWidget {
const HomePage ( { Key ? key} ) : super ( key: key) ;
Widget _initGridViewData ( context, index) {
return Container (
decoration: BoxDecoration ( border: Border . all ( color: Colors . black26) ) ,
child: Column (
children: [
Image . network ( listData[ index] [ "imageUrl" ] ) ,
const SizedBox ( height: 10 ) ,
Text ( listData[ index] [ "title" ] , style: const TextStyle ( fontSize: 18 ) )
] ,
) ,
) ;
}
@override
Widget build ( BuildContext context) {
return GridView . builder (
padding: const EdgeInsets . all ( 10 ) ,
itemCount: listData. length,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount (
crossAxisSpacing: 10 ,
mainAxisSpacing: 10 ,
crossAxisCount: 2 ,
childAspectRatio: 1 ,
) ,
itemBuilder: _initGridViewData) ;
}
}
import 'package:flutter/material.dart' ;
import './res/listData.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const HomePage ( ) ,
) ,
) ;
}
}
class HomePage extends StatelessWidget {
const HomePage ( { Key ? key} ) : super ( key: key) ;
Widget _initGridViewData ( context, index) {
return Container (
decoration: BoxDecoration ( border: Border . all ( color: Colors . black26) ) ,
child: Column (
children: [
Image . network ( listData[ index] [ "imageUrl" ] ) ,
const SizedBox ( height: 10 ) ,
Text ( listData[ index] [ "title" ] , style: const TextStyle ( fontSize: 18 ) )
] ,
) ,
) ;
}
@override
Widget build ( BuildContext context) {
return GridView . builder (
padding: const EdgeInsets . all ( 10 ) ,
itemCount: listData. length,
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent (
crossAxisSpacing: 10 ,
mainAxisSpacing: 10 ,
childAspectRatio: 0.9 ,
maxCrossAxisExtent: 120 ,
) ,
itemBuilder: _initGridViewData) ;
}
}
import 'package:flutter/material.dart' ;
import './res/listData.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const HomePage ( ) ,
) ,
) ;
}
}
class HomePage extends StatelessWidget {
const HomePage ( { Key ? key} ) : super ( key: key) ;
Widget _initGridViewData ( context, index) {
return Container (
decoration: BoxDecoration ( border: Border . all ( color: Colors . black26) ) ,
child: Column (
children: [
Image . network ( listData[ index] [ "imageUrl" ] ) ,
const SizedBox ( height: 10 ) ,
Text ( listData[ index] [ "title" ] , style: const TextStyle ( fontSize: 18 ) )
] ,
) ,
) ;
}
@override
Widget build ( BuildContext context) {
return GridView . builder (
padding: const EdgeInsets . all ( 10 ) ,
itemCount: listData. length,
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent (
crossAxisSpacing: 10 ,
mainAxisSpacing: 10 ,
childAspectRatio: 0.9 ,
maxCrossAxisExtent: 120 ,
) ,
itemBuilder: _initGridViewData) ;
}
}
Padding Row Column Flex Expanded padding.dart row.dart column.dart flex.dart expanded.dart layoutDemo.dart layouteDemo2.dart import 'package:flutter/material.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const HomePage ( ) ,
) ,
) ;
}
}
class HomePage extends StatelessWidget {
const HomePage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return const Padding (
padding: EdgeInsets . all ( 20 ) ,
child: Text ( "你好flutter" ) ,
) ;
}
}
import 'package:flutter/material.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const HomePage ( ) ,
) ,
) ;
}
}
class HomePage extends StatelessWidget {
const HomePage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return Container (
width: double. infinity,
height: double. infinity,
color: Colors . black12,
child: Row (
mainAxisAlignment: MainAxisAlignment . spaceBetween,
crossAxisAlignment: CrossAxisAlignment . center,
children: [
IconContainer ( Icons . home) ,
IconContainer (
Icons . search,
color: Colors . yellow,
) ,
IconContainer (
Icons . ac_unit_sharp,
color: Colors . orange,
) ,
] ,
) ,
) ;
}
}
class IconContainer extends StatelessWidget {
Color color;
IconData icon;
IconContainer ( this . icon, { Key ? key, this . color = Colors . red} )
: super ( key: key) ;
@override
Widget build ( BuildContext context) {
return Container (
alignment: Alignment . center,
height: 100 ,
width: 100 ,
color: color,
child: Icon ( icon, color: Colors . white, size: 28 ) ,
) ;
}
}
import 'package:flutter/material.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const HomePage ( ) ,
) ,
) ;
}
}
class HomePage extends StatelessWidget {
const HomePage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return Container (
width: double. infinity,
height: double. infinity,
color: Colors . black12,
child: Column (
mainAxisAlignment: MainAxisAlignment . spaceEvenly,
crossAxisAlignment: CrossAxisAlignment . end,
children: [
IconContainer ( Icons . home) ,
IconContainer (
Icons . search,
color: Colors . yellow,
) ,
IconContainer (
Icons . ac_unit_sharp,
color: Colors . orange,
) ,
] ,
) ,
) ;
}
}
class IconContainer extends StatelessWidget {
Color color;
IconData icon;
IconContainer ( this . icon, { Key ? key, this . color = Colors . red} )
: super ( key: key) ;
@override
Widget build ( BuildContext context) {
return Container (
alignment: Alignment . center,
height: 100 ,
width: 100 ,
color: color,
child: Icon ( icon, color: Colors . white, size: 28 ) ,
) ;
}
}
import 'package:flutter/material.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const HomePage ( ) ,
) ,
) ;
}
}
class HomePage extends StatelessWidget {
const HomePage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return Flex (
direction: Axis . horizontal,
children: [
Expanded (
flex: 1 ,
child: IconContainer ( Icons . home) ,
) ,
Expanded (
flex: 2 ,
child: IconContainer (
Icons . ac_unit_sharp,
color: Colors . orange,
) ,
) ,
] ,
) ;
}
}
class IconContainer extends StatelessWidget {
Color color;
IconData icon;
IconContainer ( this . icon, { Key ? key, this . color = Colors . red} )
: super ( key: key) ;
@override
Widget build ( BuildContext context) {
return Container (
alignment: Alignment . center,
height: 100 ,
width: 100 ,
color: color,
child: Icon ( icon, color: Colors . white, size: 28 ) ,
) ;
}
}
import 'package:flutter/material.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const HomePage ( ) ,
) ,
) ;
}
}
class HomePage extends StatelessWidget {
const HomePage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return Row (
children: [
Expanded (
flex: 1 ,
child: IconContainer ( Icons . home) ,
) ,
IconContainer (
Icons . ac_unit_sharp,
color: Colors . orange,
)
] ,
) ;
}
}
class IconContainer extends StatelessWidget {
Color color;
IconData icon;
IconContainer ( this . icon, { Key ? key, this . color = Colors . red} )
: super ( key: key) ;
@override
Widget build ( BuildContext context) {
return Container (
alignment: Alignment . center,
height: 80 ,
width: 80 ,
color: color,
child: Icon ( icon, color: Colors . white, size: 28 ) ,
) ;
}
}
import 'package:flutter/material.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const HomePage ( ) ,
) ,
) ;
}
}
class HomePage extends StatelessWidget {
const HomePage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return ListView (
children: [
Container (
width: double. infinity,
height: 200 ,
color: Colors . black,
) ,
const SizedBox ( height: 10 ) ,
Row (
children: [
Expanded (
flex: 2 ,
child: SizedBox (
height: 180 ,
child: Image . network (
"https://www.itying.com/images/flutter/2.png" ,
fit: BoxFit . cover) ,
) ,
) ,
const SizedBox ( width: 10 ) ,
Expanded (
flex: 1 ,
child: SizedBox (
height: 180 ,
child: Column (
children: [
Expanded (
flex: 1 ,
child: SizedBox (
width: double. infinity,
child: Image . network (
"https://www.itying.com/images/flutter/3.png" ,
fit: BoxFit . cover) ,
) ,
) ,
const SizedBox ( height: 10 ) ,
Expanded (
flex: 2 ,
child: SizedBox (
width: double. infinity,
child: Image . network (
"https://www.itying.com/images/flutter/4.png" ,
fit: BoxFit . cover) ,
) ,
)
] ,
) ,
) ,
)
] ,
)
] ,
) ;
}
}
import 'package:flutter/material.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const HomePage ( ) ,
) ,
) ;
}
}
class HomePage extends StatelessWidget {
const HomePage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return ListView (
children: [
Container (
width: double. infinity,
height: 200 ,
color: Colors . black,
) ,
const SizedBox ( height: 10 ) ,
Row (
children: [
Expanded (
flex: 2 ,
child: SizedBox (
height: 180 ,
child: Image . network (
"https://www.itying.com/images/flutter/2.png" ,
fit: BoxFit . cover) ,
) ,
) ,
const SizedBox ( width: 10 ) ,
Expanded (
flex: 1 ,
child: SizedBox (
height: 180 ,
child: Column (
children: [
Expanded (
flex: 1 ,
child: SizedBox (
width: double. infinity,
child: Image . network (
"https://www.itying.com/images/flutter/3.png" ,
fit: BoxFit . cover) ,
) ,
) ,
const SizedBox ( height: 10 ) ,
Expanded (
flex: 2 ,
child: SizedBox (
width: double. infinity,
child: Image . network (
"https://www.itying.com/images/flutter/4.png" ,
fit: BoxFit . cover) ,
) ,
)
] ,
) ,
) ,
)
] ,
)
] ,
) ;
}
}
Stack Align Positioned main01.dart main02.dart main03.dart main04.dart main05.dart main06.dart main07.dart main.dart import 'package:flutter/material.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const HomePage ( ) ,
) ,
) ;
}
}
class HomePage extends StatelessWidget {
const HomePage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return Stack (
alignment: Alignment . center,
children: [
Container (
height: 400 ,
width: 300 ,
color: Colors . red,
) ,
Container (
height: 200 ,
width: 200 ,
color: Colors . yellow,
) ,
const Text ( "你好Flutter" ) ,
const Text ( "你好Flutter1111" )
] ,
) ;
}
}
import 'package:flutter/material.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const HomePage ( ) ,
) ,
) ;
}
}
class HomePage extends StatelessWidget {
const HomePage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return Center (
child: Container (
height: 400 ,
width: 300 ,
color: Colors . red,
child: Stack (
children: [
Positioned (
left: 0 ,
bottom: 0 ,
child: Container (
height: 100 ,
width: 100 ,
color: Colors . yellow,
) ) ,
const Positioned (
top: 190 ,
right: 0 ,
child: Text ( "你好Flutter" )
)
] ,
) ,
) ,
) ;
}
}
import 'package:flutter/material.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const HomePage ( ) ,
) ,
) ;
}
}
class HomePage extends StatelessWidget {
const HomePage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
final size = MediaQuery . of ( context) . size;
return Stack (
children: [
ListView (
padding: const EdgeInsets . only ( top: 50 ) ,
children: const [
ListTile ( title: Text ( "我是一个列表1" ) ) ,
ListTile ( title: Text ( "我是一个列表2" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
] ,
) ,
Positioned (
left: 0 ,
top: 0 ,
width: size. width,
height: 44 ,
child: Row (
children: [
Expanded (
flex: 1 ,
child: Container (
alignment: Alignment . center,
height: 44 ,
color: Colors . black,
child: const Text (
"二级导航" ,
style: TextStyle ( color: Colors . white) ,
) ,
) ,
)
] ,
) ,
)
] ,
) ;
}
}
import 'package:flutter/material.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const HomePage ( ) ,
) ,
) ;
}
}
class HomePage extends StatelessWidget {
const HomePage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
final size = MediaQuery . of ( context) . size;
return Stack (
children: [
ListView (
children: const [
ListTile ( title: Text ( "我是一个列表1" ) ) ,
ListTile ( title: Text ( "我是一个列表2" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
ListTile ( title: Text ( "我是一个列表" ) ) ,
] ,
) ,
Positioned (
left: 0 ,
bottom: 0 ,
width: size. width,
height: 44 ,
child: Container (
alignment: Alignment . center,
color: Colors . black,
child: const Text (
"二级导航" ,
style: TextStyle ( color: Colors . white) ,
) ,
) ,
)
] ,
) ;
}
}
import 'package:flutter/material.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const HomePage ( ) ,
) ,
) ;
}
}
class HomePage extends StatelessWidget {
const HomePage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return Container (
width: 300 ,
height: 300 ,
color: Colors . red,
child: const Align (
alignment: Alignment . center,
child: Text ( "你好Flutter" ) ,
) ,
) ;
}
}
import 'package:flutter/material.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const HomePage ( ) ,
) ,
) ;
}
}
class HomePage extends StatelessWidget {
const HomePage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return Container (
width: 300 ,
height: 300 ,
color: Colors . red,
child: const Align (
alignment: Alignment ( - 0.5 , 1 ) ,
child: Text ( "你好Flutter" ) ,
) ,
) ;
}
}
import 'package:flutter/material.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const HomePage ( ) ,
) ,
) ;
}
}
class HomePage extends StatelessWidget {
const HomePage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return Column (
children: [
SizedBox (
width: double. infinity,
height: 40 ,
child: Stack (
children: const [
Align (
alignment: Alignment . topLeft,
child: Text ( "收藏" ) ,
) ,
Align ( alignment: Alignment . topRight, child: Text ( "购买" ) ) ,
] ,
) ,
) ,
SizedBox (
width: double. infinity,
height: 40 ,
child: Stack (
children: const [
Positioned (
left: 10 ,
child: Text ( "收藏" ) ,
) ,
Positioned ( right: 10 , child: Text ( "购买" ) ) ,
] ,
) ,
)
] ,
) ;
}
}
import 'package:flutter/material.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const HomePage ( ) ,
) ,
) ;
}
}
class HomePage extends StatelessWidget {
const HomePage ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return Column (
children: [
SizedBox (
width: double. infinity,
height: 40 ,
child: Stack (
children: const [
Align (
alignment: Alignment . topLeft,
child: Text ( "收藏" ) ,
) ,
Align ( alignment: Alignment . topRight, child: Text ( "购买" ) ) ,
] ,
) ,
) ,
SizedBox (
width: double. infinity,
height: 40 ,
child: Stack (
children: const [
Positioned (
left: 10 ,
child: Text ( "收藏" ) ,
) ,
Positioned ( right: 10 , child: Text ( "购买" ) ) ,
] ,
) ,
)
] ,
) ;
}
}
AspectRatio 与 Card 组件 AspectRatio.dart Card.dart Card02.dart Card_List.dart main.dart import 'package:flutter/material.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const LayoutDemo ( ) ,
) ,
) ;
}
}
class LayoutDemo extends StatelessWidget {
const LayoutDemo ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return AspectRatio (
aspectRatio: 2 / 1 ,
child: Container (
color: Colors . red,
) ,
) ;
}
}
import 'package:flutter/material.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const LayoutDemo ( ) ,
) ,
) ;
}
}
class LayoutDemo extends StatelessWidget {
const LayoutDemo ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return ListView (
children: [
Card (
shape: RoundedRectangleBorder (
borderRadius: BorderRadius . circular ( 10 ) ) ,
elevation: 20 ,
margin: const EdgeInsets . all ( 10 ) ,
child: Column (
children: const [
ListTile (
title: Text ( "张三" , style: TextStyle ( fontSize: 28 ) ) ,
subtitle: Text ( "高级软件工程师" ) ,
) ,
Divider ( ) ,
ListTile (
title: Text ( "电话:152222222" ) ,
) ,
ListTile (
title: Text ( "地址:北京市海淀区 xxx" ) ,
) ,
] ,
) ,
) ,
Card (
shape: RoundedRectangleBorder (
borderRadius: BorderRadius . circular ( 10 ) ) ,
elevation: 20 ,
margin: const EdgeInsets . all ( 10 ) ,
child: Column (
children: const [
ListTile (
title: Text ( "李四" , style: TextStyle ( fontSize: 28 ) ) ,
subtitle: Text ( "Flutter高级软件工程师" ) ,
) ,
Divider ( ) ,
ListTile (
title: Text ( "电话:152222222" ) ,
) ,
ListTile (
title: Text ( "地址:北京市海淀区 xxx" ) ,
) ,
] ,
) ,
) ,
Card (
shape: RoundedRectangleBorder (
borderRadius: BorderRadius . circular ( 10 ) ) ,
elevation: 20 ,
margin: const EdgeInsets . all ( 10 ) ,
child: Column (
children: const [
ListTile (
title: Text ( "张三" , style: TextStyle ( fontSize: 28 ) ) ,
subtitle: Text ( "高级软件工程师" ) ,
) ,
Divider ( ) ,
ListTile (
title: Text ( "电话:152222222" ) ,
) ,
ListTile (
title: Text ( "地址:北京市海淀区 xxx" ) ,
) ,
] ,
) ,
) ,
] ,
) ;
}
}
import 'package:flutter/material.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const LayoutDemo ( ) ,
) ,
) ;
}
}
class LayoutDemo extends StatelessWidget {
const LayoutDemo ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return ListView (
children: [
Card (
shape: RoundedRectangleBorder (
borderRadius: BorderRadius . circular ( 10 )
) ,
elevation: 20 ,
margin: const EdgeInsets . all ( 10 ) ,
child: Column (
children: [
AspectRatio (
aspectRatio: 16 / 9 ,
child: Image . network (
"https://www.itying.com/images/flutter/3.png" ,
fit: BoxFit . cover) ,
) ,
ListTile (
leading: ClipOval (
child: Image . network (
"https://www.itying.com/images/flutter/3.png" ,
fit: BoxFit . cover,
height: 40 ,
width: 40 ,
) ,
) ,
title: const Text ( "xxxxxxxxx" ) ,
subtitle: const Text ( "xxxxxxxxx" ) ,
)
] ,
) ,
) ,
Card (
shape: RoundedRectangleBorder (
borderRadius: BorderRadius . circular ( 10 )
) ,
elevation: 20 ,
margin: const EdgeInsets . all ( 10 ) ,
child: Column (
children: [
AspectRatio (
aspectRatio: 16 / 9 ,
child: Image . network (
"https://www.itying.com/images/flutter/3.png" ,
fit: BoxFit . cover) ,
) ,
const ListTile (
leading: CircleAvatar (
backgroundImage: NetworkImage ( "https://www.itying.com/images/flutter/4.png" ) ,
) ,
title: Text ( "xxxxxxxxx" ) ,
subtitle: Text ( "xxxxxxxxx" ) ,
)
] ,
) ,
)
] ,
) ;
}
}
import 'package:flutter/material.dart' ;
import "./res/listData.dart" ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const LayoutDemo ( ) ,
) ,
) ;
}
}
class LayoutDemo extends StatelessWidget {
const LayoutDemo ( { Key ? key} ) : super ( key: key) ;
List < Widget > _initCardData ( ) {
var tempList = listData. map ( ( value) {
return Card (
shape: RoundedRectangleBorder (
borderRadius: BorderRadius . circular ( 10 )
) ,
elevation: 20 ,
margin: const EdgeInsets . all ( 10 ) ,
child: Column (
children: [
AspectRatio (
aspectRatio: 16 / 9 ,
child: Image . network (
value[ "imageUrl" ] ,
fit: BoxFit . cover) ,
) ,
ListTile (
leading: ClipOval (
child: Image . network (
value[ "imageUrl" ] ,
fit: BoxFit . cover,
height: 40 ,
width: 40 ,
) ,
) ,
title: Text ( value[ "title" ] ) ,
subtitle: Text ( value[ "author" ] ) ,
)
] ,
) ,
) ;
} ) ;
return tempList. toList ( ) ;
}
@override
Widget build ( BuildContext context) {
return ListView (
children: _initCardData ( ) ,
) ;
}
}
import 'package:flutter/material.dart' ;
import "./res/listData.dart" ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const LayoutDemo ( ) ,
) ,
) ;
}
}
class LayoutDemo extends StatelessWidget {
const LayoutDemo ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return ListView (
children: listData. map (
( value) {
return Card (
shape:
RoundedRectangleBorder ( borderRadius: BorderRadius . circular ( 10 ) ) ,
elevation: 20 ,
margin: const EdgeInsets . all ( 10 ) ,
child: Column (
children: [
AspectRatio (
aspectRatio: 16 / 9 ,
child: Image . network ( value[ "imageUrl" ] , fit: BoxFit . cover) ,
) ,
ListTile (
leading: ClipOval (
child: Image . network (
value[ "imageUrl" ] ,
fit: BoxFit . cover,
height: 40 ,
width: 40 ,
) ,
) ,
title: Text ( value[ "title" ] ) ,
subtitle: Text ( value[ "author" ] ) ,
)
] ,
) ,
) ;
} ,
) . toList ( ) ,
) ;
}
}
import 'package:flutter/material.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const LayoutDemo ( ) ,
) ,
) ;
}
}
class LayoutDemo extends StatelessWidget {
const LayoutDemo ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return ListView (
children: [
Row (
mainAxisAlignment: MainAxisAlignment . spaceAround,
children: [
ElevatedButton (
onPressed: ( ) {
print ( "ElevatedButton" ) ;
} ,
child: const Text ( "普通按钮" ) ) ,
TextButton ( onPressed: ( ) { } , child: const Text ( "文本按钮" ) ) ,
OutlinedButton ( onPressed: ( ) { } , child: const Text ( "边框按钮" ) ) ,
IconButton ( onPressed: ( ) { } , icon: const Icon ( Icons . thumb_up) )
] ,
) ,
const SizedBox (
height: 20 ,
) ,
Row ( mainAxisAlignment: MainAxisAlignment . spaceAround, children: [
ElevatedButton . icon (
onPressed: ( ) { } ,
icon: const Icon ( Icons . send) ,
label: const Text ( "发送" ) ) ,
TextButton . icon (
onPressed: ( ) { } ,
icon: const Icon ( Icons . info) ,
label: const Text ( "消息" ) ) ,
OutlinedButton . icon (
onPressed: null ,
icon: const Icon ( Icons . add) ,
label: const Text ( "增加" ) )
] ) ,
const SizedBox (
height: 20 ,
) ,
Row ( mainAxisAlignment: MainAxisAlignment . spaceAround, children: [
ElevatedButton (
style: ButtonStyle (
backgroundColor: MaterialStateProperty . all ( Colors . red) ,
foregroundColor:
MaterialStateProperty . all ( Colors . white)
) ,
onPressed: ( ) {
print ( "ElevatedButton" ) ;
} ,
child: const Text ( "普通按钮" ) ) ,
] ) ,
const SizedBox (
height: 20 ,
) ,
Row (
mainAxisAlignment: MainAxisAlignment . spaceAround,
children: [
SizedBox (
height: 60 ,
width: 140 ,
child: ElevatedButton (
onPressed: ( ) { } ,
child: const Text ( "大按钮" ) ,
) ,
) ,
SizedBox (
height: 40 ,
width: 100 ,
child: ElevatedButton . icon (
onPressed: ( ) { } ,
icon: const Icon ( Icons . search) ,
label: const Text ( "搜索" ) ,
) ,
)
] ,
) ,
const SizedBox (
height: 20 ,
) ,
Row (
children: [
Expanded (
flex: 1 ,
child: Container (
margin: const EdgeInsets . all ( 20 ) ,
height: 50 ,
child: ElevatedButton (
onPressed: ( ) { } ,
style: ButtonStyle (
backgroundColor: MaterialStateProperty . all (
const Color . fromARGB ( 220 , 245 , 71 , 71 ) ) ,
foregroundColor:
MaterialStateProperty . all ( Colors . white) ) ,
child: const Text ( "登录" ) ,
) ,
) )
] ,
) ,
const SizedBox (
height: 20 ,
) ,
Row (
mainAxisAlignment: MainAxisAlignment . spaceAround,
children: [
ElevatedButton (
style: ButtonStyle (
shape: MaterialStateProperty . all (
RoundedRectangleBorder (
borderRadius: BorderRadius . circular ( 12 ) ) ) ) ,
onPressed: ( ) { } ,
child: const Text ( "圆角" ) ) ,
SizedBox (
height: 80 ,
width: 80 ,
child: ElevatedButton (
style: ButtonStyle (
shape: MaterialStateProperty . all (
const CircleBorder (
side:
BorderSide ( width: 2 , color: Colors . yellow) ) ) ) ,
onPressed: ( ) { } ,
child: const Text ( "圆形" ) ) ,
) ,
] ,
) ,
const SizedBox ( height: 20 ) ,
Row (
mainAxisAlignment: MainAxisAlignment . center,
children: [
OutlinedButton (
style: ButtonStyle ( side: MaterialStateProperty . all (
const BorderSide ( width: 1 , color: Colors . red) ) ) ,
onPressed: ( ) { } ,
child: const Text ( "带边框的按钮" ) )
] ,
)
] ,
) ;
}
}
Wrap 组件 import 'package:flutter/material.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const LayoutDemo ( ) ,
) ,
) ;
}
}
class LayoutDemo extends StatelessWidget {
const LayoutDemo ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return Padding (
padding: const EdgeInsets . all ( 10 ) ,
child: Wrap (
alignment: WrapAlignment . spaceAround,
spacing: 10 ,
runSpacing: 10 ,
children: [
Button ( "第 1 集" , onPressed: ( ) { } ) ,
Button ( "第2集" , onPressed: ( ) { } ) ,
Button ( "第3集" , onPressed: ( ) { } ) ,
Button ( "第4集" , onPressed: ( ) { } ) ,
Button ( "第5集" , onPressed: ( ) { } ) ,
Button ( "第6集 (完结)" , onPressed: ( ) { } ) ,
Button ( "第7集" , onPressed: ( ) { } ) ,
Button ( "第8集" , onPressed: ( ) { } ) ,
Button ( "第9集" , onPressed: ( ) { } ) ,
Button ( "第10集" , onPressed: ( ) { } ) ,
Button ( "第11集" , onPressed: ( ) { } ) ,
Button ( "第12集" , onPressed: ( ) { } ) ,
Button ( "第13集" , onPressed: ( ) { } ) ,
Button ( "第14集" , onPressed: ( ) { } ) ,
Button ( "第15集" , onPressed: ( ) { } ) ,
Button ( "第16集" , onPressed: ( ) { } ) ,
Button ( "第17集" , onPressed: ( ) { } ) ,
Button ( "第18集" , onPressed: ( ) { } ) ,
] ,
) ,
) ;
}
}
class Button extends StatelessWidget {
String text;
void Function ( ) ? onPressed;
Button ( this . text, { Key ? key, required this . onPressed} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return ElevatedButton (
style: ButtonStyle (
backgroundColor: MaterialStateProperty . all (
const Color . fromARGB ( 241 , 223 , 219 , 219 ) ) ,
foregroundColor: MaterialStateProperty . all ( Colors . black45) ) ,
onPressed: onPressed,
child: Text ( text) ,
) ;
}
}
import 'package:flutter/material.dart' ;
void main ( ) {
runApp ( const MyApp ( ) ) ;
}
class MyApp extends StatelessWidget {
const MyApp ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return MaterialApp (
title: 'Flutter Demo' ,
theme: ThemeData (
primarySwatch: Colors . blue,
) ,
home: Scaffold (
appBar: AppBar ( title: const Text ( "Flutter App" ) ) ,
body: const LayoutDemo ( ) ,
) ,
) ;
}
}
class LayoutDemo extends StatelessWidget {
const LayoutDemo ( { Key ? key} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return ListView (
padding: const EdgeInsets . all ( 10 ) ,
children: [
Row (
children: [ Text ( "热搜" , style: Theme . of ( context) . textTheme. titleLarge) ] ,
) ,
const Divider ( ) ,
Wrap (
spacing: 10 ,
runSpacing: 10 ,
children: [
Button ( "女装" , onPressed: ( ) { } ) ,
Button ( "笔记本" , onPressed: ( ) { } ) ,
Button ( "玩具" , onPressed: ( ) { } ) ,
Button ( "文学" , onPressed: ( ) { } ) ,
Button ( "女装" , onPressed: ( ) { } ) ,
Button ( "时尚" , onPressed: ( ) { } ) ,
Button ( "男装" , onPressed: ( ) { } ) ,
Button ( "xxxx" , onPressed: ( ) { } ) ,
Button ( "手机" , onPressed: ( ) { } )
] ,
) ,
const SizedBox ( height: 10 ) ,
Row (
children: [
Text ( "历史记录" , style: Theme . of ( context) . textTheme. titleLarge)
] ,
) ,
const Divider ( ) ,
Column (
children: const [
ListTile ( title: Text ( "女装" ) ) ,
Divider ( ) ,
ListTile ( title: Text ( "手机" ) ) ,
Divider ( ) ,
ListTile ( title: Text ( "电脑" ) ) ,
Divider ( ) ,
] ,
) ,
const SizedBox ( height: 40 ) ,
Padding (
padding: const EdgeInsets . all ( 40 ) ,
child: OutlinedButton . icon (
style: ButtonStyle (
foregroundColor: MaterialStateProperty . all ( Colors . black45)
) ,
onPressed: ( ) { } ,
icon: const Icon ( Icons . delete) ,
label: const Text ( "清空历史记录" ) ) ,
)
] ,
) ;
}
}
class Button extends StatelessWidget {
String text;
void Function ( ) ? onPressed;
Button ( this . text, { Key ? key, required this . onPressed} ) : super ( key: key) ;
@override
Widget build ( BuildContext context) {
return ElevatedButton (
style: ButtonStyle (
backgroundColor: MaterialStateProperty . all (
const Color . fromARGB ( 241 , 223 , 219 , 219 ) ) ,
foregroundColor: MaterialStateProperty . all ( Colors . black45) ) ,
onPressed: onPressed,
child: Text ( text) ,
) ;
}
}
参考资料