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

services_screen.dart 8.9KB

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