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

services_screen.dart 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. import 'package:flutter/material.dart';
  2. import '../../navigation/bottom_nav_bar.dart';
  3. class ServicesScreen extends StatelessWidget {
  4. const ServicesScreen({super.key});
  5. @override
  6. Widget build(BuildContext context) {
  7. return Scaffold(
  8. appBar: AppBar(
  9. title: const Text('服务'),
  10. ),
  11. body: SingleChildScrollView(
  12. padding: const EdgeInsets.all(20),
  13. child: Column(
  14. crossAxisAlignment: CrossAxisAlignment.start,
  15. children: [
  16. // 服务分类
  17. const Text(
  18. '服务分类',
  19. style: TextStyle(
  20. fontSize: 18,
  21. fontWeight: FontWeight.bold,
  22. ),
  23. ),
  24. const SizedBox(height: 16),
  25. GridView.count(
  26. crossAxisCount: 4,
  27. shrinkWrap: true,
  28. physics: const NeverScrollableScrollPhysics(),
  29. childAspectRatio: 1.0,
  30. children: [
  31. _buildServiceCategory(
  32. icon: Icons.cloud,
  33. title: '云服务',
  34. color: Colors.blue,
  35. ),
  36. _buildServiceCategory(
  37. icon: Icons.storage,
  38. title: '存储',
  39. color: Colors.green,
  40. ),
  41. _buildServiceCategory(
  42. icon: Icons.security,
  43. title: '安全',
  44. color: Colors.orange,
  45. ),
  46. _buildServiceCategory(
  47. icon: Icons.analytics,
  48. title: '分析',
  49. color: Colors.purple,
  50. ),
  51. _buildServiceCategory(
  52. icon: Icons.code,
  53. title: '开发',
  54. color: Colors.red,
  55. ),
  56. _buildServiceCategory(
  57. icon: Icons.dns,
  58. title: '数据库',
  59. color: Colors.teal,
  60. ),
  61. _buildServiceCategory(
  62. icon: Icons.api,
  63. title: 'API',
  64. color: Colors.pink,
  65. ),
  66. _buildServiceCategory(
  67. icon: Icons.more_horiz,
  68. title: '更多',
  69. color: Colors.grey,
  70. ),
  71. ],
  72. ),
  73. const SizedBox(height: 30),
  74. // 热门服务
  75. const Text(
  76. '热门服务',
  77. style: TextStyle(
  78. fontSize: 18,
  79. fontWeight: FontWeight.bold,
  80. ),
  81. ),
  82. const SizedBox(height: 16),
  83. ListView.builder(
  84. shrinkWrap: true,
  85. physics: const NeverScrollableScrollPhysics(),
  86. itemCount: 5,
  87. itemBuilder: (context, index) {
  88. return _buildHotServiceItem(index);
  89. },
  90. ),
  91. const SizedBox(height: 30),
  92. // 推荐服务
  93. const Text(
  94. '推荐服务',
  95. style: TextStyle(
  96. fontSize: 18,
  97. fontWeight: FontWeight.bold,
  98. ),
  99. ),
  100. const SizedBox(height: 16),
  101. Card(
  102. elevation: 3,
  103. shape: RoundedRectangleBorder(
  104. borderRadius: BorderRadius.circular(12),
  105. ),
  106. child: Padding(
  107. padding: const EdgeInsets.all(16),
  108. child: Column(
  109. children: [
  110. Row(
  111. children: [
  112. Container(
  113. width: 50,
  114. height: 50,
  115. decoration: BoxDecoration(
  116. color: Colors.blue[100],
  117. borderRadius: BorderRadius.circular(25),
  118. ),
  119. child: const Icon(
  120. Icons.star,
  121. color: Colors.blue,
  122. ),
  123. ),
  124. const SizedBox(width: 16),
  125. Expanded(
  126. child: Column(
  127. crossAxisAlignment: CrossAxisAlignment.start,
  128. children: const [
  129. Text(
  130. 'VIP专属服务',
  131. style: TextStyle(
  132. fontSize: 16,
  133. fontWeight: FontWeight.bold,
  134. ),
  135. ),
  136. SizedBox(height: 4),
  137. Text(
  138. '尊享VIP特权,获得更好的服务体验',
  139. style: TextStyle(
  140. fontSize: 14,
  141. color: Colors.grey,
  142. ),
  143. ),
  144. ],
  145. ),
  146. ),
  147. ],
  148. ),
  149. const SizedBox(height: 16),
  150. Row(
  151. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  152. children: [
  153. TextButton(
  154. onPressed: () {},
  155. child: const Text('了解更多'),
  156. ),
  157. ElevatedButton(
  158. onPressed: () {},
  159. style: ElevatedButton.styleFrom(
  160. shape: RoundedRectangleBorder(
  161. borderRadius: BorderRadius.circular(20),
  162. ),
  163. ),
  164. child: const Text('立即开通'),
  165. ),
  166. ],
  167. ),
  168. ],
  169. ),
  170. ),
  171. ),
  172. ],
  173. ),
  174. ),
  175. bottomNavigationBar: const BottomNavBar(initialIndex: 2),
  176. );
  177. }
  178. Widget _buildServiceCategory({
  179. required IconData icon,
  180. required String title,
  181. required Color color,
  182. }) {
  183. return Column(
  184. children: [
  185. Container(
  186. width: 60,
  187. height: 60,
  188. decoration: BoxDecoration(
  189. color: Color.lerp(Colors.white, Colors.transparent, 0.9)!, // 0.3表示30%透明
  190. borderRadius: BorderRadius.circular(30),
  191. ),
  192. child: Icon(
  193. icon,
  194. color: color,
  195. size: 30,
  196. ),
  197. ),
  198. const SizedBox(height: 8),
  199. Text(
  200. title,
  201. style: const TextStyle(
  202. fontSize: 12,
  203. fontWeight: FontWeight.w500,
  204. ),
  205. textAlign: TextAlign.center,
  206. ),
  207. ],
  208. );
  209. }
  210. Widget _buildHotServiceItem(int index) {
  211. final services = [
  212. {'title': '云服务器', 'desc': '弹性计算,按需付费'},
  213. {'title': '对象存储', 'desc': '安全可靠的文件存储'},
  214. {'title': 'CDN加速', 'desc': '全球内容分发网络'},
  215. {'title': '数据库服务', 'desc': '高性能数据库解决方案'},
  216. {'title': 'API网关', 'desc': '统一API管理和调度'},
  217. ];
  218. return Card(
  219. margin: const EdgeInsets.only(bottom: 12),
  220. shape: RoundedRectangleBorder(
  221. borderRadius: BorderRadius.circular(10),
  222. ),
  223. child: ListTile(
  224. leading: Container(
  225. width: 40,
  226. height: 40,
  227. decoration: BoxDecoration(
  228. color: Color.lerp(
  229. Colors.primaries[index % Colors.primaries.length],
  230. Colors.transparent,
  231. 0.9, // 90% 透明 = 10% 不透明度
  232. )!,
  233. borderRadius: BorderRadius.circular(20),
  234. ),
  235. child: Icon(
  236. Icons.cloud_circle,
  237. color: Colors.primaries[index % Colors.primaries.length],
  238. ),
  239. ),
  240. title: Text(
  241. services[index]['title']!,
  242. style: const TextStyle(
  243. fontWeight: FontWeight.bold,
  244. ),
  245. ),
  246. subtitle: Text(services[index]['desc']!),
  247. trailing: const Icon(Icons.chevron_right),
  248. onTap: () {},
  249. ),
  250. );
  251. }
  252. }