Files
food_hub_app/lib/main.dart
2025-07-06 19:04:30 +08:00

122 lines
3.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:food_hub_app/profile.dart';
import 'package:food_hub_app/record.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(fontFamily: 'CustomFont', primaryColor: Colors.green),
home: MainPage(),
routes: {
'/home': (context) => MainPage(),
'/new': (context) => NewPage(),
},
);
}
}
class MainPage extends StatefulWidget {
const MainPage({super.key});
@override
State<StatefulWidget> createState() => _mainPage();
}
class _mainPage extends State<MainPage> {
int _currentIndex = 0;
final List<Widget> _tabPages = const [RecordPage(), ProfilePage()];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text('Food Hub'),
backgroundColor: Colors.white,
leading: IconButton(
icon: Icon(Icons.menu),
onPressed: () {
// 打开侧边栏或菜单
},
),
actions: [
IconButton(
icon: Icon(Icons.search),
onPressed: () {
// 搜索功能
},
),
IconButton(
icon: Icon(Icons.more_vert),
onPressed: () {
// 更多选项
},
),
],
),
backgroundColor: Color(0xFFF5F5F5),
body: _tabPages[_currentIndex],
floatingActionButton:
_currentIndex == _tabPages.length - 1
? null
: FloatingActionButton(
mini: true,
onPressed: () {
Navigator.pushNamed(context, '/new');
},
backgroundColor: Colors.green,
shape: const CircleBorder(),
child: Icon(Icons.add, color: Colors.white),
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,
iconSize: 25,
type: BottomNavigationBarType.fixed,
items: const [
BottomNavigationBarItem(icon: Icon(Icons.home), label: "记录"),
BottomNavigationBarItem(
icon: Icon(Icons.account_circle),
label: "我的",
),
],
onTap: (index) {
setState(() {
_currentIndex = index;
});
},
),
);
}
}
class NewPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('新页面')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('这是新页面'),
ElevatedButton(
onPressed: () => Navigator.pop(context),
child: Text('返回'),
),
],
),
),
);
}
}