Skip to content

Commit

Permalink
recoding app version 2: done rest api
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunhThanhDe committed Sep 19, 2022
1 parent 1f31b33 commit 27313fc
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions lib/api/uploadFile.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

Future<bool> uploadFile(BuildContext context, File file) async {
showDialog(
// // The user CANNOT close this dialog by pressing outsite it
barrierDismissible: false,
context: context,
builder: (_) {
return Dialog(
// The background color
backgroundColor: Colors.black,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 20),
child: Column(
mainAxisSize: MainAxisSize.min,
children: const [
// The loading indicator
CircularProgressIndicator(
color: Colors.white,
),
SizedBox(
height: 15,
),
// Some text
Text(
'Uploading...',
style: TextStyle(color: Colors.white),
)
],
),
),
);
});
var request = http.MultipartRequest(
'POST', Uri.parse('http://192.168.1.64:5000/uploadFile'));
request.files.add(await http.MultipartFile.fromPath('file', file.path));
var response = await request.send();

// Close the dialog programmatically
if (response.statusCode == 200) {
return true;
} else {
return false;
}
}

0 comments on commit 27313fc

Please sign in to comment.