欧美free性护士vide0shd,老熟女,一区二区三区,久久久久夜夜夜精品国产,久久久久久综合网天天,欧美成人护士h版

首頁綜合 正文
目錄

柚子快報(bào)激活碼778899分享:Flutter之TabBar篇

柚子快報(bào)激活碼778899分享:Flutter之TabBar篇

http://yzkb.51969.com/

總結(jié)了一下項(xiàng)目中用到的幾種TabBar,針對不同的樣式,有采用系統(tǒng)提供的,也有三方插件提供的,也有自定義的,效果如下(后續(xù)如果遇到新的樣式,會不間斷地記錄更新,避免重復(fù)造輪子…)

用到的三方插件:

buttons_tabbar: ^1.3.8 flutter_easyloading: ^3.0.5

1、先看第一種系統(tǒng)的

代碼如下:

class CustomTabBar extends StatelessWidget {

final TabController tabController;

final List tabs;

final TextStyle labelStyle;

final Color labelColor;

final Color unselectedLabelColor;

final TextStyle unselectedLabelStyle;

final Color indicatorColor;

final double indicatorWeight;

const CustomTabBar({

super.key,

required this.tabController,

required this.tabs,

this.labelStyle = const TextStyle(

fontSize: 16.0,

fontWeight: FontWeight.w700,

),

this.labelColor = Colors.blue,

this.unselectedLabelColor = Colors.red,

this.unselectedLabelStyle = const TextStyle(

fontSize: 16.0,

fontWeight: FontWeight.w400,

),

this.indicatorColor = Colors.blue,

this.indicatorWeight = 5.0,

});

@override

Widget build(BuildContext context) {

return TabBar(

controller: tabController,

tabs: tabs.map((e) => Tab(text: e)).toList(),

isScrollable: true,

labelPadding: const EdgeInsets.symmetric(horizontal: 16.0),

labelStyle: labelStyle,

labelColor: labelColor,

unselectedLabelColor: unselectedLabelColor,

unselectedLabelStyle: unselectedLabelStyle,

indicatorWeight: indicatorWeight,

indicator: DotTabIndicator(

color: indicatorColor,

radius: 4,

),

onTap: (value) {},

dividerColor: Colors.transparent, //去除tabBar下面的那根線的顏色

);

}

}

class DotTabIndicator extends Decoration {

final Color color;

final double radius;

const DotTabIndicator({required this.color, required this.radius});

@override

BoxPainter createBoxPainter([VoidCallback? onChanged]) {

return _DotTabIndicatorPainter(this, onChanged!);

}

}

class _DotTabIndicatorPainter extends BoxPainter {

final DotTabIndicator decoration;

_DotTabIndicatorPainter(this.decoration, VoidCallback onChanged)

: super(onChanged);

@override

void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {

final Rect rect = offset & configuration.size!;

final Paint paint = Paint();

paint.color = decoration.color;

paint.style = PaintingStyle.fill;

final Offset circleOffset =

Offset(rect.center.dx, rect.bottomCenter.dy - decoration.radius);

canvas.drawCircle(circleOffset, decoration.radius, paint);

}

}

使用方法:

late final TabController _tabController;

final List _tabs = [

"能源洞察",

"用戶故事",

"智匯回答",

];

final List _tabViews = [

Container(color: Colors.red),

Container(color: Colors.yellow),

Container(color: Colors.orange),

];

@override

void initState() {

super.initState();

_tabController = TabController(

initialIndex: 1,

length: _tabs.length,

vsync: this,

);

}

@override

void dispose() {

_tabController.dispose();

super.dispose();

}

Container(

height: 200,

child: Column(

children: [

CustomTabBar(

tabController: _tabController,

indicatorWeight: 1,

tabs: _tabs,

),

const SizedBox(height: 10.0),

Expanded(

child: TabBarView(

controller: _tabController,

children: _tabViews,

),

),

],

),

),

第二種采用的三方插件buttons_tabbar: ^1.3.8

