add android fick picker
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:file_picker/file_picker.dart';
|
import 'package:file_picker/file_picker.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import '../../main.dart';
|
import '../../main.dart';
|
||||||
@@ -69,18 +71,54 @@ class _MIHProfilePictureState extends State<MIHProfilePicture> {
|
|||||||
type: FileType.custom,
|
type: FileType.custom,
|
||||||
allowedExtensions: ['jpg', 'png'],
|
allowedExtensions: ['jpg', 'png'],
|
||||||
);
|
);
|
||||||
if (result == null) return;
|
// print(
|
||||||
final selectedFile = result.files.first;
|
// "Platform: ${MzanziInnovationHub.of(context)!.theme.getPlatform()}");
|
||||||
setState(() {
|
if (MzanziInnovationHub.of(context)!.theme.getPlatform() ==
|
||||||
widget.onChange(selectedFile);
|
"Web") {
|
||||||
widget.proPic = selectedFile;
|
if (result == null) return;
|
||||||
//print("MIH Profile Picture: ${widget.proPic}");
|
final selectedFile = result.files.first;
|
||||||
propicPreview = MemoryImage(widget.proPic!.bytes!);
|
setState(() {
|
||||||
});
|
widget.onChange(selectedFile);
|
||||||
|
widget.proPic = selectedFile;
|
||||||
|
//print("MIH Profile Picture: ${widget.proPic}");
|
||||||
|
propicPreview = MemoryImage(widget.proPic!.bytes!);
|
||||||
|
});
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
widget.proPicController.text = selectedFile.name;
|
widget.proPicController.text = selectedFile.name;
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
// print(
|
||||||
|
// "================\nHere for Android\n========================");
|
||||||
|
if (result != null) {
|
||||||
|
// print("here 1");
|
||||||
|
File file = File(result.files.single.path!);
|
||||||
|
PlatformFile? androidFile = PlatformFile(
|
||||||
|
path: file.path,
|
||||||
|
name: file.path.split('/').last,
|
||||||
|
size: file.lengthSync(),
|
||||||
|
bytes: await file.readAsBytes(), // Read file bytes
|
||||||
|
//extension: fileExtension,
|
||||||
|
);
|
||||||
|
// print("here 2");
|
||||||
|
setState(() {
|
||||||
|
// print("here 3");
|
||||||
|
widget.onChange(androidFile);
|
||||||
|
// print("here 4");
|
||||||
|
widget.proPic = androidFile;
|
||||||
|
// print("here 5");
|
||||||
|
//print("MIH Profile Picture: ${widget.proPic}");
|
||||||
|
//print("bytes: ${widget.proPic!.bytes!}");
|
||||||
|
propicPreview = FileImage(file);
|
||||||
|
});
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
widget.proPicController.text = widget.proPic!.name;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// User canceled the picker
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
icon: const Icon(Icons.edit),
|
icon: const Icon(Icons.edit),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user