flutter10個常用的元件
//基礎格式。Text元件
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Text Widgetdddddd',
home: Scaffold(
body: Center(
child: Text(
'Heldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgesteldlo Widgest',
textAlign: TextAlign.center,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 25.0, color: Color.fromARGB(255, 255, 127, 127)),
),
),
));
}
}
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Text Widgetdddddd',
home: Scaffold(
body: Center(
child: Container(
child: new Image.network(
"https://blogimages.jspang.com/blogtouxiang1.jpg",
fit: BoxFit.contain,
repeat: ImageRepeat.repeat,
),
width: 300.0,
height: 200.0,
color: Colors.blue,
),
),
));
}
}
列表元件
import 'package:flutter/material.dart';
void main() =>
runApp(MyApp(items: new List<String>.generate(100, (i) => "Item $i")));
class MyApp extends StatelessWidget {
final List<String> items;
MyApp({Key key, @required this.items}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'ListView widget',
home: Scaffold(
body: new ListView.builder(
itemCount: 100,
itemBuilder: (context, index) {
return new ListTile(
title: new Text('${items[index]}'),
);
})),
);
}
}
網格元件
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'ListView widget',
home: Scaffold(
appBar: new AppBar(title: new Text('網格元件')),
body: new Container(
child: new GridView(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
childAspectRatio: 1,
),
children: <Widget>[
new Image.network(
"https://blogimages.jspang.com/blogtouxiang1.jpg"),
new Image.network(
"https://blogimages.jspang.com/blogtouxiang1.jpg"),
new Image.network(
"https://blogimages.jspang.com/blogtouxiang1.jpg"),
new Image.network(
"https://blogimages.jspang.com/blogtouxiang1.jpg"),
new Image.network(
"https://blogimages.jspang.com/blogtouxiang1.jpg"),
new Image.network(
"https://blogimages.jspang.com/blogtouxiang1.jpg"),
new Image.network(
"https://blogimages.jspang.com/blogtouxiang1.jpg"),
new Image.network(
"https://blogimages.jspang.com/blogtouxiang1.jpg"),
new Image.network(
"https://blogimages.jspang.com/blogtouxiang1.jpg"),
],
)),
),
);
}
}
佈局:5種
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'ListView widget',
home: Scaffold(
appBar: new AppBar(title: new Text('Row佈局')),
body: new Row(
children: <Widget>[
new RaisedButton(
onPressed: () {},
color: Colors.blue,
child: new Text('Blue'),
),
Expanded(
child: new RaisedButton(
onPressed: () {},
color: Colors.orange,
child: new Text('Blue'),
)),
new RaisedButton(
onPressed: () {},
color: Colors.blue,
child: new Text('Blue'),
)
],
)),
);
}
}
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'ListView widget',
home: Scaffold(
appBar: new AppBar(title: new Text('Colum佈局')),
body: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Center(child: Text('I am JSPang')),
Expanded(child: Text('my website is jspang.com')),
Center(child: Text('I love coding'))
],
)),
);
}
}
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
var stack = new Stack(
alignment: const FractionalOffset(0.5, 0.8),
children: <Widget>[
new CircleAvatar(
backgroundImage: new NetworkImage(
'https://blogimages.jspang.com/blogtouxiang1.jpg'),
radius: 100.0,
),
new Container(
decoration: new BoxDecoration(
color: Colors.lightBlue,
),
padding: EdgeInsets.all(5.0),
child: new Text('JSPang 技術胖'),
),
new Positioned(
top: 10.0,
left: 10.0,
child: new Text('JSPang.com'),
),
new Positioned(
bottom: 10.0,
right: 10.0,
child: new Text('技術胖'),
)
],
);
return MaterialApp(
title: 'ListView widget',
home: Scaffold(
appBar: new AppBar(
title: new Text('垂直方向佈局'),
),
body: Center(child: stack),
),
);
}
}
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
var card = new Card(
child: Column(
children: <Widget>[
ListTile(
title: new Text(
'吉林省吉林市昌邑區',
style: TextStyle(fontWeight: FontWeight.w500),
),
subtitle: new Text('技術胖:1513938888'),
leading: new Icon(
Icons.account_box,
color: Colors.lightBlue,
),
),
new Divider(),
ListTile(
title: new Text(
'北京市海淀區中國科技大學',
style: TextStyle(fontWeight: FontWeight.w500),
),
subtitle: new Text('勝巨集宇:1513938888'),
leading: new Icon(
Icons.account_box,
color: Colors.lightBlue,
),
),
new Divider(),
ListTile(
title: new Text(
'河南省濮陽市百姓辦公樓',
style: TextStyle(fontWeight: FontWeight.w500),
),
subtitle: new Text('JSPang:1513938888'),
leading: new Icon(
Icons.account_box,
color: Colors.lightBlue,
),
),
new Divider(),
],
),
);
return MaterialApp(
title: 'ListView widget',
home: Scaffold(
appBar: new AppBar(
title: new Text('卡片佈局'),
),
body: Center(child: card),
),
);
}
}
相關文章
- 深度解析11個最常用的遊戲控制元件遊戲控制元件
- Form開發中元件控制的幾個常用方法ORM元件
- 做ColdFusion 常用的元件元件
- COLA常用元件元件
- html的常用控制元件HTML控制元件
- nodejs常用元件NodeJS元件
- 常用SWT元件(六)元件
- flutter的進階之路之常用元件Flutter元件
- .NET平臺常用的開發元件元件
- vue常用元件通訊Vue元件
- iView常用元件清空技巧View元件
- react元件常用網站React元件網站
- 【微信小程式】常用元件及自定義元件微信小程式元件
- Flutter常用控制元件-ImageFlutter控制元件
- XAML常用控制元件2控制元件
- 物件導向例項--常用元件物件元件
- 常用控制元件類集合控制元件
- MAC常用的127個常用軟體Mac
- §2.1 最常用的控制元件------文字框(TextView)控制元件TextView
- iOS元件化常用的幾種構建模式iOS元件化模式
- android之 控制元件常用的屬性Android控制元件
- 遊戲互動的基礎!詳細解讀遊戲中最常用的11個控制元件遊戲控制元件
- bootstrap框架基礎和常用元件boot框架元件
- SpringCloud-常用元件介紹SpringGCCloud元件
- html5常用控制元件HTML控制元件
- Flutter新手入門常用元件總結,讓你瞭解更多的Flutter元件?Flutter元件
- GCD常用的幾個方法GC
- 一個常用的佈局
- DBA 常用的10個SQLSQL
- 使用wepy開發微信小程式01——常用的元件微信小程式元件
- 7款Android開發者常用的Android UI元件AndroidUI元件
- vue3 常用的幾種元件通訊方式Vue元件
- QT常用控制元件(三)——自定義控制元件封裝QT控制元件封裝
- 常用元件 / 導航欄及圖示元件
- ANDROID 控制元件常用屬性Android控制元件
- C#常用控制元件縮寫C#控制元件
- 常用Email元件傳送函式 (轉)AI元件函式
- git的幾個常用基本操作Git