123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- ///
- /// 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:compdfkit_flutter/core/document/textsearcher/cpdf_search_data.dart';
- import 'package:compdfkit_flutter/core/document/textsearcher/cpdf_text_searcher.dart';
- import 'package:compdfkit_flutter/widgets/common/views/cpdf_action_widget.dart';
- import 'package:compdfkit_flutter/widgets/viewer/pdfsearch/cpdf_search_result_list_page.dart';
- import 'package:flutter/material.dart';
- import '../../../common/util/Strings.dart';
- import '../../../common/util/cpdf_keyboard_util.dart';
- import '../../../theme/themes.dart';
- class CPDFSearchToolbar extends StatefulWidget {
- final bool isDark;
- final CPDFViewCtrl ctrl;
- final VoidCallback? onBack;
- const CPDFSearchToolbar(
- {Key? key, this.isDark = false, required this.ctrl, this.onBack})
- : super(key: key);
- @override
- State<CPDFSearchToolbar> createState() => _CPDFSearchToolbarState();
- }
- class _CPDFSearchToolbarState extends State<CPDFSearchToolbar> {
- final TextEditingController _textEditingController = TextEditingController();
- bool _hasSearchResult = false;
- String _keyword = '';
- @override
- void dispose() {
- super.dispose();
- _textEditingController.dispose();
- }
- @override
- Widget build(BuildContext context) {
- return Theme(
- data: widget.isDark
- ? comPDFKitDarkTheme
- : comPDFKitLightTheme.copyWith(
- colorScheme: comPDFKitLightTheme.colorScheme
- .copyWith(primary: const Color(0xFFFAFCFF))),
- child: Builder(builder: (context) {
- return AppBar(
- leading: IconButton(
- onPressed: widget.onBack,
- icon: Icon(Icons.arrow_back,
- color: Theme.of(context).colorScheme.onBackground),
- ),
- title: TextField(
- controller: _textEditingController,
- style: Theme.of(context).textTheme.titleMedium,
- decoration: const InputDecoration(
- focusedBorder: UnderlineInputBorder(
- borderSide: BorderSide(color: Colors.transparent, width: 0)
- ),
- enabledBorder: UnderlineInputBorder(
- borderSide: BorderSide(color: Colors.transparent, width: 0)),
- hintText: Strings.Search,
- hintStyle: TextStyle(color: Color(0xFFCCCCCC), fontSize: 18),
- ),
- maxLines: 1,
- textInputAction: TextInputAction.search,
- autofocus: false,
- onEditingComplete: () async {
- _keyword = _textEditingController.text;
- if (_textEditingController.text.isNotEmpty) {
- CPDFKeyboardUtils.hideKeyShowUnfocused();
- CPDFTextSearcher textSearcher =
- widget.ctrl.document.textSearcher;
- var data = await textSearcher.searchFirst(
- keywords: _textEditingController.text);
- if (data != null) {
- textSearcher.searchBegin(
- pageIndex: data.pageIndex,
- textRangeIndex: data.textRangeIndex);
- }
- setState(() {
- _hasSearchResult = data != null;
- });
- }
- },
- ),
- titleSpacing: 10,
- elevation: 2,
- actions: [
- if (_hasSearchResult) ...{
- CPDFActionWidget(
- image: 'assets/images/ic_arrow_search_backward.png',
- onPressed: (context) {
- widget.ctrl.document.textSearcher.searchBackward();
- },
- ),
- CPDFActionWidget(
- image: 'assets/images/ic_arrow_search_forward.png',
- onPressed: (context) {
- widget.ctrl.document.textSearcher.searchForward();
- },
- ),
- CPDFActionWidget(
- image: 'assets/images/ic_searchlist.png',
- onPressed: (context) async {
- CPDFSearchData? data = await Navigator.push(context,
- MaterialPageRoute(builder: (_) {
- return CPDFSearchResultListPage(
- isDark: widget.isDark,
- document: widget.ctrl.document,
- keywords: _keyword);
- }));
- if (data != null) {
- widget.ctrl.setDisplayPageIndex(data.pageIndex);
- widget.ctrl.document.textSearcher.searchBegin(
- pageIndex: data.pageIndex,
- textRangeIndex: data.textRangeIndex);
- }
- },
- )
- }
- ],
- );
- }));
- }
- }
|