multipart_request 0.1.1 copy "multipart_request: ^0.1.1" to clipboard
multipart_request: ^0.1.1 copied to clipboard

outdated

A flutter plugin to send a multipart request and get stream of progress.

example/lib/main.dart

import 'dart:io';

import 'package:flutter/material.dart';

import 'package:image_picker/image_picker.dart';
import 'package:multipart_request/multipart_request.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String imagePath = "";

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              FlatButton(
                child: Text("Pick an image"),
                onPressed: () async {
                  File image =
                      await ImagePicker.pickImage(source: ImageSource.gallery);
                  imagePath = image.path;
                },
              ),
              FlatButton(
                child: Text("Call multipart request"),
                onPressed: () {
                  sendRequest();
                },
              ),
            ],
          ),
        ),
      ),
    );
  }

  void sendRequest() {
    var request = MultipartRequest();

    request.setUrl("https://b804ca15.ngrok.io/images");
    request.addFile("image", imagePath);

    Response response = request.send();

    response.onError = () {
      print("Error");
    };

    response.onComplete = (response) {
      print(response);
    };

    response.progress.listen((int progress) {
      print("progress from response object " + progress.toString());
    });
  }
}
16
likes
0
pub points
72%
popularity

Publisher

verified publisheraawaz.dev

A flutter plugin to send a multipart request and get stream of progress.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on multipart_request