亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

flutter實(shí)現(xiàn)頭部tabTop滾動(dòng)欄

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

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

效果圖如下:

main.dart代碼如下:

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

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

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

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

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

? @override
? void initState() {
? ? super.initState();
? ? //混入SingleTickerProviderStateMixin的this
? ? //實(shí)例化一個(gè)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;
? ? //控制器移動(dòng)到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) 可以多個(gè)
? ? ? ? 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, //圓點(diǎn)居中
? ? ? ? ? ? ? ? //給自定義導(dǎo)航欄設(shè)置圓點(diǎn)控制器
? ? ? ? ? ? ? ? child: TabPageSelector(
? ? ? ? ? ? ? ? ? controller: _tabController,
? ? ? ? ? ? ? ? ),
? ? ? ? ? ? ? ),
? ? ? ? ? ? ),
? ? ? ? ? ? preferredSize: Size.fromHeight(48)),
? ? ? ),
? ? ? //主體內(nèi)容
? ? ? body: TabBarView(
? ? ? ? //主題內(nèi)容也跟隨控制器變化
? ? ? ? controller: _tabController,
? ? ? ? //將數(shù)據(jù)遍歷成n個(gè)子組件數(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) {
? ? //滾動(dòng)時(shí)的卡片小部件
? ? 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ù)的類(lèi)型
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滾動(dòng)欄效果組件
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使用這個(gè)組件
? ? 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, '首頁(yè)', '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) {
? ? //滾動(dòng)時(shí)的卡片小部件
? ? 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ù)的類(lèi)型
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),
];

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

相關(guān)文章

  • Android圖片選擇器ImageEditContainer

    Android圖片選擇器ImageEditContainer

    這篇文章主要為大家詳細(xì)介紹了Android圖片選擇器ImageEditContainer的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • Android事件分發(fā)機(jī)制深入刨析原理及源碼

    Android事件分發(fā)機(jī)制深入刨析原理及源碼

    Android?的事件分發(fā)機(jī)制大體可以分為三部分:事件生產(chǎn)、事件分發(fā)?、事件消費(fèi)。事件的生產(chǎn)是由用戶(hù)點(diǎn)擊屏幕產(chǎn)生,我們這次著重分析事件的分發(fā)和消費(fèi),因?yàn)槭录职l(fā)和處理聯(lián)系的過(guò)于緊密,這篇文章將把事件的分發(fā)和消費(fèi)放在一起分析
    2023-04-04
  • Android控件系列之CheckBox使用介紹

    Android控件系列之CheckBox使用介紹

    CheckBox和Button一樣,也是一種古老的控件,它的優(yōu)點(diǎn)在于,不用用戶(hù)去填寫(xiě)具體的信息,只需輕輕點(diǎn)擊,缺點(diǎn)在于只有“是”和“否”兩種情況,但我們往往利用它的這個(gè)特性,來(lái)獲取用戶(hù)的一些信息
    2012-11-11
  • Android模仿Toast實(shí)現(xiàn)提示框效果

    Android模仿Toast實(shí)現(xiàn)提示框效果

    這篇文章主要為大家詳細(xì)介紹了Android模仿Toast實(shí)現(xiàn)提示框效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • android繪制觸點(diǎn)軌跡的代碼

    android繪制觸點(diǎn)軌跡的代碼

    這篇文章主要為大家詳細(xì)介紹了android繪制觸點(diǎn)軌跡的相關(guān)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-06-06
  • Android View實(shí)現(xiàn)圓形進(jìn)度條

    Android View實(shí)現(xiàn)圓形進(jìn)度條

    這篇文章主要為大家詳細(xì)介紹了Android View實(shí)現(xiàn)圓形進(jìn)度條,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • Android 退出多Activity的application的方式方法

    Android 退出多Activity的application的方式方法

    在開(kāi)發(fā)過(guò)程中,我們常常需要一個(gè)退出功能,來(lái)退出該應(yīng)用的所有Activity,本篇文章主要介紹了Android 退出多Activity的application的方式,有興趣的可以了解一下。
    2017-02-02
  • android 設(shè)置鬧鐘及通知示例

    android 設(shè)置鬧鐘及通知示例

    本篇文章主要介紹了android 設(shè)置鬧鐘及通知示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-02-02
  • android?WindowManager的簡(jiǎn)單使用實(shí)例詳解

    android?WindowManager的簡(jiǎn)單使用實(shí)例詳解

    這篇文章主要介紹了android?WindowManager的簡(jiǎn)單使用,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-08-08
  • 清楚詳解Android?進(jìn)程間圖傳遞圖形buffer原理

    清楚詳解Android?進(jìn)程間圖傳遞圖形buffer原理

    這篇文章主要為大家清楚的詳解了Android?進(jìn)程間圖傳遞圖形buffer原理,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-02-02

最新評(píng)論