/// /// 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/common/util/Strings.dart'; import 'package:compdfkit_flutter/common/util/cpdf_date_util.dart'; import 'package:compdfkit_flutter/core/document/cpdf_document.dart'; import 'package:compdfkit_flutter/core/document/cpdf_info.dart'; import 'package:compdfkit_flutter/core/document/cpdf_permissions_info.dart'; import 'package:compdfkit_flutter/widgets/common/views/cpdf_scaffold.dart'; import 'package:compdfkit_flutter/widgets/common/views/cpdf_tool_bar.dart'; import 'package:flutter/material.dart'; class CPDFDocumentInfoPage extends StatefulWidget { final bool isDark; final CPDFDocument document; const CPDFDocumentInfoPage( {Key? key, this.isDark = false, required this.document}) : super(key: key); @override State createState() => _CPDFDocumentInfoPageState(); } class _CPDFDocumentInfoPageState extends State { @override Widget build(BuildContext context) { return CPDFScaffold( isDark: widget.isDark, appBar: CPDFToolbar.normal( context: context, titleText: Strings.DocumentInfo, leadingOnPressed: () { Navigator.pop(context); }, ), body:ListView(children: [_documentInfo(), _permissionInfo()],), ); } Widget _documentInfo() { return FutureBuilder( future: widget.document.getInfo(), builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.done && snapshot.hasData) { CPDFInfo info = snapshot.data!; return Column( children: [ const CPDFDocumentInfoTitle(title: Strings.Abstract), CPDFDocumentInfoItem( title: Strings.FileName, content: info.fileName), CPDFDocumentInfoItem( title: Strings.FileSize, content: info.fileSizeStr()), CPDFDocumentInfoItem(title: Strings.Title, content: info.title), CPDFDocumentInfoItem( title: Strings.Author, content: info.author), CPDFDocumentInfoItem( title: Strings.Subject, content: info.subject), CPDFDocumentInfoItem( title: Strings.Keywords, content: info.keywords), const CPDFDocumentInfoTitle(title: Strings.CreateInformation), CPDFDocumentInfoItem( title: Strings.Version, content: info.majorVersion.toString()), CPDFDocumentInfoItem( title: Strings.Pages, content: info.pageCount.toString()), CPDFDocumentInfoItem( title: Strings.Creator, content: info.creator), CPDFDocumentInfoItem( title: Strings.CreationDate, content: CPDFDateUtil.format(info.creationDate)), CPDFDocumentInfoItem( title: Strings.ModificationDate, content: CPDFDateUtil.format(info.modificationDate)), ], ); } else { return const Padding(padding: EdgeInsets.zero); } }); } Widget _permissionInfo() { return FutureBuilder( future: widget.document.getPermissionsInfo(), builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.done && snapshot.hasData) { CPDFPermissionsInfo info = snapshot.data!; return Column( children: [ const CPDFDocumentInfoTitle(title: Strings.CreateInformation), CPDFDocumentInfoItem( title: Strings.Printing, content: _allowStr(info.allowsPrinting)), CPDFDocumentInfoItem( title: Strings.ContentCopying, content: _allowStr(info.allowsCopying)), CPDFDocumentInfoItem( title: Strings.DocumentChange, content: _allowStr(info.allowsDocumentChanges)), CPDFDocumentInfoItem( title: Strings.DocumentAssembly, content: _allowStr(info.allowsDocumentAssembly)), CPDFDocumentInfoItem( title: Strings.Commenting, content: _allowStr(info.allowsCommenting)), CPDFDocumentInfoItem( title: Strings.FillingOfFormField, content: _allowStr(info.allowsFormFieldEntry)), ], ); } else { return const Padding(padding: EdgeInsets.zero); } }); } String _allowStr(bool allow) { return allow ? Strings.Allowed : Strings.NotAllowed; } } class CPDFDocumentInfoTitle extends StatelessWidget { final String title; const CPDFDocumentInfoTitle({Key? key, required this.title}) : super(key: key); @override Widget build(BuildContext context) { 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, ), ); } } class CPDFDocumentInfoItem extends StatelessWidget { final String title; final String content; const CPDFDocumentInfoItem( {Key? key, required this.title, required this.content}) : super(key: key); @override Widget build(BuildContext context) { return Container( color: Theme.of(context).colorScheme.background, padding: const EdgeInsets.only(left: 16), child: Column( children: [ SizedBox( height: 56, child: Row( mainAxisSize: MainAxisSize.max, children: [ Text('$title:', style: Theme.of(context).textTheme.labelLarge), Expanded( child: Container( alignment: Alignment.centerRight, padding: const EdgeInsets.only(left: 10, right: 16), child: Text( content, style: Theme.of(context).textTheme.bodyMedium?.copyWith( color: Theme.of(context).colorScheme.primaryContainer), ), )) ], )), const Divider(height: 0.5) ], )); } }