Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!
We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!
Learn from Guru Rajesh Kumar and double your salary in just one year.
Error:
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FormatException: Unexpected character (at character 1)
E/flutter ( 3050): <!DOCTYPE html>
E/flutter ( 3050): ^
E/flutter ( 3050):
E/flutter ( 3050): #0 _ChunkedJsonParser.fail (dart:convert-patch/convert_patch.dart:1383:5)
E/flutter ( 3050): #1 _ChunkedJsonParser.parseNumber (dart:convert-patch/convert_patch.dart:1250:9)
E/flutter ( 3050): #2 _ChunkedJsonParser.parse (dart:convert-patch/convert_patch.dart:915:22)
E/flutter ( 3050): #3 _parseJson (dart:convert-patch/convert_patch.dart:35:10)
E/flutter ( 3050): #4 JsonDecoder.convert (dart:convert/json.dart:612:36)
E/flutter ( 3050): #5 JsonCodec.decode (dart:convert/json.dart:216:41)
E/flutter ( 3050): #6 _MedicalRegistrationState.fetch_council
medical_registration_edit.dart:26
E/flutter ( 3050): <asynchronous suspension>
E/flutter ( 3050):
Solution:
change the code to this
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<void> uploadImage(String title, File file) async { | |
var request =await http.MultipartRequest("POST", Uri.parse("https://api.imgur.com/3/image")); | |
request.fields["title"] = title; | |
request.headers["Authorization"] = ""; | |
var picture = http.MultipartFile.fromBytes('image', (await rootBundle.load('assets/testimage.png')).buffer.asUint8List(), | |
filename: 'image.png'); | |
request.files.add(picture); | |
var response = await request.send(); | |
var responseData = await response.stream.toBytes(); | |
var result = String.fromCharCodes(responseData); | |
print(result); | |
} |
Use await change code from
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final File? image = ImagePicker.pickImage(source: ImageSource.gallery) as File?; |
TO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final XFile? image = await ImagePicker().pickImage(source: ImageSource.gallery); |
Check documentation https://pub.dev/packages/image_picker