美文网首页
Flutter 自定义TabBar

Flutter 自定义TabBar

作者: DavidATM | 来源:发表于2019-06-19 18:16 被阅读0次

    import 'package:flutter/material.dart';

    import 'package:study_flutter/baseClass/BaseClass.dart';

    import 'package:study_flutter/pages/HomeWidget.dart';

    import 'package:study_flutter/pages/ForumWidget.dart';

    import 'package:study_flutter/pages/MineWidget.dart';

    class BaseTabBarextends StatefulWidget {

    @override

      _BaseTabBarStatecreateState() =>_BaseTabBarState();

    }

    class _BaseTabBarStateextends State {

    intselectedIndex =0;

      ListdataList;

      @override

      Widgetbuild(BuildContext context) {

    dataList = [

    {

    "title" :"主页",

            "norImage" :"images/index_icon1.png",

            "selImage" :"images/index_icon1_selected.png",

            "page" :HomeWidget(),

          },

          {

    "title" :"论坛",

            "norImage" :"images/index_icon2.png",

            "selImage" :"images/index_icon2_selected.png",

            "page" :ForumWidget(),

          },

          {

    "title" :"我的",

            "norImage" :"images/index_icon3.png",

            "selImage" :"images/index_icon3_selected.png",

            "page" :MineWidget(),

          }

    ];

        List items =List();

        for(int i =0; i

    var dic =dataList[i];

          var item =BottomNavigationBarItem(

    icon:Image.asset((selectedIndex == i) ? dic["selImage"] : dic["norImage"]),

            title:Text(dic["title"]),

          );

          items.add(item);

        }

    return Scaffold(

    body:dataList[selectedIndex]["page"],

            bottomNavigationBar:BottomNavigationBar(

    items: items,

              currentIndex:selectedIndex,

              selectedItemColor: BaseClass.kMainColor,

              onTap: clickItem,

            ),

          );

      }

    void clickItem(int index) {

    setState(() {

    selectedIndex = index;

        });

      }

    }

    相关文章

      网友评论

          本文标题:Flutter 自定义TabBar

          本文链接:https://www.haomeiwen.com/subject/ydclqctx.html