cpdf_page_setting_widget.dart 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. ///
  2. /// Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
  3. ///
  4. /// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  5. /// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  6. /// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  7. /// This notice may not be removed from this file.
  8. import 'package:compdfkit_flutter/core/cpdf_view_ctrl.dart';
  9. import 'package:flutter/material.dart';
  10. import '../../../common/util/Strings.dart';
  11. import '../../common/radio/cpdf_radio_group_data.dart';
  12. import '../../common/radio/cpdf_radio_list_group.dart';
  13. import '../../common/switch/cpdf_switch_list_tile.dart';
  14. class CPDFPageSettingWidget extends StatefulWidget {
  15. final CPDFViewCtrl ctrl;
  16. const CPDFPageSettingWidget({Key? key, required this.ctrl}) : super(key: key);
  17. @override
  18. State<CPDFPageSettingWidget> createState() => _CPDFPageSettingWidgetState();
  19. }
  20. class _CPDFPageSettingWidgetState extends State<CPDFPageSettingWidget> {
  21. bool _isContinuousScroll = false;
  22. bool _cropMode = false;
  23. @override
  24. void initState() {
  25. super.initState();
  26. _initDisplaySettings();
  27. }
  28. void _initDisplaySettings() async {
  29. CPDFViewCtrl ctrl = widget.ctrl;
  30. bool isContinuous = await ctrl.isContinueMode();
  31. bool isCrop = await ctrl.isCropMode();
  32. setState(() {
  33. _isContinuousScroll = isContinuous;
  34. _cropMode = isCrop;
  35. });
  36. }
  37. @override
  38. Widget build(BuildContext context) {
  39. return Column(
  40. children: [
  41. _title(context, ''),
  42. CPDFSwitchListTile(
  43. iconColor: Theme.of(context).brightness == Brightness.dark
  44. ? Colors.white
  45. : null,
  46. leadingPackage: 'compdfkit_flutter',
  47. leadingImageIcon: 'assets/images/ic_continuous_scroll.png',
  48. titleText: Strings.ContinuousScroll,
  49. checked: _isContinuousScroll,
  50. onChecked: (check) {
  51. setState(() {
  52. _isContinuousScroll = check;
  53. widget.ctrl.setContinueMode(_isContinuousScroll);
  54. });
  55. },
  56. ),
  57. CPDFSwitchListTile(
  58. iconColor: Theme.of(context).brightness == Brightness.dark
  59. ? Colors.white
  60. : null,
  61. leadingPackage: 'compdfkit_flutter',
  62. leadingImageIcon: 'assets/images/ic_crop_mode.png',
  63. titleText: Strings.Crop,
  64. checked: _cropMode,
  65. onChecked: (check) {
  66. setState(() {
  67. _cropMode = check;
  68. widget.ctrl.setCropMode(_cropMode);
  69. });
  70. },
  71. )
  72. ],
  73. );
  74. }
  75. Widget _title(BuildContext context, String title) {
  76. return Container(
  77. alignment: Alignment.centerLeft,
  78. height: 28,
  79. padding: const EdgeInsets.symmetric(horizontal: 16),
  80. color: Theme.of(context).colorScheme.secondaryContainer,
  81. child: Text(
  82. title,
  83. style: Theme.of(context).textTheme.labelMedium,
  84. ),
  85. );
  86. }
  87. }