129 lines
3.6 KiB
Dart
129 lines
3.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_localizations/flutter_localizations.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';
|
|
import 'package:form_builder_validators/form_builder_validators.dart';
|
|
|
|
void main() {
|
|
FormBuilderLocalizations.delegate.load(const Locale('zh', 'CN'));
|
|
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),
|
|
supportedLocales: const [
|
|
Locale('en', 'US'), // 英语
|
|
Locale('zh', 'CN'), // 中文
|
|
],
|
|
// 本地化代理配置
|
|
localizationsDelegates: const [
|
|
GlobalMaterialLocalizations.delegate,
|
|
GlobalWidgetsLocalizations.delegate,
|
|
GlobalCupertinoLocalizations.delegate,
|
|
],
|
|
// 根据系统语言自动选择Locale
|
|
localeResolutionCallback: (locale, supportedLocales) {
|
|
for (var supportedLocale in supportedLocales) {
|
|
if (supportedLocale.languageCode == locale?.languageCode) {
|
|
return supportedLocale;
|
|
}
|
|
}
|
|
return supportedLocales.first;
|
|
},
|
|
home: LoginPage(),
|
|
routes: {
|
|
'/home': (context) => MainPage(),
|
|
'/recordForm': (context) => RecordFormPage(),
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
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 : addItemButton(context),
|
|
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;
|
|
});
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
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),
|
|
);
|
|
}
|