fix(ocr): correctly load data from API
Also for some reason eng traineddata were missing in the app, hopefully fixed by this
This commit is contained in:
parent
1c85e0150d
commit
2f13b295c9
3 changed files with 13 additions and 11 deletions
|
@ -11,21 +11,22 @@ class TessdataApi {
|
|||
static final Dio _client = Dio(
|
||||
BaseOptions(
|
||||
validateStatus: (status) => true,
|
||||
headers: {"User-Agent": "prasule/1.0.0"},
|
||||
),
|
||||
);
|
||||
|
||||
/// Gets available languages from the repo
|
||||
static Future<List<String>> getAvailableData() async {
|
||||
final res = await _client.get<List<Map<String, dynamic>>>(
|
||||
final res = await _client.get<List<dynamic>>(
|
||||
"https://git.mnau.xyz/api/v1/repos/hernik/tessdata_fast/contents",
|
||||
options: Options(headers: {"Accept": "application/json"}),
|
||||
);
|
||||
if ((res.statusCode ?? 500) > 399) {
|
||||
return Future.error("The server returned status code ${res.statusCode}");
|
||||
}
|
||||
final data = res.data;
|
||||
final data = List<Map<String, dynamic>>.from(res.data ?? []);
|
||||
final dataFiles = <String>[];
|
||||
for (final file in data ?? <Map<String, dynamic>>[]) {
|
||||
for (final file in data) {
|
||||
if (!(file["name"] as String).endsWith(".traineddata")) continue;
|
||||
dataFiles.add((file["name"] as String).replaceAll(".traineddata", ""));
|
||||
}
|
||||
|
|
|
@ -472,12 +472,13 @@ class _HomeViewState extends State<HomeView> {
|
|||
PlatformButton(
|
||||
text: AppLocalizations.of(context).download,
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(
|
||||
Navigator.of(context)
|
||||
.push(
|
||||
platformRoute(
|
||||
(c) => const TessdataListView(),
|
||||
),
|
||||
);
|
||||
Navigator.of(c).pop();
|
||||
)
|
||||
.then((value) => Navigator.of(c).pop());
|
||||
},
|
||||
),
|
||||
PlatformButton(
|
||||
|
|
|
@ -84,8 +84,8 @@ flutter:
|
|||
# the material Icons class.
|
||||
uses-material-design: true
|
||||
assets:
|
||||
- assets/
|
||||
- assets/tessdata/
|
||||
- assets/tessdata_config.json
|
||||
- assets/tessdata/eng.traineddata
|
||||
# To add assets to your application, add an assets section, like this:
|
||||
# assets:
|
||||
# - images/a_dot_burr.jpeg
|
||||
|
|
Loading…
Reference in a new issue