main
1import 'dart:io';
2
3import 'package:blood_pressure_app/features/data_picker/interval_picker.dart';
4import 'package:blood_pressure_app/features/export_import/active_field_customization.dart';
5import 'package:blood_pressure_app/features/export_import/export_button.dart';
6import 'package:blood_pressure_app/features/export_import/export_warn_banner.dart';
7import 'package:blood_pressure_app/features/export_import/import_button.dart';
8import 'package:blood_pressure_app/features/settings/tiles/dropdown_list_tile.dart';
9import 'package:blood_pressure_app/features/settings/tiles/input_list_tile.dart';
10import 'package:blood_pressure_app/features/settings/tiles/number_input_list_tile.dart';
11import 'package:blood_pressure_app/model/storage/export_columns_store.dart';
12import 'package:blood_pressure_app/model/storage/storage.dart';
13import 'package:flutter/material.dart';
14import 'package:blood_pressure_app/l10n/app_localizations.dart';
15import 'package:persistent_user_dir_access_android/persistent_user_dir_access_android.dart';
16import 'package:provider/provider.dart';
17
18/// Screen to configure and perform exports and imports of blood pressure values.
19class ExportImportScreen extends StatelessWidget {
20 /// Create a screen that shows options for ex- and importing data.
21 const ExportImportScreen({super.key});
22
23 @override
24 Widget build(BuildContext context) {
25 final localizations = AppLocalizations.of(context)!;
26 return Scaffold(
27 appBar: AppBar(
28 title: Text(localizations.exportImport),
29 backgroundColor: Theme.of(context).primaryColor,
30 ),
31 body: Consumer<ExportSettings>(builder: (context, settings, child) => SingleChildScrollView(
32 child: Column(
33 children: [
34 Consumer<CsvExportSettings>(builder: (context, csvExportSettings, child) =>
35 Consumer<ExportColumnsManager>(builder: (context, availableColumns, child) =>
36 ExportWarnBanner(
37 exportSettings: settings,
38 csvExportSettings: csvExportSettings,
39 availableColumns: availableColumns,
40 ),
41 ),
42 ),
43 const SizedBox(
44 height: 15,
45 ),
46 if (settings.exportFormat != ExportFormat.db)
47 const IntervalPicker(type: IntervalStoreManagerLocation.exportPage),
48 if (Platform.isAndroid) // only supported on android
49 ListTile(
50 title: Text(localizations.exportDir),
51 subtitle: settings.defaultExportDir.isNotEmpty ? Text(settings.defaultExportDir) : null,
52 trailing: settings.defaultExportDir.isEmpty ? const Icon(Icons.folder_open) : const Icon(Icons.delete),
53 onTap: () async {
54 if (settings.defaultExportDir.isEmpty) {
55 final uri = await const PersistentUserDirAccessAndroid().requestDirectoryUri();
56 settings.defaultExportDir = uri ?? '';
57 } else {
58 settings.defaultExportDir = '';
59 }
60 },
61 ),
62 SwitchListTile(
63 title: Text(localizations.exportAfterEveryInput),
64 subtitle: Text(localizations.exportAfterEveryInputDesc),
65 value: settings.exportAfterEveryEntry,
66 onChanged: (value) {
67 settings.exportAfterEveryEntry = value;
68 },
69 ),
70 DropDownListTile<ExportFormat>(
71 key: const Key('exportFormat'),
72 title: Text(localizations.exportFormat),
73 value: settings.exportFormat,
74 items: [
75 DropdownMenuItem(
76 value: ExportFormat.csv, child: Text(localizations.csv)),
77 DropdownMenuItem(
78 value: ExportFormat.pdf, child: Text(localizations.pdf)),
79 DropdownMenuItem(
80 value: ExportFormat.db, child: Text(localizations.db)),
81 DropdownMenuItem(
82 value: ExportFormat.xsl, child: Text(localizations.xsl)),
83 ],
84 onChanged: (ExportFormat? value) {
85 if (value != null) {
86 settings.exportFormat = value;
87 }
88 },
89 ),
90 if (settings.exportFormat == ExportFormat.csv)
91 Consumer<CsvExportSettings>(builder: (context, csvExportSettings, child) =>
92 Column(
93 children: [
94 InputListTile(
95 label: localizations.fieldDelimiter,
96 value: csvExportSettings.fieldDelimiter,
97 onSubmit: (value) {
98 csvExportSettings.fieldDelimiter = value;
99 },
100 ),
101 InputListTile(
102 label: localizations.textDelimiter,
103 value: csvExportSettings.textDelimiter,
104 onSubmit: (value) {
105 csvExportSettings.textDelimiter = value;
106 },
107 ),
108 SwitchListTile(
109 title: Text(localizations.exportCsvHeadline),
110 subtitle: Text(localizations.exportCsvHeadlineDesc),
111 value: csvExportSettings.exportHeadline,
112 onChanged: (value) {
113 csvExportSettings.exportHeadline = value;
114 },
115 ),
116 ],
117 ),
118 ),
119 if (settings.exportFormat == ExportFormat.pdf)
120 Consumer<PdfExportSettings>(builder: (context, pdfExportSettings, child) =>
121 Column(
122 children: [
123 SwitchListTile(
124 title: Text(localizations.exportPdfExportTitle),
125 value: pdfExportSettings.exportTitle,
126 onChanged: (value) {
127 pdfExportSettings.exportTitle = value;
128 },),
129 SwitchListTile(
130 title: Text(localizations.exportPdfExportStatistics),
131 value: pdfExportSettings.exportStatistics,
132 onChanged: (value) {
133 pdfExportSettings.exportStatistics = value;
134 },),
135 SwitchListTile(
136 title: Text(localizations.exportPdfExportData),
137 value: pdfExportSettings.exportData,
138 onChanged: (value) {
139 pdfExportSettings.exportData = value;
140 },),
141 if (pdfExportSettings.exportData)
142 Column(
143 children: [
144 NumberInputListTile(
145 value: pdfExportSettings.headerHeight,
146 label: localizations.exportPdfHeaderHeight,
147 onParsableSubmit: (value) {
148 pdfExportSettings.headerHeight = value;
149 },
150 ),
151 NumberInputListTile(
152 value: pdfExportSettings.cellHeight,
153 label: localizations.exportPdfCellHeight,
154 onParsableSubmit: (value) {
155 pdfExportSettings.cellHeight = value;
156 },
157 ),
158 NumberInputListTile(
159 value: pdfExportSettings.headerFontSize,
160 label: localizations.exportPdfHeaderFontSize,
161 onParsableSubmit: (value) {
162 pdfExportSettings.headerFontSize = value;
163 },
164 ),
165 NumberInputListTile(
166 value: pdfExportSettings.cellFontSize,
167 label: localizations.exportPdfCellFontSize,
168 onParsableSubmit: (value) {
169 pdfExportSettings.cellFontSize = value;
170 },
171 ),
172 ],
173 ),
174 ],
175 ),
176 ),
177 ActiveExportFieldCustomization(
178 format: settings.exportFormat,
179 ),
180 ],
181 ),
182 ),),
183 persistentFooterButtons: const [
184 ExportButton(share: true),
185 ExportButton(share: false),
186 ImportButton(),
187 ],
188 );
189 }
190}