主页添加底栏

This commit is contained in:
2026-03-10 23:39:51 +08:00
parent 5ba923838b
commit 52beb51a54
27 changed files with 118 additions and 36 deletions

BIN
lib/assets/add.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 B

BIN
lib/assets/add_circle.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 607 B

BIN
lib/assets/arrow_back.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 B

BIN
lib/assets/block.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 598 B

BIN
lib/assets/cancel.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 663 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 B

BIN
lib/assets/close.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B

BIN
lib/assets/delete.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

BIN
lib/assets/group.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 515 B

BIN
lib/assets/groups.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 415 B

BIN
lib/assets/home.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 327 B

BIN
lib/assets/menu.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 B

BIN
lib/assets/person.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 423 B

BIN
lib/assets/search.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 451 B

BIN
lib/assets/settings.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 701 B

BIN
lib/assets/star.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 566 B

BIN
lib/assets/thumb_up.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 395 B

17
lib/pages/home/index.dart Normal file
View File

@@ -0,0 +1,17 @@
import "package:flutter/material.dart";
class HomeView extends StatefulWidget {
const HomeView({super.key});
@override
State<HomeView> createState() => _HomeViewState();
}
class _HomeViewState extends State<HomeView> {
@override
Widget build(BuildContext context) {
return Center(
child: Text("Home View"),
);
}
}

View File

@@ -1,4 +1,7 @@
import "package:flutter/material.dart";
import '../home/index.dart';
import '../myfriends/index.dart';
import '../profile/index.dart';
class MainPage extends StatefulWidget {
const MainPage({super.key});
@@ -8,14 +11,64 @@ class MainPage extends StatefulWidget {
}
class _MainPageState extends State<MainPage> {
// 定义数据 根据数据进行渲染导航键
final List<Map<String, dynamic>> _navList = [
{
"icon": Icons.home_outlined,
"activeIcon": Icons.home,
"label": "Home",
},
{
"icon": Icons.face_outlined,
"activeIcon": Icons.face,
"label": "MyFriends",
},
{
"icon": Icons.person_outlined,
"activeIcon": Icons.person,
"label": "Profile",
},
];
// 根据数据渲染导航键
List<BottomNavigationBarItem> _buildNavItems() {
return List.generate(_navList.length, (int index) {
final navItem = _navList[index];
return BottomNavigationBarItem(
icon: Icon(navItem["icon"]),
activeIcon: Icon(navItem["activeIcon"]),
label: navItem["label"],
);
});
}
int _currentIndex = 0; // 当前选中的导航键索引
List<Widget> get _pages {
return [
const HomeView(),
const MyFriendsView(),
const ProfileView(),
]; // 对应导航键的页面列表
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Main Page"),
),
body: Center(
child: Text("This is the main page."),
// 避开刘海屏等特殊屏幕区域
body: SafeArea(child: IndexedStack(
index: _currentIndex,
children: _pages,
)), // 堆叠索引组件,根据当前索引显示对应的页面
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,
items: _buildNavItems(),
onTap: (int index) { // 点击导航键时更新当前索引
setState(() {
_currentIndex = index;
});
},
),
);
}

View File

@@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
class MyFriendsView extends StatefulWidget {
const MyFriendsView({super.key});
@override
State<MyFriendsView> createState() => _MyFriendsViewState();
}
class _MyFriendsViewState extends State<MyFriendsView> {
@override
Widget build(BuildContext context) {
return Center(
child: Text("MyFriends View"),
);
}
}

View File

@@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
class ProfileView extends StatefulWidget {
const ProfileView({super.key});
@override
State<ProfileView> createState() => _ProfileViewState();
}
class _ProfileViewState extends State<ProfileView> {
@override
Widget build(BuildContext context) {
return Center(
child: Text("Profile View"),
);
}
}