这是CaiYouHui前端,一个关于flutter的安卓app,前端使用flutter实现

home_screen.dart 9.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. import 'package:flutter/material.dart';
  2. import 'package:provider/provider.dart';
  3. import '../../navigation/bottom_nav_bar.dart';
  4. import '../../providers/auth_provider.dart';
  5. class HomeScreen extends StatelessWidget {
  6. const HomeScreen({super.key});
  7. @override
  8. Widget build(BuildContext context) {
  9. final authProvider = Provider.of<AuthProvider>(context);
  10. return Scaffold(
  11. appBar: AppBar(
  12. title: const Text('首页'),
  13. actions: [
  14. if (authProvider.isAuthenticated)
  15. IconButton(
  16. icon: const Icon(Icons.notifications_none),
  17. onPressed: () {},
  18. ),
  19. ],
  20. ),
  21. body: SingleChildScrollView(
  22. child: Padding(
  23. padding: const EdgeInsets.all(20),
  24. child: Column(
  25. crossAxisAlignment: CrossAxisAlignment.start,
  26. children: [
  27. // 欢迎区域
  28. Card(
  29. elevation: 0,
  30. shape: RoundedRectangleBorder(
  31. borderRadius: BorderRadius.circular(16),
  32. ),
  33. color: Colors.blue[50],
  34. child: Padding(
  35. padding: const EdgeInsets.all(20),
  36. child: Column(
  37. crossAxisAlignment: CrossAxisAlignment.start,
  38. children: [
  39. Row(
  40. children: [
  41. Expanded(
  42. child: Column(
  43. crossAxisAlignment: CrossAxisAlignment.start,
  44. children: [
  45. Text(
  46. authProvider.isAuthenticated
  47. ? '您好,${authProvider.user?.fullName}'
  48. : '您好,游客',
  49. style: const TextStyle(
  50. fontSize: 18,
  51. fontWeight: FontWeight.bold,
  52. ),
  53. ),
  54. const SizedBox(height: 4),
  55. Text(
  56. authProvider.isAuthenticated
  57. ? '这里会展示一些有趣的东西!'
  58. : '请登录以使用完整功能',
  59. style: TextStyle(
  60. fontSize: 14,
  61. color: Colors.grey[600],
  62. ),
  63. ),
  64. ],
  65. ),
  66. ),
  67. ],
  68. ),
  69. const SizedBox(height: 100),
  70. ],
  71. ),
  72. ),
  73. ),
  74. const SizedBox(height: 30),
  75. // 功能卡片
  76. const Text(
  77. '功能服务',
  78. style: TextStyle(
  79. fontSize: 18,
  80. fontWeight: FontWeight.bold,
  81. ),
  82. ),
  83. const SizedBox(height: 16),
  84. GridView.count(
  85. crossAxisCount: 3,
  86. shrinkWrap: true,
  87. physics: const NeverScrollableScrollPhysics(),
  88. childAspectRatio: 0.9,
  89. children: [
  90. _buildFeatureCard(
  91. icon: Icons.newspaper,
  92. title: '推荐',
  93. color: Colors.green,
  94. onTap: () {
  95. Navigator.of(context).pushNamed('/news');
  96. },
  97. ),
  98. _buildFeatureCard(
  99. icon: Icons.work,
  100. title: '服务',
  101. color: Colors.orange,
  102. onTap: () {
  103. Navigator.of(context).pushNamed('/services');
  104. },
  105. ),
  106. _buildFeatureCard(
  107. icon: Icons.person,
  108. title: '我的',
  109. color: Colors.purple,
  110. onTap: () {
  111. if (authProvider.isAuthenticated) {
  112. Navigator.of(context).pushNamed('/profile');
  113. } else {
  114. Navigator.of(context).pushNamed('/login');
  115. }
  116. },
  117. ),
  118. _buildFeatureCard(
  119. icon: Icons.settings,
  120. title: '设置',
  121. color: Colors.grey,
  122. onTap: () {},
  123. ),
  124. _buildFeatureCard(
  125. icon: Icons.help,
  126. title: '帮助',
  127. color: Colors.red,
  128. onTap: () {},
  129. ),
  130. _buildFeatureCard(
  131. icon: Icons.info,
  132. title: '关于',
  133. color: Colors.teal,
  134. onTap: () {},
  135. ),
  136. ],
  137. ),
  138. const SizedBox(height: 30),
  139. // 快速访问
  140. const Text(
  141. '快速访问',
  142. style: TextStyle(
  143. fontSize: 18,
  144. fontWeight: FontWeight.bold,
  145. ),
  146. ),
  147. const SizedBox(height: 16),
  148. Card(
  149. elevation: 2,
  150. shape: RoundedRectangleBorder(
  151. borderRadius: BorderRadius.circular(12),
  152. ),
  153. child: Column(
  154. children: [
  155. _buildQuickAccessItem(
  156. icon: Icons.history,
  157. title: '最近访问',
  158. subtitle: '查看您最近的操作记录',
  159. ),
  160. const Divider(height: 1),
  161. _buildQuickAccessItem(
  162. icon: Icons.star_border,
  163. title: '我的收藏',
  164. subtitle: '查看您收藏的内容',
  165. ),
  166. const Divider(height: 1),
  167. _buildQuickAccessItem(
  168. icon: Icons.download,
  169. title: '下载管理',
  170. subtitle: '管理您的下载文件',
  171. ),
  172. ],
  173. ),
  174. ),
  175. const SizedBox(height: 20),
  176. // 系统信息
  177. Card(
  178. elevation: 0,
  179. shape: RoundedRectangleBorder(
  180. borderRadius: BorderRadius.circular(12),
  181. side: BorderSide(color: Colors.grey[300]!),
  182. ),
  183. child: Padding(
  184. padding: const EdgeInsets.all(16),
  185. child: Column(
  186. crossAxisAlignment: CrossAxisAlignment.start,
  187. children: [
  188. const Text(
  189. '系统信息',
  190. style: TextStyle(
  191. fontSize: 16,
  192. fontWeight: FontWeight.bold,
  193. ),
  194. ),
  195. const SizedBox(height: 12),
  196. Row(
  197. children: [
  198. Icon(Icons.check_circle, color: Colors.green, size: 16),
  199. const SizedBox(width: 8),
  200. const Expanded(
  201. child: Text('系统运行正常'),
  202. ),
  203. Text(
  204. 'v1.0.0',
  205. style: TextStyle(
  206. color: Colors.grey[600],
  207. fontSize: 12,
  208. ),
  209. ),
  210. ],
  211. ),
  212. ],
  213. ),
  214. ),
  215. ),
  216. ],
  217. ),
  218. ),
  219. ),
  220. bottomNavigationBar: const BottomNavBar(initialIndex: 0),
  221. );
  222. }
  223. Widget _buildFeatureCard({
  224. required IconData icon,
  225. required String title,
  226. required Color color,
  227. required VoidCallback onTap,
  228. }) {
  229. return InkWell(
  230. onTap: onTap,
  231. borderRadius: BorderRadius.circular(12),
  232. child: Card(
  233. elevation: 2,
  234. shape: RoundedRectangleBorder(
  235. borderRadius: BorderRadius.circular(12),
  236. ),
  237. child: Column(
  238. mainAxisAlignment: MainAxisAlignment.center,
  239. children: [
  240. Container(
  241. width: 50,
  242. height: 50,
  243. decoration: BoxDecoration(
  244. color: Color.lerp(Colors.white, Colors.transparent, 0.9)!, // 0.3表示30%透明
  245. borderRadius: BorderRadius.circular(25),
  246. ),
  247. child: Icon(
  248. icon,
  249. color: color,
  250. size: 28,
  251. ),
  252. ),
  253. const SizedBox(height: 12),
  254. Text(
  255. title,
  256. style: const TextStyle(
  257. fontSize: 14,
  258. fontWeight: FontWeight.w500,
  259. ),
  260. ),
  261. ],
  262. ),
  263. ),
  264. );
  265. }
  266. Widget _buildQuickAccessItem({
  267. required IconData icon,
  268. required String title,
  269. required String subtitle,
  270. }) {
  271. return ListTile(
  272. leading: Icon(icon),
  273. title: Text(title),
  274. subtitle: Text(subtitle),
  275. trailing: const Icon(Icons.chevron_right),
  276. onTap: () {},
  277. );
  278. }
  279. }