feat:增加登录模块

This commit is contained in:
2025-07-06 22:59:35 +08:00
parent ab00d6726f
commit 570a141133
3 changed files with 310 additions and 33 deletions

View File

@@ -1,6 +1,8 @@
import 'package:flutter/material.dart';
import 'package:food_hub_app/profile.dart';
import 'package:food_hub_app/record.dart';
import 'package:food_hub_app/views/login.dart';
import 'package:food_hub_app/views/recordForm.dart';
void main() {
runApp(const MyApp());
@@ -15,10 +17,10 @@ class MyApp extends StatelessWidget {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(fontFamily: 'CustomFont', primaryColor: Colors.green),
home: MainPage(),
home: LoginPage(),
routes: {
'/home': (context) => MainPage(),
'/new': (context) => NewPage(),
'/recordForm': (context) => RecordFormPage(),
},
);
}
@@ -28,10 +30,10 @@ class MainPage extends StatefulWidget {
const MainPage({super.key});
@override
State<StatefulWidget> createState() => _mainPage();
State<StatefulWidget> createState() => _MainPage();
}
class _mainPage extends State<MainPage> {
class _MainPage extends State<MainPage> {
int _currentIndex = 0;
final List<Widget> _tabPages = const [RecordPage(), ProfilePage()];
@@ -67,17 +69,7 @@ class _mainPage extends State<MainPage> {
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),
),
_currentIndex == _tabPages.length - 1 ? null : addItemButton(context),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,
iconSize: 25,
@@ -99,23 +91,16 @@ class _mainPage extends State<MainPage> {
}
}
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('返回'),
),
],
),
),
);
Widget addItemButton(BuildContext context) {
void onAddItemClick(BuildContext context) {
Navigator.pushNamed(context, '/recordForm');
}
return FloatingActionButton(
mini: true,
onPressed: () => onAddItemClick(context),
backgroundColor: Colors.green,
shape: const CircleBorder(),
child: Icon(Icons.add, color: Colors.white),
);
}