cpdf_page_mode_widget.dart 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. const singlePage = 0;
  14. const doublePage = 1;
  15. const coverPage = 2;
  16. final pageModes = [
  17. CPDFRadioGroupData(
  18. singlePage, 'assets/images/ic_single_page.png', Strings.SinglePage),
  19. CPDFRadioGroupData(
  20. doublePage, 'assets/images/ic_double_page.png', Strings.DoublePage),
  21. CPDFRadioGroupData(
  22. coverPage, 'assets/images/ic_book_mode.png', Strings.BookMode),
  23. ];
  24. class CPDFPageModeWidget extends StatefulWidget {
  25. final CPDFViewCtrl ctrl;
  26. const CPDFPageModeWidget({Key? key, required this.ctrl}) : super(key: key);
  27. @override
  28. State<CPDFPageModeWidget> createState() => _CPDFPageModeWidgetState();
  29. }
  30. class _CPDFPageModeWidgetState extends State<CPDFPageModeWidget> {
  31. // 0:single page、 1: double page、 2: book mode
  32. int _pageMode = -1;
  33. @override
  34. void initState() {
  35. super.initState();
  36. _initDisplaySettings();
  37. }
  38. void _initDisplaySettings() async {
  39. CPDFViewCtrl ctrl = widget.ctrl;
  40. bool isDoublePage = await ctrl.isDoublePageMode();
  41. bool isCoverPage = await ctrl.isCoverPageMode();
  42. setState(() {
  43. if (isDoublePage) {
  44. if (isCoverPage) {
  45. _pageMode = coverPage;
  46. } else {
  47. _pageMode = doublePage;
  48. }
  49. } else {
  50. _pageMode = singlePage;
  51. }
  52. });
  53. }
  54. @override
  55. Widget build(BuildContext context) {
  56. return Column(
  57. children: [
  58. _title(context, ''),
  59. CPDFRadioListGroup(
  60. iconColor: Theme.of(context).brightness == Brightness.dark
  61. ? Colors.white
  62. : null,
  63. checkId: _pageMode,
  64. list: pageModes,
  65. onChecked: (checkId) {
  66. setState(() {
  67. _pageMode = checkId;
  68. switch (checkId) {
  69. case doublePage:
  70. widget.ctrl.setDoublePageMode(true);
  71. widget.ctrl.setCoverPageMode(false);
  72. break;
  73. case coverPage:
  74. widget.ctrl.setDoublePageMode(true);
  75. widget.ctrl.setCoverPageMode(true);
  76. break;
  77. default:
  78. widget.ctrl.setDoublePageMode(false);
  79. widget.ctrl.setCoverPageMode(false);
  80. break;
  81. }
  82. });
  83. },
  84. )
  85. ],
  86. );
  87. }
  88. Widget _title(BuildContext context, String title) {
  89. return Container(
  90. alignment: Alignment.centerLeft,
  91. height: 28,
  92. padding: const EdgeInsets.symmetric(horizontal: 16),
  93. color: Theme.of(context).colorScheme.secondaryContainer,
  94. child: Text(
  95. title,
  96. style: Theme.of(context).textTheme.labelMedium,
  97. ),
  98. );
  99. }
  100. }