123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- import 'package:compdfkit_flutter/theme/colors.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import '../core/cpdf_view_ctrl.dart';
- import '../cpdf_configuration.dart';
- import '../theme/themes.dart';
- import 'common/pdfview/cpdf_page_indicator.dart';
- import 'common/pdfview/cpdf_page_slider_bar.dart';
- import 'common/pdfview/cpdf_reader_widget.dart';
- import 'common/slider/cpdf_slider_theme.dart';
- import 'common/views/cpdf_main_tool_bar.dart';
- /// 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.
- class CPDFReaderViewPage extends StatefulWidget {
- final bool isDark;
- const CPDFReaderViewPage({super.key, this.isDark = false});
- @override
- State<CPDFReaderViewPage> createState() => _CPDFReaderViewPageState();
- }
- class _CPDFReaderViewPageState extends State<CPDFReaderViewPage>
- with SingleTickerProviderStateMixin {
- CPDFViewCtrl? ctrl;
- bool _isNormalMode = true;
- late final AnimationController _controller;
- @override
- void initState() {
- super.initState();
- _controller = AnimationController(
- vsync: this, duration: const Duration(milliseconds: 300));
- }
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- theme: comPDFKitLightTheme,
- darkTheme: comPDFKitDarkTheme,
- themeMode: widget.isDark ? ThemeMode.dark : ThemeMode.light,
- home: Scaffold(
- primary: _isNormalMode,
- appBar: PreferredSize(
- preferredSize: const Size(0, 0),
- child: Builder(builder: (context) {
- return AppBar(
- systemOverlayStyle: SystemUiOverlayStyle(
- systemNavigationBarColor:
- Theme.of(context).scaffoldBackgroundColor),
- backgroundColor:
- widget.isDark ? null : CPDFColors.backgroundLight,
- elevation: 0,
- );
- })),
- body: Column(
- children: [
- if (ctrl != null) ...{
- CPDFMainToolbar(
- visible: _isNormalMode,
- controller: _controller,
- ctrl: ctrl!,
- isDark: widget.isDark)
- },
- Expanded(
- child: Stack(
- alignment: Alignment.center,
- children: [
- CPDFReaderWidget(
- documentPath: "",
- configuration: CPDFConfiguration(),
- onComPDFKitWidgetCreate: (ctrl) {
- setState(() {
- this.ctrl = ctrl;
- setReaderViewCallback();
- });
- },
- ),
- if (ctrl != null) ...{
- Positioned(
- bottom: 20,
- child: AnimatedOpacity(
- opacity: _isNormalMode ? 1.0 : 0.0,
- duration: const Duration(milliseconds: 300),
- curve: Curves.fastOutSlowIn,
- child: CPDFPageIndicator(
- ctrl: ctrl!,
- isDark: widget.isDark,
- ),
- )),
- Positioned(
- right: 0,
- top: 0,
- bottom: 0,
- child: AnimatedOpacity(
- opacity: _isNormalMode ? 1.0 : 0.0,
- duration: const Duration(milliseconds: 300),
- curve: Curves.fastOutSlowIn,
- child: CPDFPageNavigationSliderBar(
- ctrl: ctrl!,
- position: CPDFSliderIndicatorPosition.right),
- )),
- },
- ],
- ))
- ],
- )),
- );
- }
- void setReaderViewCallback() {
- ctrl!.onTapMainDocArea.stream.listen((event) {
- setState(() {
- _isNormalMode = !_isNormalMode;
- });
- });
- }
- }
|