feat:增加底部标题栏
This commit is contained in:
@@ -20,3 +20,8 @@ final List<PageInfo> pages = [
|
||||
];
|
||||
|
||||
final List<Widget> pageWidgets = pages.map((item) => item.page).toList();
|
||||
|
||||
final List<BottomNavigationBarItem> bottomNavItems =
|
||||
pages.map((page) {
|
||||
return BottomNavigationBarItem(icon: Icon(page.icon), label: page.title);
|
||||
}).toList();
|
||||
|
||||
22
lib/layout/nav_bar.dart
Normal file
22
lib/layout/nav_bar.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'menu.dart';
|
||||
|
||||
Widget buildBottomNavigationBar({
|
||||
required BuildContext context,
|
||||
required int index,
|
||||
required Function(int) onTap,
|
||||
}) {
|
||||
return BottomNavigationBar(
|
||||
currentIndex: index,
|
||||
onTap: onTap,
|
||||
items: bottomNavItems,
|
||||
type: BottomNavigationBarType.fixed,
|
||||
selectedItemColor: Theme.of(context).colorScheme.primary,
|
||||
unselectedItemColor: Colors.grey,
|
||||
showSelectedLabels: true,
|
||||
showUnselectedLabels: true,
|
||||
backgroundColor: Colors.white,
|
||||
elevation: 8,
|
||||
);
|
||||
}
|
||||
@@ -1,11 +1,14 @@
|
||||
import 'package:blog_app/apis/blog.dart';
|
||||
import 'package:blog_app/layout/drawer.dart';
|
||||
import 'package:blog_app/layout/menu.dart';
|
||||
import 'package:blog_app/layout/nav_bar.dart';
|
||||
import 'package:blog_app/models/blog.dart';
|
||||
import 'package:blog_app/widget/search.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class HomePage extends StatefulWidget {
|
||||
const HomePage({super.key});
|
||||
|
||||
@override
|
||||
_HomePageState createState() => _HomePageState();
|
||||
}
|
||||
@@ -162,6 +165,20 @@ class _HomePageState extends State<HomePage> {
|
||||
return buildSearchResultList(context, _searchResults);
|
||||
}
|
||||
|
||||
void _onBottomNavTap(int index) {
|
||||
setState(() {
|
||||
_currentPageIndex = index;
|
||||
if (_isSearching) {
|
||||
_exitSearch();
|
||||
}
|
||||
});
|
||||
_pageController.animateToPage(
|
||||
index,
|
||||
duration: Duration(milliseconds: 300),
|
||||
curve: Curves.easeInOut,
|
||||
);
|
||||
}
|
||||
|
||||
void onTapDrawerItem(int index) {
|
||||
setState(() {
|
||||
_currentPageIndex = index;
|
||||
@@ -220,6 +237,11 @@ class _HomePageState extends State<HomePage> {
|
||||
),
|
||||
drawer: _buildDrawer(),
|
||||
body: Padding(padding: EdgeInsets.all(10), child: _buildPageView()),
|
||||
bottomNavigationBar: buildBottomNavigationBar(
|
||||
context: context,
|
||||
index: _currentPageIndex,
|
||||
onTap: _onBottomNavTap,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,27 +228,18 @@ Widget buildBlogListItem(BuildContext context, Blog blog, int index) {
|
||||
padding: EdgeInsets.all(10),
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 25,
|
||||
child: Text(
|
||||
index.toString(),
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w500,
|
||||
color: colors.primary,
|
||||
),
|
||||
Text(
|
||||
'$index.',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w500
|
||||
),
|
||||
),
|
||||
|
||||
// 发布时间
|
||||
SizedBox(
|
||||
width: 150,
|
||||
child: Text(
|
||||
blog.createTime,
|
||||
style: TextStyle(fontSize: 14, color: Colors.grey.shade600),
|
||||
),
|
||||
SizedBox(width: 10),
|
||||
Text(
|
||||
formatDateString(blog.createTime),
|
||||
style: TextStyle(fontSize: 14, color: Colors.grey.shade600),
|
||||
),
|
||||
|
||||
// 标题
|
||||
SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
blog.title,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'package:blog_app/models/blog.dart';
|
||||
import 'package:blog_app/pages/blog_detail_page.dart';
|
||||
import 'package:blog_app/widget/blog.dart';
|
||||
import 'package:blog_app/widget/common.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
Reference in New Issue
Block a user