123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- /// 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/document/cpdf_outline_data.dart';
- import 'package:flutter/material.dart';
- import '../../../../theme/colors.dart';
- typedef OutlineExpandedCallback = Function(bool isExpanded);
- class CPDFOutlineItem extends StatefulWidget {
- final CPDFOutlineData outlineData;
- final ValueChanged<int>? onDisplayPageIndex;
- final OutlineExpandedCallback? onExpanded;
- const CPDFOutlineItem(
- {Key? key,
- required this.outlineData,
- this.onDisplayPageIndex,
- this.onExpanded})
- : super(key: key);
- @override
- State<CPDFOutlineItem> createState() => _CPDFOutlineItemState();
- }
- class _CPDFOutlineItemState extends State<CPDFOutlineItem> {
- bool _expanded = false;
- @override
- void initState() {
- super.initState();
- _expanded = widget.outlineData.expanded;
- }
- @override
- Widget build(BuildContext context) {
- CPDFOutlineData data = widget.outlineData;
- _expanded = widget.outlineData.expanded;
- return Ink(
- color: _backgroundColor(context, data.level == 1),
- child: InkWell(
- child: Column(
- children: [
- Row(
- children: [
- Padding(
- padding: EdgeInsets.only(left: (data.level - 1) * 8),
- child: AnimatedOpacity(
- opacity: data.childOutline != null &&
- data.childOutline!.isNotEmpty
- ? 1.0
- : 0.0,
- duration: const Duration(milliseconds: 100),
- child: IconButton(
- splashRadius: 20,
- icon: ImageIcon(AssetImage(
- _expanded
- ? 'assets/images/ic_arrow_down.png'
- : 'assets/images/ic_arrow_right.png',
- package: 'compdfkit_flutter')),
- onPressed: () {
- if (data.childOutline != null &&
- data.childOutline!.isNotEmpty) {
- if (widget.onExpanded != null) {
- widget.onExpanded!(_expanded);
- }
- _expanded = !_expanded;
- widget.outlineData.expanded = _expanded;
- }
- },
- ),
- )),
- Expanded(
- child: Text(
- widget.outlineData.title,
- style: Theme.of(context).textTheme.titleSmall,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- )),
- Padding(
- padding: const EdgeInsets.only(right: 16),
- child: Text(
- (widget.outlineData.pageIndex + 1).toString(),
- style: const TextStyle(fontSize: 12),
- ),
- )
- ],
- ),
- const Divider(height: 0.5)
- ],
- ),
- onTap: () {
- if (widget.onDisplayPageIndex != null) {
- widget.onDisplayPageIndex!(data.pageIndex);
- }
- },
- ),
- );
- }
- Color _backgroundColor(BuildContext context, bool root) {
- if (root) {
- if (Theme.of(context).brightness == Brightness.dark) {
- return CPDFColors.readerSettingHeadBgColorDark;
- } else {
- return CPDFColors.readerSettingHeadBgColorLight;
- }
- } else {
- if (Theme.of(context).brightness == Brightness.dark) {
- return const Color(0xFF414347);
- } else {
- return Colors.white;
- }
- }
- }
- }
|