'Flutter How to pick an image and convert BASE64 string in web

Actually I'm very new in Flutter-Dart. And I'm writing an web app. So I should pick images from file path in web. And I should convert the image to base64 code. because I will add the image to my PHP server with my php codes. PHP code is ready. but I don't know a lot of information about pick images and convert base64. Can anybody help me.



Solution 1:[1]

Add file_picker: ^4.3.0 to pubspec.yaml and try this:

void pickFile(){
    FilePickerResult? result = await FilePicker.platform.pickFiles(
      type: FileType.custom,
    );
    if (result != null) {
      Uint8List? file = result.files.first.bytes!;
      final x = base64Encode(file);
      //do what you want with x.
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Josteve