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

home_screen.dart 10KB

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