cpdf_display_mode_widget.dart 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. final displayModes = [
  14. CPDFRadioGroupData(
  15. 0, 'assets/images/ic_vertical_scrolling.png', Strings.VerticalScrolling),
  16. CPDFRadioGroupData(1, 'assets/images/ic_horizontal_scrolling.png',
  17. Strings.HorizontalScrolling)
  18. ];
  19. class CPDFDisplayModeWidget extends StatefulWidget {
  20. final CPDFViewCtrl ctrl;
  21. const CPDFDisplayModeWidget({Key? key, required this.ctrl}) : super(key: key);
  22. @override
  23. State<CPDFDisplayModeWidget> createState() => _CPDFDisplayModeWidgetState();
  24. }
  25. class _CPDFDisplayModeWidgetState extends State<CPDFDisplayModeWidget> {
  26. bool _isVerticalMode = true;
  27. @override
  28. void initState() {
  29. super.initState();
  30. _initDisplaySettings();
  31. }
  32. void _initDisplaySettings() async {
  33. CPDFViewCtrl ctrl = widget.ctrl;
  34. bool verticalMode = await ctrl.isVerticalMode();
  35. setState(() {
  36. _isVerticalMode = verticalMode;
  37. });
  38. }
  39. @override
  40. Widget build(BuildContext context) {
  41. return Column(
  42. children: [
  43. _title(context, Strings.DisplayMode),
  44. CPDFRadioListGroup(
  45. iconColor: Theme.of(context).brightness == Brightness.dark
  46. ? Colors.white
  47. : null,
  48. checkId: _isVerticalMode ? 0 : 1,
  49. list: displayModes,
  50. onChecked: (checkId) {
  51. setState(() {
  52. _isVerticalMode = checkId == 0;
  53. widget.ctrl.setVerticalMode(_isVerticalMode);
  54. });
  55. },
  56. )
  57. ],
  58. );
  59. }
  60. Widget _title(BuildContext context, String title) {
  61. return Container(
  62. alignment: Alignment.centerLeft,
  63. height: 28,
  64. padding: const EdgeInsets.symmetric(horizontal: 16),
  65. color: Theme.of(context).colorScheme.secondaryContainer,
  66. child: Text(
  67. title,
  68. style: Theme.of(context).textTheme.labelMedium,
  69. ),
  70. );
  71. }
  72. }