最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

flutter實現(xiàn)頭部tabTop滾動欄

 更新時間:2022年03月22日 17:04:48   作者:舜岳  
這篇文章主要為大家詳細(xì)介紹了flutter實現(xiàn)頭部tabTop滾動欄,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了flutter實現(xiàn)頭部tabTop滾動欄的具體代碼,供大家參考,具體內(nèi)容如下

效果圖如下:

main.dart代碼如下:

import 'package:flutter/material.dart';
//啟動函數(shù)
void main() => runApp(MyApp());

//自定義組件
class MyApp extends StatelessWidget {
? @override
? Widget build(BuildContext context) {
? ? //MaterialApp 是flutter的頁面根組件
? ? return MaterialApp(
? ? ? title: 'main根頁面',
? ? ? debugShowCheckedModeBanner: false, ?//清除debug
? ? ? //home表示頁面信息
? ? ? home: AppbarTop()
? ? );
? }
}

//頭部tabTop滾動欄效果組件
import 'package:flutter/material.dart';

class AppbarTop extends StatefulWidget {
? @override
? _AppbarTopState createState() => _AppbarTopState();
}

//混合SingleTickerProviderStateMixin類 同步屬性
class _AppbarTopState extends State<AppbarTop>
? ? with SingleTickerProviderStateMixin {
? //定義一個控制器
? TabController _tabController;

? @override
? void initState() {
? ? super.initState();
? ? //混入SingleTickerProviderStateMixin的this
? ? //實例化一個tab控制器 作用:
? ? _tabController = TabController(length: choices.length, vsync: this);
? }

? _nextPage(index) {
? ? int currentIndex = _tabController.index + index;
? ? if (currentIndex < -0) currentIndex = _tabController.length - 1;
? ? if (currentIndex >= _tabController.length) currentIndex = 0;
? ? //控制器移動到currentIndex處
? ? _tabController.animateTo(currentIndex);
? }

? @override
? Widget build(BuildContext context) {
? ? return Scaffold(
? ? ? appBar: AppBar(
? ? ? ? title: Text('頭部菜單欄'),
? ? ? ? centerTitle: true, //title居中顯示
? ? ? ? leading: IconButton(
? ? ? ? ? ? icon: Icon(Icons.arrow_back),
? ? ? ? ? ? onPressed: () {
? ? ? ? ? ? ? _nextPage(-1);
? ? ? ? ? ? }),
? ? ? ? iconTheme: IconThemeData(color: Colors.yellow), //頭部icon樣式顏色
? ? ? ? //右邊icon圖標(biāo) 可以多個
? ? ? ? actions: <Widget>[
? ? ? ? ? IconButton(
? ? ? ? ? ? ? icon: Icon(Icons.arrow_forward),
? ? ? ? ? ? ? onPressed: () {
? ? ? ? ? ? ? ? _nextPage(1);
? ? ? ? ? ? ? })
? ? ? ? ],
? ? ? ? actionsIconTheme: IconThemeData(color: Colors.white),
? ? ? ? //自定義導(dǎo)航欄
? ? ? ? bottom: PreferredSize(
? ? ? ? ? ? child: Theme(
? ? ? ? ? ? ? data: Theme.of(context).copyWith(accentColor: Colors.white),
? ? ? ? ? ? ? child: Container(
? ? ? ? ? ? ? ? height: 40,
? ? ? ? ? ? ? ? alignment: Alignment.center, //圓點居中
? ? ? ? ? ? ? ? //給自定義導(dǎo)航欄設(shè)置圓點控制器
? ? ? ? ? ? ? ? child: TabPageSelector(
? ? ? ? ? ? ? ? ? controller: _tabController,
? ? ? ? ? ? ? ? ),
? ? ? ? ? ? ? ),
? ? ? ? ? ? ),
? ? ? ? ? ? preferredSize: Size.fromHeight(48)),
? ? ? ),
? ? ? //主體內(nèi)容
? ? ? body: TabBarView(
? ? ? ? //主題內(nèi)容也跟隨控制器變化
? ? ? ? controller: _tabController,
? ? ? ? //將數(shù)據(jù)遍歷成n個子組件數(shù)組
? ? ? ? children: choices.map((item) {
? ? ? ? ? return Padding(
? ? ? ? ? ? padding: EdgeInsets.all(20),
? ? ? ? ? ? child: ChoiceCard(
? ? ? ? ? ? ? choice: item,
? ? ? ? ? ? ),
? ? ? ? ? );
? ? ? ? }).toList(),
? ? ? ),
? ? );
? }
}

//ChoiceCard將數(shù)據(jù)渲染到Card卡片組件上
class ChoiceCard extends StatelessWidget {
? final Choice choice;
? const ChoiceCard({Key key, this.choice}) : super(key: key);

? @override
? Widget build(BuildContext context) {
? ? //滾動時的卡片小部件
? ? return Card(
? ? ? color: Colors.blue,
? ? ? child: Column(
? ? ? ? mainAxisAlignment: MainAxisAlignment.center,
? ? ? ? children: <Widget>[
? ? ? ? ? Icon(choice.icon, size: 120, color: Colors.white,),
? ? ? ? ? Text(choice.title),
? ? ? ? ],
? ? ? )
? ? );
? }
}


