how to access file path for the image in the app, lets say i upload the image to the app, and want to use same image for editing, it get this error, how to solve it? this is my code after selecting an image from camera or gallery, i declared two var for display and one for supposed to edit image
ElevatedButton(
onPressed: ()async {
// call dialog and get value "camera" or "galery"
final type = await _settingModalBottomSheet(context);
if(type != null){
// call image pikcer
final pickedFile = await _openImagePicker(type);
if(pickedFile !=null){
final directory = (await getExternalStorageDirectory())!.path;
await Directory('$directory/$_image').create(recursive: true);
final fullPath =
'$directory/$_image/${DateTime.now().millisecondsSinceEpoch}.png';
// set here
setState(()
{
_image = pickedFile;
// Uint8List bytes = pickedFile.readAsBytesSync();
// var simage = ImageProvider;
// image= simage;
// List<int> imageBase64 = _image!.readAsBytesSync();
// String imageAsString = base64Encode(imageBase64);
// Uint8List uint8list = base64.decode(imageAsString);
// image = Image.memory(uint8list);
image = fullPath;
});
}
}
},
child: const Text('Select An Image'),
)
this is my code for edit paint image
class ImagePainterExample extends StatefulWidget {
const ImagePainterExample({super.key, required this.image});
final String? image;
@override
// ignore: library_private_types_in_public_api
_ImagePainterExampleState createState() => _ImagePainterExampleState(image_1: image);
}
class _ImagePainterExampleState extends State<ImagePainterExample> {
final _imageKey = GlobalKey<ImagePainterState>();
final _key = GlobalKey<ScaffoldState>();
_ImagePainterExampleState({required this.image_1});
String? image_1;
// void saveImage() async {
// final image = await _imageKey.currentState?.exportImage();
// final directory = (await getApplicationDocumentsDirectory()).path;
// await Directory('$directory/sample').create(recursive: true);
// final fullPath =
// '$directory/sample/${DateTime.now().millisecondsSinceEpoch}.png';
// final imgFile = File(fullPath);
// imgFile.writeAsBytesSync(image!);
// await GallerySaver.saveImage(fullPath, toDcim: true);
// // ignore: use_build_context_synchronously
// ScaffoldMessenger.of(context).showSnackBar(
// SnackBar(
// backgroundColor: Colors.grey[700],
// padding: const EdgeInsets.only(left: 10),
// content: Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: [
// const Text("Image Exported successfully.",
// style: TextStyle(color: Colors.white)),
// TextButton(
// onPressed: () => OpenFile.open(fullPath),
// child: Text(
// "Open",
// style: TextStyle(
// color: Colors.blue[200],
// ),
// ),
// )
// ],
// ),
// ),
// );
// }
@override
Widget build(BuildContext context) {
return Scaffold(
key: _key,
appBar: AppBar(
title: const Text("Image Painter Example"),
// actions: [
// IconButton(
// icon: const Icon(Icons.save_alt),
// onPressed: saveImage,
// )
// ],
),
body: ImagePainter.asset(
image_1!,
key: _imageKey,
scalable: true,
initialStrokeWidth: 2,
initialColor: Colors.green,
initialPaintMode: PaintMode.line,
placeholderWidget: Text (image_1!),
),
);
}
}
how to solve this?