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

news_screen.dart 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import 'package:flutter/material.dart';
  2. import '../../navigation/bottom_nav_bar.dart';
  3. import '../../widgets/common/app_search_bar.dart';
  4. class NewsScreen extends StatelessWidget {
  5. const NewsScreen({super.key});
  6. @override
  7. Widget build(BuildContext context) {
  8. return Scaffold(
  9. appBar: AppBar(
  10. title: const Text('推荐'),
  11. ),
  12. body: SingleChildScrollView(
  13. padding: const EdgeInsets.all(20),
  14. child: Column(
  15. crossAxisAlignment: CrossAxisAlignment.start,
  16. children: [
  17. // 使用 StatefulWidget 搜索框
  18. SearchBarCustom(
  19. hintText: '搜索...',
  20. onSearch: (query) {
  21. // 处理搜索逻辑
  22. // print('搜索: $query');
  23. },
  24. onChanged: (query) {
  25. // 实时搜索
  26. // print('输入变化: $query');
  27. },
  28. onClear: () {
  29. // print('清除搜索');
  30. },
  31. ),
  32. const SizedBox(height: 30),
  33. // 推荐列表
  34. ListView.builder(
  35. // padding: const EdgeInsets.all(16),
  36. shrinkWrap: true,
  37. physics: const NeverScrollableScrollPhysics(),
  38. itemCount: 10,
  39. itemBuilder: (context, index) {
  40. return _buildNewsCard(index);
  41. },
  42. ),
  43. ],
  44. ),
  45. ),
  46. bottomNavigationBar: const BottomNavBar(initialIndex: 1),
  47. );
  48. }
  49. Widget _buildNewsCard(int index) {
  50. final titles = [
  51. 'Flutter 3.0 新特性详解',
  52. 'Dart 语言最新更新',
  53. '移动开发趋势分析',
  54. '前端框架对比',
  55. '用户体验设计原则',
  56. '后端架构最佳实践',
  57. '数据库性能优化',
  58. '云原生技术解析',
  59. '人工智能在移动端的应用',
  60. '跨平台开发方案比较',
  61. ];
  62. final subtitles = [
  63. '深入了解Flutter最新版本的重要更新和改进',
  64. 'Dart语言的最新特性和优化方向',
  65. '2024年移动开发的重要趋势和技术方向',
  66. '主流前端框架的优缺点对比分析',
  67. '提升应用用户体验的关键设计原则',
  68. '构建高性能后端服务的最佳实践',
  69. '数据库查询优化和性能调优技巧',
  70. '云原生技术在微服务中的应用',
  71. 'AI技术在移动应用中的创新应用',
  72. '各种跨平台开发方案的对比和选择',
  73. ];
  74. final times = [
  75. '2小时前',
  76. '5小时前',
  77. '昨天',
  78. '2天前',
  79. '3天前',
  80. '1周前',
  81. '1周前',
  82. '2周前',
  83. '2周前',
  84. '1个月前',
  85. ];
  86. return Card(
  87. margin: const EdgeInsets.only(bottom: 16),
  88. shape: RoundedRectangleBorder(
  89. borderRadius: BorderRadius.circular(12),
  90. ),
  91. child: InkWell(
  92. onTap: () {},
  93. borderRadius: BorderRadius.circular(12),
  94. child: Padding(
  95. padding: const EdgeInsets.all(16),
  96. child: Column(
  97. crossAxisAlignment: CrossAxisAlignment.start,
  98. children: [
  99. Row(
  100. children: [
  101. Container(
  102. width: 60,
  103. height: 60,
  104. decoration: BoxDecoration(
  105. color: Colors.primaries[index % Colors.primaries.length],
  106. borderRadius: BorderRadius.circular(8),
  107. ),
  108. child: Center(
  109. child: Text(
  110. '新闻',
  111. style: TextStyle(
  112. color: Colors.white,
  113. fontWeight: FontWeight.bold,
  114. ),
  115. ),
  116. ),
  117. ),
  118. const SizedBox(width: 16),
  119. Expanded(
  120. child: Column(
  121. crossAxisAlignment: CrossAxisAlignment.start,
  122. children: [
  123. Text(
  124. titles[index],
  125. style: const TextStyle(
  126. fontSize: 16,
  127. fontWeight: FontWeight.bold,
  128. ),
  129. maxLines: 2,
  130. overflow: TextOverflow.ellipsis,
  131. ),
  132. const SizedBox(height: 4),
  133. Text(
  134. subtitles[index],
  135. style: TextStyle(
  136. fontSize: 14,
  137. color: Colors.grey[600],
  138. ),
  139. maxLines: 2,
  140. overflow: TextOverflow.ellipsis,
  141. ),
  142. ],
  143. ),
  144. ),
  145. ],
  146. ),
  147. const SizedBox(height: 12),
  148. Row(
  149. children: [
  150. Icon(
  151. Icons.schedule,
  152. size: 14,
  153. color: Colors.grey[500],
  154. ),
  155. const SizedBox(width: 4),
  156. Text(
  157. times[index],
  158. style: TextStyle(
  159. fontSize: 12,
  160. color: Colors.grey[500],
  161. ),
  162. ),
  163. const Spacer(),
  164. IconButton(
  165. icon: Icon(
  166. Icons.bookmark_border,
  167. color: Colors.grey[500],
  168. ),
  169. onPressed: () {},
  170. iconSize: 20,
  171. ),
  172. IconButton(
  173. icon: Icon(
  174. Icons.share,
  175. color: Colors.grey[500],
  176. ),
  177. onPressed: () {},
  178. iconSize: 20,
  179. ),
  180. ],
  181. ),
  182. ],
  183. ),
  184. ),
  185. ),
  186. );
  187. }
  188. }