convert_list_widget.dart 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import 'package:ConversionFlutterDemo/models/convert_bean.dart';
  2. import 'package:ConversionFlutterDemo/states/convert_provider.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:open_file/open_file.dart';
  5. import 'package:provider/provider.dart';
  6. /// convert_list_widget.dart
  7. /// Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
  8. ///
  9. /// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  10. /// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  11. /// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  12. /// This notice may not be removed from this file.
  13. class ConvertListWidget extends StatefulWidget {
  14. const ConvertListWidget({Key? key}) : super(key: key);
  15. @override
  16. State<ConvertListWidget> createState() => _ConvertListWidgetState();
  17. }
  18. class _ConvertListWidgetState extends State<ConvertListWidget> {
  19. @override
  20. Widget build(BuildContext context) {
  21. var count =
  22. context.select<ConvertProvider, int>((value) => value.items.length);
  23. return ListView.builder(
  24. itemCount: count,
  25. primary: true,
  26. shrinkWrap: true,
  27. physics: new ClampingScrollPhysics(),
  28. itemBuilder: (BuildContext context, int index) {
  29. //设置子条目
  30. return Builder(builder: (context) {
  31. ConvertBean bean = context.select<ConvertProvider, ConvertBean>(
  32. (value) => value.items[index]);
  33. context.select<ConvertProvider, int>(
  34. (value) => value.items[index].progress);
  35. int status = context.select<ConvertProvider, int>(
  36. (value) => value.items[index].status);
  37. return Column(
  38. children: [
  39. ListTile(
  40. isThreeLine: true,
  41. title: Text(
  42. bean.fileName,
  43. style: const TextStyle(fontSize: 18),
  44. ),
  45. subtitle: Text(
  46. "PDF convert ${bean.convertType.toUpperCase()} ${bean.outputPath != null ? "\n${bean.outputPath}" : ''}",
  47. style: const TextStyle(fontSize: 12),
  48. ),
  49. trailing: Text(bean.getStatusName()),
  50. // item 直观感受是整体大小
  51. contentPadding:
  52. const EdgeInsets.symmetric(horizontal: 12, vertical: 2),
  53. onTap: () async {
  54. print('ontap list status:${status}, path:${bean.outputPath}');
  55. if (status == convertSuccess) {
  56. OpenFile.open(bean.outputPath);
  57. }
  58. },
  59. ),
  60. ],
  61. );
  62. });
  63. },
  64. );
  65. }
  66. }