Flutter dio add a picture or file

Flutter Add Picture :

Flutter add picture or file is a key side in few app’s so i wish to make it simple for you thru this vlog. In our earlier vlogs we now have seen varied api request implementations.

Api’s play a key position in app performance by offering dynamic options which gives varied performance to the person.

For instance offering listing of merchandise which change dynamically, buy, audio & video information, social networking all of those works on api implementation.

On this tutorial we now have made use of a 3rd get together web site for explaining you ways the picture add course of is completed.It is extremely sensible simply you have to change the api and observe this course of.

By utilizing this tutorial you may add any file like picture, audio, video so on..



pubspec.yaml :

Add the required dependencies to carry out flutter picture add like dio and file picker.

    sdk: flutter
  dio: ^4.0.6
  file_picker: ^5.2.2


essential.dart :

Full code for file add in flutter app.



import 'dart:io';
import 'package deal:file_picker/file_picker.dart';
import 'package deal:dio/dio.dart';
import 'package deal:flutter/materials.dart';
import 'package deal:path_provider/path_provider.dart';

void essential() {

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : tremendous(key: key);

  Widget construct(BuildContext context) {
    return MaterialApp(
      house: Scaffold(
        physique: Middle(
          youngster: Column(
            mainAxisAlignment: MainAxisAlignment.middle,
            youngsters: [
                  onPressed: () {
                  child: const Text("Upload File")),

Future uploadFile() async {
  var dio = Dio();

  FilePickerResult? consequence = await FilePicker.platform.pickFiles();

    File file = File(consequence.information.single.path ?? " ");

    String filename = file.path.cut up('/').final;

    String filepath = file.path;

  FormData knowledge = FormData.fromMap({
    'key': 'your key right here',
    'picture': await MultipartFile.fromFile(filepath, filename: filename)

  var response = await dio.submit("https://api.imgbb.com/1/add", knowledge: knowledge,
  onSendProgress:(int despatched, int complete){
    print('$despatched, $complete');
  } );


  }else {
    print("Result's null");


Output :

If you’re having any question on this tutorial on flutter picture add do tell us within the remark part under.Should you like this tutorial do like and share us for extra fascinating updates.


Related Articles


Please enter your comment!
Please enter your name here

Latest Articles