//數(shù)據(jù)的類型
class Choice {
? const Choice({this.title, this.icon});
? final String title;
? final IconData icon;
}
//模擬的數(shù)據(jù)
const List<Choice> choices = const <Choice>[
? const Choice(title: 'CAR', icon: Icons.directions_car),
? const Choice(title: 'BICYCLE', icon: Icons.directions_bike),
? const Choice(title: 'BOAT', icon: Icons.directions_boat),
? const Choice(title: 'BUS', icon: Icons.directions_bus),
? const Choice(title: 'TRAIN', icon: Icons.directions_railway),
? const Choice(title: 'WALK', icon: Icons.directions_walk),
];

效果圖2:

代碼如下:

//頭部tabTop滾動欄效果組件
class AppBarBottom extends StatefulWidget {
? AppBarBottom({Key key}) : super(key: key);

? @override
? _AppBarBottomState createState() => _AppBarBottomState();
}

class _AppBarBottomState extends State<AppBarBottom> {
? _SelectView(icon, text, id) {
? ? return PopupMenuItem(
? ? ? ? child: Row(
? ? ? mainAxisAlignment: MainAxisAlignment.spaceAround,
? ? ? children: <Widget>[
? ? ? ? Icon(icon, color: Colors.blue),
? ? ? ? Text(
? ? ? ? ? text,
? ? ? ? ? style: TextStyle(color: Colors.black),
? ? ? ? )
? ? ? ],
? ? ));
? }

? @override
? Widget build(BuildContext context) {
? ? //tab使用這個組件
? ? return DefaultTabController(
? ? ? ? length: choices.length,
? ? ? ? child: Scaffold(
? ? ? ? ? appBar: AppBar(
? ? ? ? ? ? title: Text('AppBar與TabBar'),
? ? ? ? ? ? centerTitle: true,
? ? ? ? ? ? actions: <Widget>[
? ? ? ? ? ? ? PopupMenuButton(
? ? ? ? ? ? ? ? ? shape: BeveledRectangleBorder(
? ? ? ? ? ? ? ? ? ? ? borderRadius: BorderRadius.circular(10)),
? ? ? ? ? ? ? ? ? itemBuilder: (BuildContext context) {
? ? ? ? ? ? ? ? ? ? return [
? ? ? ? ? ? ? ? ? ? ? PopupMenuItem(
? ? ? ? ? ? ? ? ? ? ? ? ? child: _SelectView(Icons.message, '首頁', 'A')),
? ? ? ? ? ? ? ? ? ? ? PopupMenuItem(
? ? ? ? ? ? ? ? ? ? ? ? ? child: _SelectView(Icons.message, '商品', 'B')),
? ? ? ? ? ? ? ? ? ? ? PopupMenuItem(
? ? ? ? ? ? ? ? ? ? ? ? ? child: _SelectView(Icons.message, '消息', 'C')),
? ? ? ? ? ? ? ? ? ? ];
? ? ? ? ? ? ? ? ? })
? ? ? ? ? ? ],
? ? ? ? ? ? bottom: TabBar(
? ? ? ? ? ? ? isScrollable: true,
? ? ? ? ? ? ? indicatorSize: TabBarIndicatorSize.label,
? ? ? ? ? ? ? tabs: choices.map((item) {
? ? ? ? ? ? ? ? return Tab(
? ? ? ? ? ? ? ? ? text: item.title,
? ? ? ? ? ? ? ? ? icon: Icon(item.icon),
? ? ? ? ? ? ? ? );
? ? ? ? ? ? ? }).toList(),
? ? ? ? ? ? ),
? ? ? ? ? ),
? ? ? ? ? body: TabBarView(
? ? ? ? ? ? children: choices.map((item) {
? ? ? ? ? ? ? return Container(
? ? ? ? ? ? ? ? width: double.infinity,
? ? ? ? ? ? ? ? color: Colors.white70,
? ? ? ? ? ? ? ? child: Padding(
? ? ? ? ? ? ? ? ? padding: EdgeInsets.all(16),
? ? ? ? ? ? ? ? ? child: ChoiceCard(
? ? ? ? ? ? ? ? ? ? choice: item,
? ? ? ? ? ? ? ? ? ),
? ? ? ? ? ? ? ? ),
? ? ? ? ? ? ? );
? ? ? ? ? ? }).toList(),
? ? ? ? ? ),
? ? ? ? ));
? }
}

