From 2f13b295c9ddb9468b5834bcd6ecf444d9058ca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Caras?= Date: Tue, 9 Jan 2024 23:03:23 +0100 Subject: [PATCH] fix(ocr): correctly load data from API Also for some reason eng traineddata were missing in the app, hopefully fixed by this --- lib/network/tessdata.dart | 7 ++++--- lib/views/home.dart | 13 +++++++------ pubspec.yaml | 4 ++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/network/tessdata.dart b/lib/network/tessdata.dart index 20e1c32..a8dcca2 100644 --- a/lib/network/tessdata.dart +++ b/lib/network/tessdata.dart @@ -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> getAvailableData() async { - final res = await _client.get>>( + final res = await _client.get>( "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>.from(res.data ?? []); final dataFiles = []; - for (final file in data ?? >[]) { + for (final file in data) { if (!(file["name"] as String).endsWith(".traineddata")) continue; dataFiles.add((file["name"] as String).replaceAll(".traineddata", "")); } diff --git a/lib/views/home.dart b/lib/views/home.dart index 6b31dac..3420864 100644 --- a/lib/views/home.dart +++ b/lib/views/home.dart @@ -472,12 +472,13 @@ class _HomeViewState extends State { PlatformButton( text: AppLocalizations.of(context).download, onPressed: () { - Navigator.of(context).push( - platformRoute( - (c) => const TessdataListView(), - ), - ); - Navigator.of(c).pop(); + Navigator.of(context) + .push( + platformRoute( + (c) => const TessdataListView(), + ), + ) + .then((value) => Navigator.of(c).pop()); }, ), PlatformButton( diff --git a/pubspec.yaml b/pubspec.yaml index f79b64d..9e5b183 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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