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

home_screen.dart 9.7KB

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