diff options
Diffstat (limited to 'lib/views/file_info.dart')
-rw-r--r-- | lib/views/file_info.dart | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/lib/views/file_info.dart b/lib/views/file_info.dart new file mode 100644 index 0000000..e032716 --- /dev/null +++ b/lib/views/file_info.dart @@ -0,0 +1,103 @@ +import 'dart:io'; + +import 'package:flutter/material.dart'; + +import 'package:kulinar_app/constants.dart'; +import 'package:kulinar_app/util/file_handler.dart'; +import 'package:kulinar_app/widgets/error_widgets.dart'; + +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; + +class FileInfo extends StatefulWidget { + FileInfo({Key? key, required this.filePath}) : super(key: key); + + final String filePath; + + @override + _FileInfoState createState() => _FileInfoState(); +} + +class _FileInfoState extends State<FileInfo> { + @override + Widget build(BuildContext context) { + final File _file = File(widget.filePath.split(":")[1]); + + return Scaffold( + appBar: AppBar(title: Text(AppLocalizations.of(context)!.category9)), + body: FutureBuilder( + future: FileHandler.deserializeFileInformation(_file), + builder: (BuildContext context, AsyncSnapshot<Map<String, String>> snapshot) { + if (snapshot.connectionState != ConnectionState.done) return CircularProgressIndicator(); + if (snapshot.hasError || !snapshot.hasData) return UnknownError(); + + return _buildFileInfoTable(_getSortedSnapshotData(snapshot), _file); + }, + ), + ); + } + + String _localizeInfoField(BuildContext context, String field) { + switch (field) { + case "type": + return AppLocalizations.of(context)!.infoField1; + case "version": + return AppLocalizations.of(context)!.infoField2; + case "size": + return AppLocalizations.of(context)!.infoField3; + case "entries": + return AppLocalizations.of(context)!.infoField4; + default: + return AppLocalizations.of(context)!.unknown; + } + } + + List<TableRow> _getSortedSnapshotData(AsyncSnapshot<Map<String, String>> snapshot) { + List<TableRow> _children = []; + + snapshot.data!.forEach((key, value) { + _children.add( + TableRow( + children: [ + Padding( + padding: const EdgeInsets.only(right: 4.0), + child: Text(_localizeInfoField(context, key), style: cTableKeyStyle, textAlign: TextAlign.right), + ), + Padding( + padding: const EdgeInsets.only(left: 4.0), + child: Text(value, style: cTableValueStyle), + ), + ], + ), + ); + }); + + return _children; + } + + Widget _buildFileInfoTable(List<TableRow> children, File file) { + return Padding( + padding: const EdgeInsets.only(top: 16.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Table( + columnWidths: const <int, TableColumnWidth>{ + 0: FlexColumnWidth(), + 1: FlexColumnWidth(), + }, + children: children, + ), + Padding( + padding: const EdgeInsets.all(16.0), + child: ElevatedButton( + child: Text(AppLocalizations.of(context)!.option312, style: cOptionTextStyle.copyWith(color: cIconColor)), + onPressed: () { + FileHandler.deserializeFile(context, file); + }, + ), + ), + ], + ), + ); + } +} |