Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAINTROID-782 : Use file picker for choosing file saving location #106

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 61 additions & 8 deletions lib/ui/shared/dialogs/save_image_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';

import 'package:file_picker/file_picker.dart';
import 'package:paintroid/core/enums/image_format.dart';
import 'package:paintroid/core/models/image_meta_data.dart';
import 'package:paintroid/ui/shared/image_format_info.dart';
Expand All @@ -25,30 +25,40 @@ class SaveImageDialog extends StatefulWidget {

class _SaveImageDialogState extends State<SaveImageDialog> {
final TextEditingController nameFieldController = TextEditingController();
final TextEditingController savePathController =
TextEditingController(text: 'default/save/path');
final formKey = GlobalKey<FormState>(debugLabel: 'SaveImageDialog Form');
var selectedFormat = ImageFormat.jpg;
var imageQualityValue = 100;

@override
void initState() {
super.initState();

if (widget.savingProject) {
selectedFormat = ImageFormat.catrobatImage;
}
}

void _dismissDialogWithData() {
Future<void> _dismissDialogWithData() async {
final directoryPath = savePathController.text;
if (directoryPath.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Please specify a valid save path.')));
return;
}

late ImageMetaData data;
switch (selectedFormat) {
case ImageFormat.png:
data = PngMetaData(nameFieldController.text);
data = PngMetaData('$directoryPath/${nameFieldController.text}.png');
break;
case ImageFormat.jpg:
data = JpgMetaData(nameFieldController.text, imageQualityValue);
data = JpgMetaData(
'$directoryPath/${nameFieldController.text}.jpg', imageQualityValue);
break;
case ImageFormat.catrobatImage:
data = CatrobatImageMetaData(nameFieldController.text);
data = CatrobatImageMetaData(
'$directoryPath/${nameFieldController.text}.catrobat');
break;
}
Navigator.of(context).pop(data);
Expand Down Expand Up @@ -81,6 +91,14 @@ class _SaveImageDialogState extends State<SaveImageDialog> {
height: 16,
color: PaintroidTheme.of(context).onSurfaceVariantColor,
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: _savePathTextField,
),
Divider(
height: 16,
color: PaintroidTheme.of(context).onSurfaceVariantColor,
),
if (!widget.savingProject)
Column(
children: [
Expand Down Expand Up @@ -120,10 +138,10 @@ class _SaveImageDialogState extends State<SaveImageDialog> {

TextButton get _saveButton {
return TextButton(
onPressed: () {
onPressed: () async {
final formState = formKey.currentState;
if (formState != null && formState.validate()) {
_dismissDialogWithData();
await _dismissDialogWithData();
}
},
child: Text(
Expand Down Expand Up @@ -184,6 +202,41 @@ class _SaveImageDialogState extends State<SaveImageDialog> {
);
}

Padding get _savePathTextField {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: TextFormField(
controller: savePathController,
decoration: InputDecoration(
labelStyle: const TextStyle(fontWeight: FontWeight.bold),
hintText: 'Enter custom save path or use default',
suffixIcon: IconButton(
icon: const Icon(Icons.folder_open),
onPressed: () async {
final directoryPath = await FilePicker.platform.getDirectoryPath();
if (directoryPath != null) {
setState(() {
savePathController.text = directoryPath;
});
}
},
),
filled: true,
fillColor: PaintroidTheme.of(context).secondaryContainerColor,
border: const OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(8)),
),
),
validator: (path) {
if (path == null || path.isEmpty) {
return 'Please specify a save path';
}
return null;
},
),
);
}

Row get _imageFormatDropdown {
return Row(
children: [
Expand Down
10 changes: 5 additions & 5 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,10 @@ packages:
dependency: transitive
description:
name: ffi
sha256: "7bf0adc28a23d395f19f3f1eb21dd7cfd1dd9f8e1c50051c069122e6853bc878"
sha256: "16ed7b077ef01ad6170a3d0c57caa4a112a38d7a2ed5602e0aca9ca6f3d98da6"
url: "https://pub.dev"
source: hosted
version: "2.1.0"
version: "2.1.3"
file:
dependency: transitive
description:
Expand Down Expand Up @@ -1377,13 +1377,13 @@ packages:
source: hosted
version: "3.0.3"
win32:
dependency: transitive
dependency: "direct main"
description:
name: win32
sha256: "464f5674532865248444b4c3daca12bd9bf2d7c47f759ce2617986e7229494a8"
sha256: "84ba388638ed7a8cb3445a320c8273136ab2631cd5f2c57888335504ddab1bc2"
url: "https://pub.dev"
source: hosted
version: "5.2.0"
version: "5.8.0"
win32_registry:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ dependencies:
file_picker: ^5.3.1
floor: ^1.2.0
sqflite: ^2.3.0
win32: 5.8.0
colorpicker:
path: packages/colorpicker

Expand Down