Table of Contents
Flutter Upload Picture :
Flutter add impression or file is a critical element in couple of app’s so i would like to make it uncomplicated for you by this vlog. In our previous vlogs we have observed many api ask for implementations.
By making use of this tutorial you can upload any file like impression, audio, movie so on..
https://www.youtube.com/view?v=5cKmqkO–oo
pubspec.yaml :
Incorporate the necessary dependencies like dio and file picker.
dependencies: flutter: sdk: flutter dio: ^4..6 file_picker: ^5.2.2
key.dart :
Entire code for file upload in flutter application.
import 'dart:io' import 'package:file_picker/file_picker.dart' import 'package:dio/dio.dart' import 'package:flutter/substance.dart' import 'package:path_provider/route_supplier.dart' void major() runApp(MyApp()) class MyApp extends StatelessWidget const MyApp(Crucial? critical) : tremendous(essential: critical) @override Widget create(BuildContext context) return MaterialApp( residence: Scaffold( system: Center( child: Column( mainAxisAlignment: MainAxisAlignment.heart, little ones: [ TextButton( onPressed: () uploadFile(); , child: const Text("Upload File")), ], ), ), ), ) Potential uploadFile() async var dio = Dio() FilePickerResult? final result = await FilePicker.platform.pickFiles() if(result!=null) File file = File(consequence.documents.solitary.path ?? " ") String filename = file.path.split('/').final String filepath = file.path FormData facts = FormData.fromMap( 'key': 'your key here', 'image': await MultipartFile.fromFile(filepath, filename: filename) ) var response = await dio.put up("https://api.imgbb.com/1/upload", information: information, onSendProgress:(int sent, int total) print('$despatched, $total') ) print(reaction.data) else print("End result is null")