//ChoiceCard將數(shù)據(jù)渲染到Card卡片組件上
class ChoiceCard extends StatelessWidget {
? final Choice choice;
? const ChoiceCard({Key key, this.choice}) : super(key: key);

? @override
? Widget build(BuildContext context) {
? ? //滾動時的卡片小部件
? ? return Card(
? ? ? ? color: Colors.blue,
? ? ? ? child: Column(
? ? ? ? ? mainAxisAlignment: MainAxisAlignment.center,
? ? ? ? ? children: <Widget>[
? ? ? ? ? ? Icon(
? ? ? ? ? ? ? choice.icon,
? ? ? ? ? ? ? size: 120,
? ? ? ? ? ? ? color: Colors.white,
? ? ? ? ? ? ),
? ? ? ? ? ? Text(choice.title),
? ? ? ? ? ],
? ? ? ? ));
? }
}

//數(shù)據(jù)的類型
class Choice {
? const Choice({this.title, this.icon});
? final String title;
? final IconData icon;
}

//模擬的數(shù)據(jù)
const List<Choice> choices = const <Choice>[
? const Choice(title: 'CAR', icon: Icons.directions_car),
? const Choice(title: 'BICYCLE', icon: Icons.directions_bike),
? const Choice(title: 'BOAT', icon: Icons.directions_boat),
? const Choice(title: 'BUS', icon: Icons.directions_bus),
? const Choice(title: 'TRAIN', icon: Icons.directions_railway),
? const Choice(title: 'WALK', icon: Icons.directions_walk),
];

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解Android Material Design自定義動畫的編寫

    詳解Android Material Design自定義動畫的編寫

    這篇文章主要介紹了詳解Android Material Design自定義動畫的編寫,其中對Activity的過渡動畫進(jìn)行了重點講解,需要的朋友可以參考下
    2016-04-04
  • Android 新手入門體驗

    Android 新手入門體驗

    本篇文章小編為大家介紹,Android 新手入門體驗。需要的朋友參考下
    2013-04-04
  • Android自定義ViewGroup實現(xiàn)絢麗的仿支付寶咻一咻雷達(dá)脈沖效果

    Android自定義ViewGroup實現(xiàn)絢麗的仿支付寶咻一咻雷達(dá)脈沖效果

    這篇文章主要介紹了Android自定義ViewGroup實現(xiàn)絢麗的仿支付寶咻一咻雷達(dá)脈沖效果的相關(guān)資料,需要的朋友可以參考下
    2016-10-10
  • Android實現(xiàn)界面左右滑動切換功能

    Android實現(xiàn)界面左右滑動切換功能

    相信大家一定都使用過手機QQ和微信之類的軟件,當(dāng)我們使用時不難發(fā)現(xiàn)其界面的切換不僅可以通過點擊頁標(biāo)簽來實現(xiàn),還可以通過左右滑動來實現(xiàn)的,下面小編給大家介紹下如何實現(xiàn)這個功能
    2016-12-12
  • Android Studio添加第三方庫的注意事項

    Android Studio添加第三方庫的注意事項

    這篇文章給大家介紹的是Android Studio添加第三方庫遇到的一些坑,以及對應(yīng)的解決辦法,有需要的可以參考借鑒。
    2016-09-09
  • Android自定義Progress控件的方法

    Android自定義Progress控件的方法

    這篇文章主要為大家詳細(xì)介紹了Android自定義Progress控件的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • Android Lottie實現(xiàn)中秋月餅變明月動畫特效實例

    Android Lottie實現(xiàn)中秋月餅變明月動畫特效實例

    Lottie是Airbnb開源的一個支持 Android、iOS 以及 ReactNative,利用json文件的方式快速實現(xiàn)動畫效果的庫,下面這篇文章主要給大家介紹了關(guān)于Android Lottie實現(xiàn)中秋月餅變明月動畫特效的相關(guān)資料,需要的朋友可以參考下
    2021-09-09
  • android中SQLite使用及特點

    android中SQLite使用及特點

    SQLite是一個輕量級數(shù)據(jù)庫,它設(shè)計目標(biāo)是嵌入式的,而且占用資源非常低,本文重點給大家介紹android中SQLite使用及特點,感興趣的朋友跟隨小編一起看看吧
    2021-04-04
  • Android的VSYNC機制和UI刷新流程示例詳解

    Android的VSYNC機制和UI刷新流程示例詳解

    這篇文章主要為大家介紹了Android的VSYNC機制和UI刷新流程示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-12-12
  • Android高仿微信對話列表滑動刪除效果

    Android高仿微信對話列表滑動刪除效果

    這篇文章主要為大家詳細(xì)介紹了Android高仿微信對話列表滑動刪除效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-08-08

最新評論

乌鲁木齐市| 韩城市| 普定县| 渝中区| 湖南省| 黄山市| 封丘县| 水城县| 耒阳市| 绩溪县| 绥化市| 清河县| 黄大仙区| 蒙城县| 洪泽县| 青川县| 富顺县| 兰西县| 江川县| 肥东县| 陇南市| 万年县| 沙雅县| 湖口县| 太白县| 万安县| 资源县| 循化| 临高县| 温宿县| 新昌县| 山东省| 建始县| 綦江县| 贵州省| 红原县| 陇南市| 扎囊县| 二手房| 富蕴县| 花莲市|