Dart語言常用的基本數(shù)據(jù)類型:Number,String,Boolean,List,Map
Number(int double)
實(shí)現(xiàn)頂部標(biāo)簽欄代碼
TabBarSample.dart
import 'package:flutter/material.dart';
class TabBarSampleextends StatelessWidget{
@override
? Widgetbuild(BuildContext context) {
return new MaterialApp(
home:new DefaultTabController(length: items.length,
? ? ? ? child:new Scaffold(
appBar:new AppBar(
title:const Text('TabBar選項(xiàng)卡示例'),
? ? ? ? ? ? bottom:new TabBar(isScrollable:true,
? ? ? ? ? ? ? tabs: items.map((ItemView item) {
return new Tab(
text: item.title,
? ? ? ? ? ? ? ? ? icon:new Icon(item.icon),
? ? ? ? ? ? ? ? );
? ? ? ? ? ? ? }).toList(),
? ? ? ? ? ? ),
? ? ? ? ? ),
? ? ? ? ? body:new TabBarView(children: items.map((ItemView item) {
return new Padding(padding:const EdgeInsets.all(16.0),
? ? ? ? ? ? ? child:new SelectedView(item: item),
? ? ? ? ? ? );
? ? ? ? ? }).toList(),
? ? ? ? ? ),
? ? ? ? ),
? ? ? ),
? ? );
? }
}
class ItemView{
const ItemView({this.title,this.icon});//構(gòu)造方法
? final Stringtitle;//標(biāo)題
? final IconDataicon;//圖標(biāo)
}
const List items =const[
const ItemView(title:'自駕', icon: Icons.directions_car),
? const ItemView(title:'自行車', icon: Icons.directions_bike),
? const ItemView(title:'輪船', icon: Icons.directions_boat),
? const ItemView(title:'公交', icon: Icons.directions_bus),
];
class SelectedViewextends StatelessWidget{
const SelectedView({Key key, this.item }):super(key:key);
? final ItemViewitem;
? Widgetbuild(BuildContext context){
final TextStyle textStyle=Theme.of(context).textTheme.display1;
? ? return new Card(
color: Colors.white,
? ? ? child:new Center(
child:new Column(
mainAxisSize: MainAxisSize.min,
? ? ? ? ? crossAxisAlignment: CrossAxisAlignment.center,
? ? ? ? ? children: [
new Icon(item.icon,size:128.0,color: textStyle.color),
? ? ? ? ? ? new Text(item.title,style: textStyle),
? ? ? ? ? ],
? ? ? ? ),
? ? ? ),
? ? );
? }
}