新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
使用Flutter怎么實現(xiàn)一個底部菜單欄功能
使用Flutter怎么實現(xiàn)一個底部菜單欄功能?針對這個問題,這篇文章詳細(xì)介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

創(chuàng)新互聯(lián)主要從事成都做網(wǎng)站、成都網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)山陽,十年網(wǎng)站建設(shè)經(jīng)驗,價格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):028-86922220
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget{
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: MyHomePage(),
),
);
}
}
class MyHomePage extends StatefulWidget{
MyHomePage({Key key}) : super(key:key);
@override
_MyHomePageState createState() => _MyHomePageState();
@override
Widget build(BuildContext context) {
// TODO: implement build
return null;
}
}
class _MyHomePageState extends State
{
int _selectedIndex = 1;//當(dāng)前選中項的索引
final _widgetOptions = [
Text('Index 0: 微信'),
Text('Index 1: 通訊錄'),
Text('Index 2: 發(fā)現(xiàn)'),
Text('Index 3:我')
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('仿微信'),
),
body: Center(
child: _widgetOptions.elementAt(_selectedIndex),//居中顯示某個文本
),
//底部導(dǎo)航按鈕,包含圖標(biāo)及文本
bottomNavigationBar: BottomNavigationBar(
items: [
BottomNavigationBarItem(icon: Icon(Icons.chat),backgroundColor:Colors.green,title: Text('微信')),//設(shè)置背景顏色和icon的描述
BottomNavigationBarItem(icon: Icon(Icons.contacts),backgroundColor:Colors.green,title: Text('通訊錄')),
BottomNavigationBarItem(icon: Icon(Icons.account_circle),backgroundColor:Colors.green,title: Text('發(fā)現(xiàn)')),
BottomNavigationBarItem(icon: Icon(Icons.memory),backgroundColor:Colors.green,title: Text('我')),
],
// backgroundColor: Colors.green,
currentIndex: _selectedIndex,//當(dāng)前選中項的索引
fixedColor: Colors.deepPurple,//選項中項的顏色
onTap:_onItemTapped,//選擇按下處理
),
);
}
//選擇按下處理
void _onItemTapped(int index)
{
setState(() {
_selectedIndex = index;
});
}
} 關(guān)于使用Flutter怎么實現(xiàn)一個底部菜單欄功能問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識。
分享標(biāo)題:使用Flutter怎么實現(xiàn)一個底部菜單欄功能
網(wǎng)站路徑:http://www.dlmjj.cn/article/igjohh.html


咨詢
建站咨詢
