|
|
|
@ -1,4 +1,6 @@
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:file_picker/file_picker.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:practice_engine/practice_engine.dart';
|
|
|
|
import 'package:practice_engine/practice_engine.dart';
|
|
|
|
@ -271,6 +273,30 @@ class _DeckImportScreenState extends State<DeckImportScreen> {
|
|
|
|
showTopSnackBar(context, message: 'JSON copied to clipboard');
|
|
|
|
showTopSnackBar(context, message: 'JSON copied to clipboard');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> _pickJsonFile() async {
|
|
|
|
|
|
|
|
final result = await FilePicker.platform.pickFiles(
|
|
|
|
|
|
|
|
type: FileType.custom,
|
|
|
|
|
|
|
|
allowedExtensions: ['json'],
|
|
|
|
|
|
|
|
withData: true,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
if (result == null || result.files.isEmpty || !mounted) return;
|
|
|
|
|
|
|
|
final file = result.files.single;
|
|
|
|
|
|
|
|
if (file.bytes == null) {
|
|
|
|
|
|
|
|
if (mounted) {
|
|
|
|
|
|
|
|
showTopSnackBar(context, message: 'Could not read file content');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
final text = utf8.decode(file.bytes!);
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
|
|
|
|
_errorMessage = null;
|
|
|
|
|
|
|
|
_jsonController.text = text;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
if (mounted) {
|
|
|
|
|
|
|
|
showTopSnackBar(context, message: 'File loaded');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
return Scaffold(
|
|
|
|
@ -393,6 +419,11 @@ class _DeckImportScreenState extends State<DeckImportScreen> {
|
|
|
|
Row(
|
|
|
|
Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
children: [
|
|
|
|
|
|
|
|
TextButton.icon(
|
|
|
|
|
|
|
|
onPressed: _pickJsonFile,
|
|
|
|
|
|
|
|
icon: const Icon(Icons.folder_open),
|
|
|
|
|
|
|
|
label: const Text('Select file'),
|
|
|
|
|
|
|
|
),
|
|
|
|
TextButton.icon(
|
|
|
|
TextButton.icon(
|
|
|
|
onPressed: _loadSampleDeck,
|
|
|
|
onPressed: _loadSampleDeck,
|
|
|
|
icon: const Icon(Icons.description),
|
|
|
|
icon: const Icon(Icons.description),
|
|
|
|
|