/// /// Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved. /// /// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW /// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT. /// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES. /// This notice may not be removed from this file. import 'package:compdfkit_flutter/core/cpdf_view_ctrl.dart'; import 'package:compdfkit_flutter/theme/colors.dart'; import 'package:flutter/material.dart'; import '../../../common/util/Strings.dart'; import '../../common/radio/cpdf_radio_group_data.dart'; import '../../common/radio/cpdf_radio_list_group.dart'; import '../../common/radio/cpdf_radio_list_tile.dart'; import '../../common/switch/cpdf_switch_list_tile.dart'; class CPDFThemesWidget extends StatefulWidget { final CPDFViewCtrl ctrl; const CPDFThemesWidget({Key? key, required this.ctrl}) : super(key: key); @override State createState() => _CPDFPageThemesWidgetState(); } class _CPDFPageThemesWidgetState extends State { final themes = [ CPDFRadioGroupData(CPDFColors.themesLight.value, 'assets/images/ic_themes_light.png', Strings.Light), CPDFRadioGroupData(CPDFColors.themesDark.value, 'assets/images/ic_themes_dark.png', Strings.Dark), CPDFRadioGroupData(CPDFColors.themesSepia.value, 'assets/images/ic_themes_sepia.png', Strings.Sepia), CPDFRadioGroupData(CPDFColors.themesReseda.value, 'assets/images/ic_themes_reseda.png', Strings.Reseda), ]; int _theme = CPDFColors.themesLight.value; @override void initState() { super.initState(); _initDisplaySettings(); } void _initDisplaySettings() async { CPDFViewCtrl ctrl = widget.ctrl; ctrl.getReadBackgroundColor().then((value) { setState(() { _theme = value.value; }); }); } @override Widget build(BuildContext context) { var sepia = themes.firstWhere((element) { return element.checkId == CPDFColors.themesSepia.value; }); if (Theme.of(context).brightness == Brightness.dark) { sepia.leadingIcon = 'assets/images/ic_themes_sepia_dark.png'; } var iconColor = Theme.of(context).brightness == Brightness.dark ? Colors.white : null; return Column( children: [ _title(context, Strings.Themes), Column( children: themes.map((e) { return CPDFRadioListTile( iconColor: e.checkId != CPDFColors.themesSepia.value ? iconColor : null, leadingImageIcon: e.leadingIcon, leadingPackage: 'compdfkit_flutter', titleText: e.title, checked: e.checkId == _theme, onPressed: () { setState(() { _theme = e.checkId; widget.ctrl.setReadBackgroundColor(Color(e.checkId)); }); }, ); }).toList()), ], ); } Widget _title(BuildContext context, String title) { return Container( alignment: Alignment.centerLeft, height: 28, padding: const EdgeInsets.symmetric(horizontal: 16), color: Theme.of(context).colorScheme.secondaryContainer, child: Text( title, style: Theme.of(context).textTheme.labelMedium, ), ); } }