Skip to content

Commit

Permalink
Fix issues with saving images
Browse files Browse the repository at this point in the history
  • Loading branch information
Kara-Zor-El committed Nov 23, 2023
1 parent 0fedf32 commit c72edd3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
18 changes: 16 additions & 2 deletions lib/screens/EditScreen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// the purpose of this file is to allow you to edit a entry in your library

import 'dart:convert';

import 'package:auto_size_text/auto_size_text.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
Expand All @@ -22,6 +24,8 @@ import 'package:image_picker/image_picker.dart';
import 'package:built_collection/built_collection.dart';
import 'package:flutter/cupertino.dart';
import 'dart:io';
import 'package:path_provider/path_provider.dart';
import 'package:path/path.dart' as p;

class EditScreen extends StatefulWidget {
bool offline;
Expand Down Expand Up @@ -106,11 +110,21 @@ class _EditScreenState extends State<EditScreen> {
Future<void> _pickImage() async {
final pickedFile = await picker.pickImage(source: ImageSource.gallery);
if (pickedFile != null) {
entry.imagePath = pickedFile.path;
setState(() {});
File image = File(pickedFile.path);
saveImageToDocumentsDirectory(image);
}
}

Future saveImageToDocumentsDirectory(File image) async {
final documentsDir = await getApplicationDocumentsDirectory();
final fileName =
p.basename(image.path); // Use path package to get the file name
final savedImage = await image.copy('${documentsDir.path}/$fileName');
setState(() {
widget.entry.imagePath = savedImage.path;
});
}

bool isTablet(BuildContext context) {
final shortestSide = MediaQuery.of(context).size.shortestSide;

Expand Down
14 changes: 13 additions & 1 deletion lib/widgets/roundedImageWithShadow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,19 @@ class _RoundedImageWithShadowState extends State<RoundedImageWithShadow> {
);
},
)
: Image.file(File(widget.imageUrl), fit: BoxFit.cover),
: LayoutBuilder(
builder: (context, constraints) {
imageSize = constraints.biggest;
return Image.file(
File(widget.imageUrl),
fit: BoxFit.cover,
width: imageSize
?.width, // Use the width from the imageSize
height: imageSize
?.height, // Use the height from the imageSize
);
},
),
),
),
);
Expand Down

0 comments on commit c72edd3

Please sign in to comment.