From 66fece5a089c4091156fa3382a2e11b0275005d0 Mon Sep 17 00:00:00 2001 From: enrique-lozano Date: Tue, 30 Apr 2024 16:54:30 +0200 Subject: [PATCH] fix: CSV import issue with small files Resolves #148 --- lib/app/settings/import_csv.dart | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/app/settings/import_csv.dart b/lib/app/settings/import_csv.dart index 5ca8fddb..d86727ee 100644 --- a/lib/app/settings/import_csv.dart +++ b/lib/app/settings/import_csv.dart @@ -33,6 +33,8 @@ class ImportCSVPage extends StatefulWidget { State createState() => _ImportCSVPageState(); } +const _rowsToPreview = 5; + class _ImportCSVPageState extends State { int currentStep = 0; @@ -291,6 +293,8 @@ class _ImportCSVPageState extends State { Widget build(BuildContext context) { final t = Translations.of(context); + print("csv data: $csvData"); + return Scaffold( appBar: AppBar(title: Text(t.backup.import.manual_import.title)), body: Stepper( @@ -408,7 +412,11 @@ class _ImportCSVPageState extends State { .map((item) => DataColumn(label: Text(item))) .toList(), rows: csvData! - .sublist(1, 5) + .sublist( + 1, + _rowsToPreview > csvData!.length + ? null + : _rowsToPreview) .map( (csvrow) => DataRow( cells: csvrow @@ -420,9 +428,9 @@ class _ImportCSVPageState extends State { .toList(), ), ), - if (csvData!.length - 4 >= 1) + if (csvData!.length - _rowsToPreview >= 1) Text( - '+${csvData!.length - 4} rows', + '+${csvData!.length - _rowsToPreview} rows', textAlign: TextAlign.left, style: Theme.of(context).textTheme.labelSmall, ),