diff --git a/CHANGELOG.md b/CHANGELOG.md index 8878bc9..8370ce2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## 0.0.1 * Initial Release -* load text from assets/file +* load text from assets/file * search text by keyword ## 0.0.2 @@ -14,8 +14,12 @@ ## 0.0.4 * textStyle issue fixed -* default focus color change to amber +* default focus color change to amber * refactor code ## 0.0.5 * Updated readme md and github action + +## 0.0.6 +* documentation update +* added onErrorCallback for handle error diff --git a/example/lib/main.dart b/example/lib/main.dart index c189f07..fe62c41 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,3 +1,4 @@ +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_text_viewer/flutter_text_viewer.dart'; @@ -45,6 +46,12 @@ class _HomePageState extends State { highLightColor: Colors.yellow, focusColor: Colors.orange, ignoreCase: true, + onErrorCallback: (error) { + // show error in your UI + if (kDebugMode) { + print("Error: $error"); + } + }, ), showSearchAppBar: true, ); diff --git a/example/pubspec.lock b/example/pubspec.lock index 2457e6e..e11dfed 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.8.2" + version: "2.9.0" boolean_selector: dependency: transitive description: @@ -21,21 +21,14 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.1" + version: "1.2.1" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: @@ -56,7 +49,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.1" flutter: dependency: "direct main" description: flutter @@ -80,7 +73,7 @@ packages: path: ".." relative: true source: path - version: "0.0.4" + version: "0.0.6" image_painter: dependency: "direct main" description: @@ -101,28 +94,28 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.11" + version: "0.12.12" material_color_utilities: dependency: transitive description: name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.1.4" + version: "0.1.5" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.2" sky_engine: dependency: transitive description: flutter @@ -134,7 +127,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.2" + version: "1.9.0" stack_trace: dependency: transitive description: @@ -155,21 +148,21 @@ packages: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.9" + version: "0.4.12" vector_math: dependency: transitive description: diff --git a/lib/model/text_viewer.dart b/lib/model/text_viewer.dart index 519cad9..f6f70ef 100644 --- a/lib/model/text_viewer.dart +++ b/lib/model/text_viewer.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; +typedef OnErrorCallback = void Function(String error); + class TextViewer { /// Provide the path of the file that need to load /// In this case you need to pass .txt file @@ -36,10 +38,14 @@ class TextViewer { ///Search text case is sensitive or not final bool ignoreCase; + ///Search on error Callback + final OnErrorCallback? onErrorCallback; + const TextViewer._({ this.assetPath, this.filePath, this.textContent, + this.onErrorCallback, required this.textStyle, required this.focusTextStyle, required this.highLightTextStyle, @@ -56,18 +62,19 @@ class TextViewer { Color highLightColor = Colors.yellow, Color focusColor = Colors.amber, bool ignoreCase = true, + OnErrorCallback? onErrorCallback, }) { return TextViewer._( - assetPath: assetPath, - textStyle: textStyle, - highLightTextStyle: highLightTextStyle ?? - textStyle.copyWith(background: Paint()..color = highLightColor), - focusTextStyle: focusTextStyle ?? - textStyle.copyWith(background: Paint()..color = focusColor), - highLightColor: highLightColor, - focusColor: focusColor, - ignoreCase: ignoreCase, - ); + assetPath: assetPath, + textStyle: textStyle, + highLightTextStyle: highLightTextStyle ?? + textStyle.copyWith(background: Paint()..color = highLightColor), + focusTextStyle: focusTextStyle ?? + textStyle.copyWith(background: Paint()..color = focusColor), + highLightColor: highLightColor, + focusColor: focusColor, + ignoreCase: ignoreCase, + onErrorCallback: onErrorCallback); } factory TextViewer.file( @@ -78,6 +85,7 @@ class TextViewer { Color highLightColor = Colors.yellow, Color focusColor = Colors.amber, bool ignoreCase = true, + OnErrorCallback? onErrorCallback, }) { return TextViewer._( filePath: filePath, @@ -89,6 +97,7 @@ class TextViewer { highLightColor: highLightColor, focusColor: focusColor, ignoreCase: ignoreCase, + onErrorCallback: onErrorCallback, ); } @@ -100,17 +109,18 @@ class TextViewer { Color highLightColor = Colors.yellow, Color focusColor = Colors.amber, bool ignoreCase = true, + OnErrorCallback? onErrorCallback, }) { return TextViewer._( - textContent: textContent, - textStyle: textStyle, - highLightTextStyle: highLightTextStyle ?? - textStyle.copyWith(background: Paint()..color = highLightColor), - focusTextStyle: focusTextStyle ?? - textStyle.copyWith(background: Paint()..color = focusColor), - highLightColor: highLightColor, - focusColor: focusColor, - ignoreCase: ignoreCase, - ); + textContent: textContent, + textStyle: textStyle, + highLightTextStyle: highLightTextStyle ?? + textStyle.copyWith(background: Paint()..color = highLightColor), + focusTextStyle: focusTextStyle ?? + textStyle.copyWith(background: Paint()..color = focusColor), + highLightColor: highLightColor, + focusColor: focusColor, + ignoreCase: ignoreCase, + onErrorCallback: onErrorCallback); } } diff --git a/lib/screen/text_viewer_page.dart b/lib/screen/text_viewer_page.dart index 4fe7705..73c98e6 100644 --- a/lib/screen/text_viewer_page.dart +++ b/lib/screen/text_viewer_page.dart @@ -1,4 +1,5 @@ import 'dart:io' if (dart.library.html) 'package:flutter_text_viewer/web.dart'; + import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_text_viewer/model/text_viewer.dart'; @@ -126,9 +127,13 @@ class _TextViewerPageState extends State { searchValue = value; }); } else { - ScaffoldMessenger.of(context).showSnackBar(const SnackBar( - content: Text('Enter some value to search'), - )); + if (widget.textViewer.onErrorCallback != null) { + widget.textViewer.onErrorCallback!('Enter some value to search'); + } else { + ScaffoldMessenger.of(context).showSnackBar(const SnackBar( + content: Text('Enter some value to search'), + )); + } } }, ); diff --git a/lib/web.dart b/lib/web.dart index 2eb99c5..0df1906 100644 --- a/lib/web.dart +++ b/lib/web.dart @@ -5,12 +5,12 @@ class File { File(this.path) { throw PlatformException( code: 'Platform Exception', - message: 'ImageViewer.file does not support in web', + message: 'TextViewer.file does not support in web', ); } String readAsStringSync() { throw PlatformException( code: 'Platform Exception', - message: 'ImageViewer.file does not support in web'); + message: 'TextViewer.file does not support in web'); } } diff --git a/pubspec.yaml b/pubspec.yaml index b9750c7..7cbab15 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_text_viewer description: Flutter textviewer package provide easy and simple way to load and search text from assets,file and even direct input string. -version: 0.0.5 +version: 0.0.6 homepage: https://github.com/CodingWithTashi/flutter_text_viewer issue_tracker: https://github.com/CodingWithTashi/flutter_text_viewer/issues @@ -15,6 +15,6 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - flutter_lints: ^2.0.0 + flutter_lints: ^2.0.1 flutter: