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個最常用的遊戲控制元件遊戲控制元件
- html的常用控制元件HTML控制元件
- COLA常用元件元件
- flutter的進階之路之常用元件Flutter元件
- iView常用元件清空技巧View元件
- vue常用元件通訊Vue元件
- react元件常用網站React元件網站
- 【微信小程式】常用元件及自定義元件微信小程式元件
- Flutter常用控制元件-ImageFlutter控制元件
- XAML常用控制元件2控制元件
- SpringCloud-常用元件介紹SpringGCCloud元件
- html5常用控制元件HTML控制元件
- bootstrap框架基礎和常用元件boot框架元件
- Flutter新手入門常用元件總結,讓你瞭解更多的Flutter元件?Flutter元件
- ARM常用的22個概念!
- NodeJS 常用的 8 個工具NodeJS
- vue3 常用的幾種元件通訊方式Vue元件
- 遊戲互動的基礎!詳細解讀遊戲中最常用的11個控制元件遊戲控制元件
- QT常用控制元件(三)——自定義控制元件封裝QT控制元件封裝
- python 的幾個常用的函式Python函式
- 使用wepy開發微信小程式01——常用的元件微信小程式元件
- 十五個常用的 Laravel 集合(Collection)Laravel
- 五個常用的爬蟲包爬蟲
- git的幾個常用基本操作Git
- 常用的Linux,記住了幾個?Linux
- IBM HMC 10個常用的操作IBM
- 18個常用的JavaScript片段分享JavaScript
- 15個常用的Laravel 集合(Collection)Laravel
- Android常用控制元件-BannerView(無限輪播圖控制元件)Android控制元件View
- React Native常用三方元件庫大全React Native元件
- React 元件封裝 以及常用項記錄React元件封裝
- Harmony 應用開發常用元件介紹元件
- 介紹4個大神常用而你不常用的python函式Python函式
- 個人常用集
- 100 個最常用的 PHP 函式PHP函式
- 25個常用的Linux iptables規則Linux
- 我常用的4個備份工具
- Linux磁碟管理常用的三個命令!Linux