11import 'package:flutter/material.dart' ;
22
3+ typedef OnErrorCallback = void Function (String error);
4+
35class TextViewer {
46 /// Provide the path of the file that need to load
57 /// In this case you need to pass .txt file
@@ -36,10 +38,14 @@ class TextViewer {
3638 ///Search text case is sensitive or not
3739 final bool ignoreCase;
3840
41+ ///Search on error Callback
42+ final OnErrorCallback ? onErrorCallback;
43+
3944 const TextViewer ._({
4045 this .assetPath,
4146 this .filePath,
4247 this .textContent,
48+ this .onErrorCallback,
4349 required this .textStyle,
4450 required this .focusTextStyle,
4551 required this .highLightTextStyle,
@@ -56,18 +62,19 @@ class TextViewer {
5662 Color highLightColor = Colors .yellow,
5763 Color focusColor = Colors .amber,
5864 bool ignoreCase = true ,
65+ OnErrorCallback ? onErrorCallback,
5966 }) {
6067 return TextViewer ._(
61- assetPath: assetPath,
62- textStyle: textStyle,
63- highLightTextStyle: highLightTextStyle ??
64- textStyle.copyWith (background: Paint ()..color = highLightColor),
65- focusTextStyle: focusTextStyle ??
66- textStyle.copyWith (background: Paint ()..color = focusColor),
67- highLightColor: highLightColor,
68- focusColor: focusColor,
69- ignoreCase: ignoreCase,
70- );
68+ assetPath: assetPath,
69+ textStyle: textStyle,
70+ highLightTextStyle: highLightTextStyle ??
71+ textStyle.copyWith (background: Paint ()..color = highLightColor),
72+ focusTextStyle: focusTextStyle ??
73+ textStyle.copyWith (background: Paint ()..color = focusColor),
74+ highLightColor: highLightColor,
75+ focusColor: focusColor,
76+ ignoreCase: ignoreCase,
77+ onErrorCallback : onErrorCallback );
7178 }
7279
7380 factory TextViewer .file (
@@ -78,6 +85,7 @@ class TextViewer {
7885 Color highLightColor = Colors .yellow,
7986 Color focusColor = Colors .amber,
8087 bool ignoreCase = true ,
88+ OnErrorCallback ? onErrorCallback,
8189 }) {
8290 return TextViewer ._(
8391 filePath: filePath,
@@ -89,6 +97,7 @@ class TextViewer {
8997 highLightColor: highLightColor,
9098 focusColor: focusColor,
9199 ignoreCase: ignoreCase,
100+ onErrorCallback: onErrorCallback,
92101 );
93102 }
94103
@@ -100,17 +109,18 @@ class TextViewer {
100109 Color highLightColor = Colors .yellow,
101110 Color focusColor = Colors .amber,
102111 bool ignoreCase = true ,
112+ OnErrorCallback ? onErrorCallback,
103113 }) {
104114 return TextViewer ._(
105- textContent: textContent,
106- textStyle: textStyle,
107- highLightTextStyle: highLightTextStyle ??
108- textStyle.copyWith (background: Paint ()..color = highLightColor),
109- focusTextStyle: focusTextStyle ??
110- textStyle.copyWith (background: Paint ()..color = focusColor),
111- highLightColor: highLightColor,
112- focusColor: focusColor,
113- ignoreCase: ignoreCase,
114- );
115+ textContent: textContent,
116+ textStyle: textStyle,
117+ highLightTextStyle: highLightTextStyle ??
118+ textStyle.copyWith (background: Paint ()..color = highLightColor),
119+ focusTextStyle: focusTextStyle ??
120+ textStyle.copyWith (background: Paint ()..color = focusColor),
121+ highLightColor: highLightColor,
122+ focusColor: focusColor,
123+ ignoreCase: ignoreCase,
124+ onErrorCallback : onErrorCallback );
115125 }
116126}
0 commit comments