view.dart 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. import 'package:electronic_assistant/base/base_page.dart';
  2. import 'package:electronic_assistant/resource/assets.gen.dart';
  3. import 'package:electronic_assistant/resource/string.gen.dart';
  4. import 'package:electronic_assistant/utils/expand.dart';
  5. import 'package:flutter/cupertino.dart';
  6. import 'package:flutter/src/widgets/framework.dart';
  7. import 'package:flutter_screenutil/flutter_screenutil.dart';
  8. import 'package:get/get.dart';
  9. import 'package:get/get_state_manager/src/rx_flutter/rx_obx_widget.dart';
  10. import 'package:photo_manager/photo_manager.dart';
  11. import 'package:pull_to_refresh/pull_to_refresh.dart';
  12. import '../../resource/colors.gen.dart';
  13. import '../../utils/common_style.dart';
  14. import 'controller.dart';
  15. class AudioPickerPage extends BasePage<AudioPickerController> {
  16. const AudioPickerPage({super.key});
  17. @override
  18. Color backgroundColor() {
  19. return ColorName.transparent;
  20. }
  21. @override
  22. Widget buildBody(BuildContext context) {
  23. return Container(
  24. decoration: BoxDecoration(
  25. color: "#F6F5F8".toColor(),
  26. borderRadius: const BorderRadius.only(
  27. topLeft: Radius.circular(16),
  28. topRight: Radius.circular(16),
  29. ),
  30. ),
  31. height: ScreenUtil().screenHeight - 70.h,
  32. child: Column(
  33. children: [
  34. _buildTitleView(),
  35. Expanded(child: Obx(() {
  36. return SmartRefresher(
  37. enablePullUp: true,
  38. enablePullDown: false,
  39. onLoading: controller.onLoadMoreData,
  40. controller: controller.refreshController,
  41. child: ListView.builder(
  42. itemBuilder: _buildItem,
  43. itemCount: controller.audioList.length,
  44. ),
  45. );
  46. })),
  47. _buildImportBtnView()
  48. ],
  49. ),
  50. );
  51. }
  52. Widget _buildTitleView() {
  53. return Container(
  54. padding: EdgeInsets.symmetric(vertical: 18.h),
  55. child: IntrinsicHeight(
  56. child: Stack(
  57. children: [
  58. Container(
  59. margin: EdgeInsets.only(left: 16.w),
  60. child: GestureDetector(
  61. onTap: () {
  62. controller.pickSystemFile();
  63. },
  64. child: Align(
  65. alignment: Alignment.centerLeft,
  66. child: Text(
  67. StringName.audioPickerAllFile.tr,
  68. style: TextStyle(
  69. fontSize: 14.sp, color: ColorName.primaryTextColor),
  70. ),
  71. ),
  72. ),
  73. ),
  74. Center(
  75. child: Text(
  76. StringName.importLocalAudio.tr,
  77. style:
  78. TextStyle(fontSize: 17.sp, color: ColorName.primaryTextColor),
  79. )),
  80. Container(
  81. margin: EdgeInsets.only(right: 16.w),
  82. child: GestureDetector(
  83. onTap: () {
  84. Get.back();
  85. },
  86. child: Align(
  87. alignment: Alignment.centerRight,
  88. child: Text(
  89. StringName.cancel.tr,
  90. style: TextStyle(
  91. fontSize: 14.sp, color: ColorName.secondaryTextColor),
  92. ),
  93. ),
  94. ),
  95. ),
  96. ],
  97. ),
  98. ),
  99. );
  100. }
  101. Widget _buildImportBtnView() {
  102. return Container(
  103. color: ColorName.white,
  104. padding: EdgeInsets.symmetric(vertical: 6.h),
  105. child: GestureDetector(
  106. onTap: () {
  107. controller.onImportClick();
  108. },
  109. child: Container(
  110. height: 48.h,
  111. margin: EdgeInsets.symmetric(horizontal: 16.w),
  112. width: double.infinity,
  113. decoration: getCommonDecoration(8.w),
  114. child: Center(
  115. child: Text(
  116. StringName.selectAndImport.tr,
  117. style: TextStyle(fontSize: 16.sp, color: ColorName.white),
  118. ),
  119. ),
  120. ),
  121. ),
  122. );
  123. }
  124. Widget _buildItem(BuildContext context, int index) {
  125. AssetEntity entity = controller.audioList[index];
  126. return GestureDetector(
  127. onTap: () {
  128. controller.onItemClick(entity);
  129. },
  130. child: Obx(() {
  131. return Container(
  132. decoration: controller.currentEntity?.id == entity.id
  133. ? BoxDecoration(
  134. border: Border.all(color: '#6177F2'.toColor(), width: 2.w),
  135. color: '#E7E9F6'.toColor(),
  136. borderRadius: BorderRadius.circular(8.w),
  137. )
  138. : BoxDecoration(
  139. color: ColorName.white,
  140. borderRadius: BorderRadius.circular(8.w),
  141. ),
  142. margin: EdgeInsets.only(bottom: 8.h, left: 16.w, right: 16.w),
  143. padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 14.h),
  144. child: Row(
  145. children: [
  146. Assets.images.iconFilesFile.image(width: 32.w, height: 32.w),
  147. SizedBox(width: 8.w),
  148. Expanded(
  149. child: Column(
  150. crossAxisAlignment: CrossAxisAlignment.start,
  151. children: [
  152. Text(
  153. maxLines: 2,
  154. overflow: TextOverflow.ellipsis,
  155. entity.title ?? '',
  156. style: TextStyle(
  157. fontSize: 14.sp,
  158. color: ColorName.primaryTextColor,
  159. fontWeight: FontWeight.bold),
  160. ),
  161. Row(
  162. children: [
  163. Text(entity.duration.toDouble().toFormattedDuration(),
  164. style: TextStyle(
  165. fontSize: 12.sp,
  166. color: ColorName.tertiaryTextColor)),
  167. SizedBox(width: 6.w),
  168. Container(
  169. width: 1,
  170. height: 9,
  171. color: ColorName.tertiaryTextColor),
  172. SizedBox(width: 6.w),
  173. Text(
  174. entity.createDateSecond
  175. ?.toFormattedDate('yyyy-MM-dd HH:mm') ??
  176. '',
  177. style: TextStyle(
  178. fontSize: 12.sp,
  179. color: ColorName.tertiaryTextColor))
  180. ],
  181. )
  182. ],
  183. ),
  184. )
  185. ],
  186. ),
  187. );
  188. }),
  189. );
  190. }
  191. }