1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- ///
- /// 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_document.dart';
- import 'package:compdfkit_flutter/core/document/cpdf_outline_data.dart';
- import 'package:flutter/material.dart';
- import 'cpdf_outline_item.dart';
- class CPDFOutlinePage extends StatefulWidget {
- final CPDFDocument document;
- const CPDFOutlinePage({Key? key, required this.document}) : super(key: key);
- @override
- State<CPDFOutlinePage> createState() => _CPDFOutlinePageState();
- }
- class _CPDFOutlinePageState extends State<CPDFOutlinePage> with AutomaticKeepAliveClientMixin
- {
- List<CPDFOutlineData> _outlineList = List.empty(growable: true);
- final globalKey = GlobalKey<AnimatedListState>();
- @override
- void initState() {
- super.initState();
- widget.document.getOutline().then((value) {
- setState(() {
- _outlineList = value;
- });
- });
- }
- @override
- Widget build(BuildContext context) {
- return ListView.builder(
- itemCount: _outlineList.length,
- itemBuilder: (context, index) {
- return CPDFOutlineItem(
- outlineData: _outlineList[index],
- onDisplayPageIndex: (pageIndex) {
- Navigator.pop(context, pageIndex);
- },
- onExpanded: (expanded) {
- setState(() {
- if (expanded) {
- loopCollapseItem(_outlineList[index]);
- } else {
- _outlineList[index].expanded = true;
- _outlineList.insertAll(
- index + 1, _outlineList[index].childOutline ?? []);
- }
- });
- },
- );
- });
- }
- @override
- bool get wantKeepAlive => true;
- void loopCollapseItem(CPDFOutlineData data) {
- data.expanded = false;
- data.childOutline?.forEach((element) {
- if (element.childOutline != null && element.childOutline!.isNotEmpty) {
- loopCollapseItem(element);
- }
- _outlineList.remove(element);
- });
- }
- }
|