Flutter - tabbar實(shí)現(xiàn),去掉水波紋效果

demo 地址: https://github.com/iotjin/jh_flutter_demo

代碼

import 'package:flutter/material.dart';
import 'package:jh_flutter_demo/one/one_page.dart';
import 'package:jh_flutter_demo/Two/two_page.dart';
import 'package:jh_flutter_demo/Three/three_page.dart';
import './four/four_page.dart';
import './JhTools/jhImageTool.dart';

class BaseTabBar extends StatefulWidget {
  BaseTabBar({Key key}) : super(key: key);

  _BaseTabBarState createState() => _BaseTabBarState();
}

class _BaseTabBarState extends State<BaseTabBar> {

  int _currentIndex=0;
  List <Widget>_pageList=[
    OnePage(),
    TwoPage(),
    ThreePage(),
    FourPage()
  ];
  static double _iconWH = 25.0;
  static double _fontSize = 10.0;
  List<BottomNavigationBarItem> bottomTabs = [

    BottomNavigationBarItem(
      title: Text("微信"),
      icon: Jh_loadAssetImage('tab/nav_tab_1',width: _iconWH),
      activeIcon: Jh_loadAssetImage('tab/nav_tab_1_on',width: _iconWH),
    ),
    BottomNavigationBarItem(
      title: Text("通訊錄"),
      icon: Jh_loadAssetImage('tab/nav_tab_2',width: _iconWH),
      activeIcon: Jh_loadAssetImage('tab/nav_tab_2_on',width: _iconWH),
    ),
    BottomNavigationBarItem(
      title: Text("朋友圈"),
      icon: Jh_loadAssetImage('tab/nav_tab_3',width: _iconWH),
      activeIcon: Jh_loadAssetImage('tab/nav_tab_3_on',width: _iconWH),
    ),
    BottomNavigationBarItem(
      title: Text("我的"),
      icon: Jh_loadAssetImage('tab/nav_tab_4',width: _iconWH),
      activeIcon: Jh_loadAssetImage('tab/nav_tab_4_on',width: _iconWH),
    ),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
//      backgroundColor: Colors.white,
      body: IndexedStack(
        index: _currentIndex,
        children: _pageList,
      ),
      bottomNavigationBar:
        Theme(
          data: ThemeData(
          highlightColor: Color.fromRGBO(0, 0, 0, 0),
          splashColor: Color.fromRGBO(0, 0, 0, 0),
          ),
          child:
          BottomNavigationBar(
//        unselectedItemColor:Colors.red,  //未選中顏色
//        selectedItemColor:Colors.yellow,  //選中顏色
            fixedColor: Color(0xFF3BB815),  //選中的顏色
            unselectedFontSize:_fontSize,
            selectedFontSize:_fontSize,
            type:BottomNavigationBarType.fixed,   //配置底部BaseTabBar可以有多個(gè)按鈕
            items: bottomTabs,
            currentIndex: this._currentIndex,   //配置對應(yīng)的索引值選中
            onTap: (int index){
              setState(() {  //改變狀態(tài)
                this._currentIndex=index;
              });
            },
          ),

        )


//      BottomNavigationBar(
////        unselectedItemColor:Colors.red,  //未選中顏色
////        selectedItemColor:Colors.yellow,  //選中顏色
//        fixedColor: Color(0xFF3BB815),  //選中的顏色
//        unselectedFontSize:_fontSize,
//        selectedFontSize:_fontSize,
//        type:BottomNavigationBarType.fixed,   //配置底部BaseTabBar可以有多個(gè)按鈕
//        items: bottomTabs,
//        currentIndex: this._currentIndex,   //配置對應(yīng)的索引值選中
//        onTap: (int index){
//          setState(() {  //改變狀態(tài)
//            this._currentIndex=index;
//          });
//        },
//      ),


    );
  }
}


/*-----------------------------------------------------------------------------*/
/*
BottomNavigationBar({
    Key key,
    @required this.items,  //必須有的item
    this.onTap,  //點(diǎn)擊事件
    this.currentIndex = 0,  //當(dāng)前選中
    this.elevation = 8.0,  //高度
    BottomNavigationBarType type,  //排列方式
    Color fixedColor,    //'Either selectedItemColor or fixedColor can be specified, but not both'
    this.backgroundColor,  //背景
    this.iconSize = 24.0,  //icon大小
    Color selectedItemColor,  //選中顏色
    this.unselectedItemColor,  //未選中顏色
    this.selectedIconTheme = const IconThemeData(),
    this.unselectedIconTheme = const IconThemeData(),
    this.selectedFontSize = 14.0,  //選中文字大小
    this.unselectedFontSize = 12.0,  //未選中文字大小
    this.selectedLabelStyle,
    this.unselectedLabelStyle,
    this.showSelectedLabels = true, //是否顯示選中的Item的文字
    bool showUnselectedLabels,  //是否顯示未選中的Item的問題
  })

 */
demo 地址: https://github.com/iotjin/jh_flutter_demo
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容