代碼如下:

late final TabController _tabController;

final List _tabs = [

"能源洞察",

"用戶故事",

"智匯回答",

];

final List _tabViews = [

Container(color: Colors.red),

Container(color: Colors.yellow),

Container(color: Colors.orange),

];

@override

void initState() {

super.initState();

_tabController = TabController(

initialIndex: 0,

length: _tabs.length,

vsync: this,

);

}

@override

void dispose() {

_tabController.dispose();

super.dispose();

}

SizedBox(

height: 200,

child: Column(

children: [

SizedBox(

height: 32.0,

child: ButtonsTabBar(

tabs: _tabs.map((e) => Tab(text: e)).toList(),

controller: _tabController,

backgroundColor: Colors.blue,

unselectedBackgroundColor: Colors.red,

labelStyle: const TextStyle(color: Colors.white),

unselectedLabelStyle: const TextStyle(color: Colors.black),

buttonMargin: const EdgeInsets.only(right: 35),

contentPadding:

const EdgeInsets.symmetric(horizontal: 15.0),

radius: 18,

),

),

const SizedBox(height: 10.0),

Expanded(

child: TabBarView(

controller: _tabController,

children: _tabViews,

),

),

],

),

),

第三種自定義

代碼如下:

class ButtonContainer extends StatelessWidget {

final int containerIndex;

final ValueChanged onContainerSelected;

final bool isSelected;

final List data;

final Color backgroundColor;

final Color unBackgroundColor;

final TextStyle labelStyle;

final TextStyle unLabelStyle;

const ButtonContainer({

super.key,

required this.containerIndex,

required this.onContainerSelected,

required this.isSelected,

required this.data,

this.backgroundColor = Colors.grey,

this.unBackgroundColor = Colors.red,

this.labelStyle = const TextStyle(

color: Colors.black,

fontSize: 16,

),

this.unLabelStyle = const TextStyle(

color: Colors.white,

fontSize: 16,

),

});

@override

Widget build(BuildContext context) {

return GestureDetector(

onTap: () {

onContainerSelected(containerIndex);

},

child: Container(

padding: const EdgeInsets.all(8.0),

margin: const EdgeInsets.all(10),

decoration: BoxDecoration(

color: isSelected ? backgroundColor : unBackgroundColor,

borderRadius: BorderRadius.circular(8.0),

),

child: Text(

data[containerIndex],

style: isSelected ? labelStyle : unLabelStyle,

),

),

);

}

}

使用方法:

int selectedContainerIndex = 4; //默認(rèn)選中第幾個

final List dataList = [

"能源",

"用戶故事",

"智回答",

"能洞察",

"用戶故事",

"智匯答",

];

Wrap(

children: List.generate(dataList.length, (index) {

return ButtonContainer(

containerIndex: index,

onContainerSelected: (index) {

setState(() {

// 更新選中狀態(tài)

selectedContainerIndex = index;

});

EasyLoading.showToast("Click---${dataList[index]}");

},

isSelected: index == selectedContainerIndex,

data: dataList,

);

}),

),

代碼已經(jīng)都貼出來了,大方向已經(jīng)指出標(biāo)明,至于根據(jù)項(xiàng)目需求更改其中的細(xì)枝末節(jié)就需要自行動手了,有不懂的可以在下方留言,看到會及時回復(fù)?

柚子快報(bào)激活碼778899分享:Flutter之TabBar篇

http://yzkb.51969.com/

精彩鏈接

評論可見,查看隱藏內(nèi)容

本文內(nèi)容根據(jù)網(wǎng)絡(luò)資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點(diǎn)和立場。

轉(zhuǎn)載請注明,如有侵權(quán),聯(lián)系刪除。

本文鏈接:http://gantiao.com.cn/post/19014724.html

發(fā)布評論

您暫未設(shè)置收款碼

請?jiān)谥黝}配置——文章設(shè)置里上傳

掃描二維碼手機(jī)訪問

文章目錄