convert_excel_options_widget.dart 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import 'package:ConversionFlutterDemo/models/convert_contain_options_bean.dart';
  2. import 'package:ConversionFlutterDemo/states/convert_options_provider.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:provider/provider.dart';
  5. /// convert_excel_options_widget.dart
  6. ///
  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 ConvertExcelOptionsWidget extends StatefulWidget {
  14. const ConvertExcelOptionsWidget({Key? key}) : super(key: key);
  15. @override
  16. State<ConvertExcelOptionsWidget> createState() =>
  17. _ConvertExcelOptionsWidgetState();
  18. }
  19. class _ConvertExcelOptionsWidgetState extends State<ConvertExcelOptionsWidget> {
  20. @override
  21. Widget build(BuildContext context) {
  22. bool containImages = context.select<ConvertOptionsProvider, bool>(
  23. (value) => value.excelOptions.containImages);
  24. bool containAnnotations = context.select<ConvertOptionsProvider, bool>(
  25. (value) => value.excelOptions.containAnnotations);
  26. return SingleChildScrollView(child: Padding(
  27. padding: EdgeInsets.all(8),
  28. child: Column(
  29. crossAxisAlignment: CrossAxisAlignment.start,
  30. children: [
  31. Row(
  32. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  33. children: [
  34. const Text('ContainImages'),
  35. Switch(
  36. value: containImages,
  37. onChanged: (value) {
  38. context
  39. .read<ConvertOptionsProvider>()
  40. .changeExcelOptions(containImages: value);
  41. })
  42. ],
  43. ),
  44. Row(
  45. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  46. children: [
  47. const Text('ContainAnnotations'),
  48. Switch(
  49. value: containAnnotations,
  50. onChanged: (value) {
  51. context
  52. .read<ConvertOptionsProvider>()
  53. .changeExcelOptions(containAnnotations: value);
  54. })
  55. ],
  56. ),
  57. excelWorkSheetOptions((value) {
  58. context
  59. .read<ConvertOptionsProvider>()
  60. .changeExcelOptions(workSheetOptions: value);
  61. }),
  62. excelContentOptions((value) {
  63. context
  64. .read<ConvertOptionsProvider>()
  65. .changeExcelOptions(contentOptions: value);
  66. })
  67. ],
  68. )),);
  69. }
  70. Widget excelWorkSheetOptions(ValueChanged<ExcelWorkSheetOptions> onChanged) {
  71. ExcelWorkSheetOptions workSheetOptions =
  72. context.select<ConvertOptionsProvider, ExcelWorkSheetOptions>(
  73. (value) => value.excelOptions.workSheetOptions);
  74. return Column(
  75. crossAxisAlignment: CrossAxisAlignment.start,
  76. children: [
  77. Text('WorkSheetOptions:'),
  78. _excelWorkSheetOptionsItem(
  79. workSheetOptions, ExcelWorkSheetOptions.ForEachTable, onChanged),
  80. _excelWorkSheetOptionsItem(
  81. workSheetOptions, ExcelWorkSheetOptions.ForEachPage, onChanged),
  82. _excelWorkSheetOptionsItem(
  83. workSheetOptions, ExcelWorkSheetOptions.ForTheDocument, onChanged),
  84. ],
  85. );
  86. }
  87. Widget _excelWorkSheetOptionsItem(
  88. ExcelWorkSheetOptions currentWorkSheetOptions,
  89. ExcelWorkSheetOptions options,
  90. ValueChanged<ExcelWorkSheetOptions> onChanged) {
  91. return CheckboxListTile(
  92. controlAffinity: ListTileControlAffinity.leading,
  93. title: Text(options.name),
  94. value: currentWorkSheetOptions == options,
  95. onChanged: (value) {
  96. onChanged(options);
  97. });
  98. }
  99. Widget excelContentOptions(ValueChanged<ContentOptions> onChanged) {
  100. ContentOptions contentOptions =
  101. context.select<ConvertOptionsProvider, ContentOptions>(
  102. (value) => value.excelOptions.contentOptions);
  103. return Column(
  104. crossAxisAlignment: CrossAxisAlignment.start,
  105. children: [
  106. Text('ContentOptions:'),
  107. _excelContentOptionsItem(
  108. contentOptions, ContentOptions.OnlyText, onChanged),
  109. _excelContentOptionsItem(
  110. contentOptions, ContentOptions.OnlyTable, onChanged),
  111. _excelContentOptionsItem(
  112. contentOptions, ContentOptions.AllContent, onChanged),
  113. ],
  114. );
  115. }
  116. Widget _excelContentOptionsItem(ContentOptions currentOptions,
  117. ContentOptions options, ValueChanged<ContentOptions> onChanged) {
  118. return CheckboxListTile(
  119. controlAffinity: ListTileControlAffinity.leading,
  120. title: Text(options.name),
  121. value: currentOptions == options,
  122. onChanged: (value) {
  123. onChanged(options);
  124. });
  125. }
  126. }