| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- import 'package:flutter/material.dart';
- import 'package:provider/provider.dart';
- import '../../navigation/bottom_nav_bar.dart';
- import '../../providers/auth_provider.dart';
- import '../../widgets/common/app_button.dart';
-
- class HomeScreen extends StatelessWidget {
- const HomeScreen({super.key});
-
- @override
- Widget build(BuildContext context) {
- final authProvider = Provider.of<AuthProvider>(context);
-
- return Scaffold(
- appBar: AppBar(
- title: const Text('首页'),
- actions: [
- if (authProvider.isAuthenticated)
- IconButton(
- icon: const Icon(Icons.notifications_none),
- onPressed: () {},
- ),
- ],
- ),
- body: SingleChildScrollView(
- child: Padding(
- padding: const EdgeInsets.all(20),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- // 欢迎区域
- Card(
- elevation: 0,
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(16),
- ),
- color: Colors.blue[50],
- child: Padding(
- padding: const EdgeInsets.all(20),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Row(
- children: [
- CircleAvatar(
- radius: 30,
- backgroundColor: Colors.blue[100],
- child: Icon(
- Icons.person,
- size: 30,
- color: Colors.blue,
- ),
- ),
- const SizedBox(width: 16),
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- authProvider.isAuthenticated
- ? '您好,${authProvider.user?.fullName}'
- : '您好,游客',
- style: const TextStyle(
- fontSize: 18,
- fontWeight: FontWeight.bold,
- ),
- ),
- const SizedBox(height: 4),
- Text(
- authProvider.isAuthenticated
- ? '欢迎回来!'
- : '请登录以使用完整功能',
- style: TextStyle(
- fontSize: 14,
- color: Colors.grey[600],
- ),
- ),
- ],
- ),
- ),
- ],
- ),
- const SizedBox(height: 20),
- if (!authProvider.isAuthenticated)
- AppButton(
- text: '立即登录',
- onPressed: () {
- Navigator.of(context).pushNamed('/login');
- },
- backgroundColor: Colors.blue,
- height: 45,
- ),
- ],
- ),
- ),
- ),
- const SizedBox(height: 30),
-
- // 功能卡片
- const Text(
- '功能服务',
- style: TextStyle(
- fontSize: 18,
- fontWeight: FontWeight.bold,
- ),
- ),
- const SizedBox(height: 16),
- GridView.count(
- crossAxisCount: 3,
- shrinkWrap: true,
- physics: const NeverScrollableScrollPhysics(),
- childAspectRatio: 0.9,
- children: [
- _buildFeatureCard(
- icon: Icons.newspaper,
- title: '资讯',
- color: Colors.green,
- onTap: () {
- Navigator.of(context).pushNamed('/news');
- },
- ),
- _buildFeatureCard(
- icon: Icons.work,
- title: '服务',
- color: Colors.orange,
- onTap: () {
- Navigator.of(context).pushNamed('/services');
- },
- ),
- _buildFeatureCard(
- icon: Icons.person,
- title: '我的',
- color: Colors.purple,
- onTap: () {
- if (authProvider.isAuthenticated) {
- Navigator.of(context).pushNamed('/profile');
- } else {
- Navigator.of(context).pushNamed('/login');
- }
- },
- ),
- _buildFeatureCard(
- icon: Icons.settings,
- title: '设置',
- color: Colors.grey,
- onTap: () {},
- ),
- _buildFeatureCard(
- icon: Icons.help,
- title: '帮助',
- color: Colors.red,
- onTap: () {},
- ),
- _buildFeatureCard(
- icon: Icons.info,
- title: '关于',
- color: Colors.teal,
- onTap: () {},
- ),
- ],
- ),
- const SizedBox(height: 30),
-
- // 快速访问
- const Text(
- '快速访问',
- style: TextStyle(
- fontSize: 18,
- fontWeight: FontWeight.bold,
- ),
- ),
- const SizedBox(height: 16),
- Card(
- elevation: 2,
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(12),
- ),
- child: Column(
- children: [
- _buildQuickAccessItem(
- icon: Icons.history,
- title: '最近访问',
- subtitle: '查看您最近的操作记录',
- ),
- const Divider(height: 1),
- _buildQuickAccessItem(
- icon: Icons.star_border,
- title: '我的收藏',
- subtitle: '查看您收藏的内容',
- ),
- const Divider(height: 1),
- _buildQuickAccessItem(
- icon: Icons.download,
- title: '下载管理',
- subtitle: '管理您的下载文件',
- ),
- ],
- ),
- ),
- const SizedBox(height: 20),
-
- // 系统信息
- Card(
- elevation: 0,
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(12),
- side: BorderSide(color: Colors.grey[300]!),
- ),
- child: Padding(
- padding: const EdgeInsets.all(16),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- const Text(
- '系统信息',
- style: TextStyle(
- fontSize: 16,
- fontWeight: FontWeight.bold,
- ),
- ),
- const SizedBox(height: 12),
- Row(
- children: [
- Icon(Icons.check_circle, color: Colors.green, size: 16),
- const SizedBox(width: 8),
- const Expanded(
- child: Text('系统运行正常'),
- ),
- Text(
- 'v1.0.0',
- style: TextStyle(
- color: Colors.grey[600],
- fontSize: 12,
- ),
- ),
- ],
- ),
- ],
- ),
- ),
- ),
- ],
- ),
- ),
- ),
- bottomNavigationBar: const BottomNavBar(initialIndex: 0),
- );
- }
-
- Widget _buildFeatureCard({
- required IconData icon,
- required String title,
- required Color color,
- required VoidCallback onTap,
- }) {
- return InkWell(
- onTap: onTap,
- borderRadius: BorderRadius.circular(12),
- child: Card(
- elevation: 2,
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(12),
- ),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Container(
- width: 50,
- height: 50,
- decoration: BoxDecoration(
- color: Color.lerp(Colors.white, Colors.transparent, 0.9)!, // 0.3表示30%透明
- borderRadius: BorderRadius.circular(25),
- ),
- child: Icon(
- icon,
- color: color,
- size: 28,
- ),
- ),
- const SizedBox(height: 12),
- Text(
- title,
- style: const TextStyle(
- fontSize: 14,
- fontWeight: FontWeight.w500,
- ),
- ),
- ],
- ),
- ),
- );
- }
-
- Widget _buildQuickAccessItem({
- required IconData icon,
- required String title,
- required String subtitle,
- }) {
- return ListTile(
- leading: Icon(icon),
- title: Text(title),
- subtitle: Text(subtitle),
- trailing: const Icon(Icons.chevron_right),
- onTap: () {},
- );
- }
- }
|