With Dart / Flutter I choose photos from the gallery. How can I send my selected photo to the c# api? I have no idea how to send the selected image to the api. Thanks for help
Api will use the selected photo according to the function of the application. The part I don't understand is; How can I send the photo to api?
Here is my code:
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
void main() {
runApp(new MaterialApp(
title: "Ymgk Proje",
home: LandingScreen(),
));
}
class LandingScreen extends StatefulWidget {
@override
_LandingScreenState createState() => _LandingScreenState();
}
class _LandingScreenState extends State<LandingScreen> {
File imageFile;
_openGallary(BuildContext context) async {
var picture =
imageFile = await ImagePicker.pickImage(source: ImageSource.gallery);
this.setState(() {
imageFile = picture;
});
Navigator.of(context).pop();
}
_openCamera(BuildContext context) async {
var picture =
imageFile = await ImagePicker.pickImage(source: ImageSource.camera);
this.setState(() {
imageFile = picture;
});
Navigator.of(context).pop();
}
Future<void> _showChoiceDiolog(BuildContext context) {
return showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text("Ekleme yönteminizi seçiniz."),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
GestureDetector(
child: Text("Galeri"),
onTap: () {
_openGallary(context);
},
),
Padding(padding: EdgeInsets.all(8.0)),
GestureDetector(
child: Text("Kamera"),
onTap: () {
_openCamera(context);
},
)
],
),
),
);
});
}
Widget _decideImageView() {
if (imageFile == null) {
return Text("Henüz resim Seçilmedi!");
} else {
return Image.file(imageFile, width: 400, height: 400);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("YMGK2"),
centerTitle: mounted,
),
body: Container(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
_decideImageView(),
RaisedButton(
onPressed: () {
_showChoiceDiolog(context);
},
child: Text("Resim Ekle"),
)
],
),
),
),
);
}
}