You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.8 KiB

11 months ago
import 'package:flutter/material.dart';
import 'package:music_player_miao/view/rank_view.dart';
import 'package:music_player_miao/view/user/user_view.dart';
import '../home_view.dart';
import '../release_view.dart';
class MainTabView extends StatefulWidget {
const MainTabView({super.key});
@override
State<MainTabView> createState() => _MainTabViewState();
}
class _MainTabViewState extends State<MainTabView> with SingleTickerProviderStateMixin {
11 months ago
TabController? controller;
int selectTab = 0;
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
@override
void initState() {
super.initState();
controller = TabController(length: 4, vsync: this);
controller?.addListener(() {
selectTab = controller?.index ?? 0;
setState(() {});
11 months ago
});
}
@override
void dispose() {
super.dispose();
controller?.dispose();
}
11 months ago
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
key: scaffoldKey,
body: TabBarView(
controller: controller,
children: const [
HomeView(),
RankView(),
ReleaseView(),
UserView()
],
),
bottomNavigationBar: Container(
11 months ago
color: Colors.white,
child: TabBar(
controller: controller,
indicatorColor: Colors.transparent,
labelColor: Colors.black,
labelStyle: const TextStyle(fontSize: 12), // 减小文字大小
11 months ago
unselectedLabelColor: const Color(0xffCDCDCD),
unselectedLabelStyle: const TextStyle(fontSize: 12), // 减小文字大小
11 months ago
tabs: [
Tab(
height: 60, // 明确指定高度
icon: Image.asset(
selectTab == 0 ? "assets/img/home_tab.png" : "assets/img/home_tab_un.png",
width: 32, // 减小图标大小
height: 32,
),
text: "首页",
11 months ago
),
Tab(
height: 60,
icon: Image.asset(
selectTab == 1 ? "assets/img/list_tab.png" : "assets/img/list_tab_un.png",
width: 32,
height: 32,
),
text: "排行榜",
11 months ago
),
Tab(
height: 60,
icon: Image.asset(
selectTab == 2 ? "assets/img/music_tab.png" : "assets/img/music_tab_un.png",
width: 32,
height: 32,
),
text: "发布",
11 months ago
),
Tab(
height: 60,
icon: Image.asset(
selectTab == 3 ? "assets/img/user_tab.png" : "assets/img/user_tab_un.png",
width: 32,
height: 32,
),
text: "我的",
11 months ago
),
],
),
),
);
}
}