-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
recoding app version 2: done rest api
- Loading branch information
1 parent
1f31b33
commit 27313fc
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |