主页添加底栏

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

3
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"cmake.ignoreCMakeListsMissing": true
}

View File

@@ -1,29 +1,2 @@
<<<<<<< HEAD # 第一次Flutter项目开发
# mydearest 这是第4次提交
=======
<<<<<<< HEAD
# Flutter_First_Project
=======
# mydearest
>>>>>>> f48a885 (第2次提交)
A new Flutter project.
## Getting Started
This project is a starting point for a Flutter application.
A few resources to get you started if this is your first Flutter project:
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
For help getting started with Flutter development, view the
[online documentation](https://docs.flutter.dev/), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
<<<<<<< HEAD
=======
>>>>>>> 4bb705a (第一次提交)
>>>>>>> f48a885 (第2次提交)

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 "package:flutter/material.dart";
import '../home/index.dart';
import '../myfriends/index.dart';
import '../profile/index.dart';
class MainPage extends StatefulWidget { class MainPage extends StatefulWidget {
const MainPage({super.key}); const MainPage({super.key});
@@ -8,14 +11,64 @@ class MainPage extends StatefulWidget {
} }
class _MainPageState extends State<MainPage> { 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( // 避开刘海屏等特殊屏幕区域
title: Text("Main Page"), body: SafeArea(child: IndexedStack(
), index: _currentIndex,
body: Center( children: _pages,
child: Text("This is the main page."), )), // 堆叠索引组件,根据当前索引显示对应的页面
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"),
);
}
}

View File

@@ -61,6 +61,9 @@ flutter:
# assets: # assets:
# - images/a_dot_burr.jpeg # - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg # - images/a_dot_ham.jpeg
assets:
- lib/assets/images/
- lib/assets/icons/
# An image asset can refer to one or more resolution-specific "variants", see # An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/to/resolution-aware-images # https://flutter.dev/to/resolution-aware-images

View File

@@ -8,12 +8,11 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:mydearest/main.dart';
void main() { void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async { testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame. // Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());
// Verify that our counter starts at 0. // Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget); expect(find.text('0'), findsOneWidget);