cpdf_themes_widget.dart 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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:compdfkit_flutter/theme/colors.dart';
  10. import 'package:flutter/material.dart';
  11. import '../../../common/util/Strings.dart';
  12. import '../../common/radio/cpdf_radio_group_data.dart';
  13. import '../../common/radio/cpdf_radio_list_group.dart';
  14. import '../../common/radio/cpdf_radio_list_tile.dart';
  15. import '../../common/switch/cpdf_switch_list_tile.dart';
  16. class CPDFThemesWidget extends StatefulWidget {
  17. final CPDFViewCtrl ctrl;
  18. const CPDFThemesWidget({Key? key, required this.ctrl}) : super(key: key);
  19. @override
  20. State<CPDFThemesWidget> createState() => _CPDFPageThemesWidgetState();
  21. }
  22. class _CPDFPageThemesWidgetState extends State<CPDFThemesWidget> {
  23. final themes = [
  24. CPDFRadioGroupData(CPDFColors.themesLight.value,
  25. 'assets/images/ic_themes_light.png', Strings.Light),
  26. CPDFRadioGroupData(CPDFColors.themesDark.value,
  27. 'assets/images/ic_themes_dark.png', Strings.Dark),
  28. CPDFRadioGroupData(CPDFColors.themesSepia.value,
  29. 'assets/images/ic_themes_sepia.png', Strings.Sepia),
  30. CPDFRadioGroupData(CPDFColors.themesReseda.value,
  31. 'assets/images/ic_themes_reseda.png', Strings.Reseda),
  32. ];
  33. int _theme = CPDFColors.themesLight.value;
  34. @override
  35. void initState() {
  36. super.initState();
  37. _initDisplaySettings();
  38. }
  39. void _initDisplaySettings() async {
  40. CPDFViewCtrl ctrl = widget.ctrl;
  41. ctrl.getReadBackgroundColor().then((value) {
  42. setState(() {
  43. _theme = value.value;
  44. });
  45. });
  46. }
  47. @override
  48. Widget build(BuildContext context) {
  49. var sepia = themes.firstWhere((element) {
  50. return element.checkId == CPDFColors.themesSepia.value;
  51. });
  52. if (Theme.of(context).brightness == Brightness.dark) {
  53. sepia.leadingIcon = 'assets/images/ic_themes_sepia_dark.png';
  54. }
  55. var iconColor =
  56. Theme.of(context).brightness == Brightness.dark ? Colors.white : null;
  57. return Column(
  58. children: [
  59. _title(context, Strings.Themes),
  60. Column(
  61. children: themes.map((e) {
  62. return CPDFRadioListTile(
  63. iconColor:
  64. e.checkId != CPDFColors.themesSepia.value ? iconColor : null,
  65. leadingImageIcon: e.leadingIcon,
  66. leadingPackage: 'compdfkit_flutter',
  67. titleText: e.title,
  68. checked: e.checkId == _theme,
  69. onPressed: () {
  70. setState(() {
  71. _theme = e.checkId;
  72. widget.ctrl.setReadBackgroundColor(Color(e.checkId));
  73. });
  74. },
  75. );
  76. }).toList()),
  77. ],
  78. );
  79. }
  80. Widget _title(BuildContext context, String title) {
  81. return Container(
  82. alignment: Alignment.centerLeft,
  83. height: 28,
  84. padding: const EdgeInsets.symmetric(horizontal: 16),
  85. color: Theme.of(context).colorScheme.secondaryContainer,
  86. child: Text(
  87. title,
  88. style: Theme.of(context).textTheme.labelMedium,
  89. ),
  90. );
  91. }
  92. }