123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- ///
- /// 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:flutter/material.dart';
- import '../../../common/util/Strings.dart';
- import '../../common/radio/cpdf_radio_group_data.dart';
- import '../../common/radio/cpdf_radio_list_group.dart';
- const singlePage = 0;
- const doublePage = 1;
- const coverPage = 2;
- final pageModes = [
- CPDFRadioGroupData(
- singlePage, 'assets/images/ic_single_page.png', Strings.SinglePage),
- CPDFRadioGroupData(
- doublePage, 'assets/images/ic_double_page.png', Strings.DoublePage),
- CPDFRadioGroupData(
- coverPage, 'assets/images/ic_book_mode.png', Strings.BookMode),
- ];
- class CPDFPageModeWidget extends StatefulWidget {
- final CPDFViewCtrl ctrl;
- const CPDFPageModeWidget({Key? key, required this.ctrl}) : super(key: key);
- @override
- State<CPDFPageModeWidget> createState() => _CPDFPageModeWidgetState();
- }
- class _CPDFPageModeWidgetState extends State<CPDFPageModeWidget> {
- // 0:single page、 1: double page、 2: book mode
- int _pageMode = -1;
- @override
- void initState() {
- super.initState();
- _initDisplaySettings();
- }
- void _initDisplaySettings() async {
- CPDFViewCtrl ctrl = widget.ctrl;
- bool isDoublePage = await ctrl.isDoublePageMode();
- bool isCoverPage = await ctrl.isCoverPageMode();
- setState(() {
- if (isDoublePage) {
- if (isCoverPage) {
- _pageMode = coverPage;
- } else {
- _pageMode = doublePage;
- }
- } else {
- _pageMode = singlePage;
- }
- });
- }
- @override
- Widget build(BuildContext context) {
- return Column(
- children: [
- _title(context, ''),
- CPDFRadioListGroup(
- iconColor: Theme.of(context).brightness == Brightness.dark
- ? Colors.white
- : null,
- checkId: _pageMode,
- list: pageModes,
- onChecked: (checkId) {
- setState(() {
- _pageMode = checkId;
- switch (checkId) {
- case doublePage:
- widget.ctrl.setDoublePageMode(true);
- widget.ctrl.setCoverPageMode(false);
- break;
- case coverPage:
- widget.ctrl.setDoublePageMode(true);
- widget.ctrl.setCoverPageMode(true);
- break;
- default:
- widget.ctrl.setDoublePageMode(false);
- widget.ctrl.setCoverPageMode(false);
- break;
- }
- });
- },
- )
- ],
- );
- }
- 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,
- ),
- );
- }
- }
|