-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from fleetimee/upload_files
- Loading branch information
Showing
26 changed files
with
1,181 additions
and
732 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
Binary file not shown.
Binary file not shown.
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
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,74 @@ | ||
// 🎯 Dart imports: | ||
|
||
// 🐦 Flutter imports: | ||
|
||
// 📦 Package imports: | ||
import 'dart:convert'; | ||
|
||
import 'package:akm/app/common/constant.dart'; | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:http/http.dart' as http; | ||
|
||
// 🌎 Project imports: | ||
import 'package:akm/app/models/debitur_model/insight_debitur.model.dart'; | ||
|
||
class MediaProvider { | ||
final httpClient = http.Client(); | ||
|
||
Future<List<Upload>> fetchMedia(int id) async { | ||
try { | ||
final response = await httpClient.get( | ||
Uri.parse('${baseUrl}debiturs/$id/uploads/'), | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Accept': 'application/json' | ||
}, | ||
); | ||
debugPrint(response.body); | ||
|
||
if (response.statusCode == 200) { | ||
var data = jsonDecode(response.body); | ||
debugPrint(data.toString()); | ||
return (data as List).map((e) => Upload.fromJson(e)).toList(); | ||
} else { | ||
throw Exception('Failed to load data'); | ||
} | ||
} catch (e) { | ||
return Future.error(e); | ||
} | ||
} | ||
|
||
Future<Upload> saveMedia(int id, body) async { | ||
try { | ||
final response = http.MultipartRequest( | ||
'POST', | ||
Uri.parse('${baseUrl}debiturs/$id/uploads/'), | ||
) | ||
..headers.addAll( | ||
{ | ||
'Content-Type': 'application/json', | ||
'Accept': 'application/json', | ||
}, | ||
) | ||
..files.add(await http.MultipartFile.fromPath('file', body['file'])); | ||
|
||
response.fields.addAll( | ||
Map<String, String>.from(body), | ||
); | ||
|
||
var res = await response.send(); | ||
|
||
final resBody = await res.stream.bytesToString(); | ||
|
||
debugPrint(resBody); | ||
|
||
if (res.statusCode == 201) { | ||
return Upload.fromJson(jsonDecode(resBody)); | ||
} else { | ||
throw Exception('Failed to load data'); | ||
} | ||
} catch (e) { | ||
return Future.error(e); | ||
} | ||
} | ||
} |
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
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
12 changes: 12 additions & 0 deletions
12
lib/app/modules/gallery_image/bindings/gallery_image_binding.dart
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,12 @@ | ||
import 'package:get/get.dart'; | ||
|
||
import '../controllers/gallery_image_controller.dart'; | ||
|
||
class GalleryImageBinding extends Bindings { | ||
@override | ||
void dependencies() { | ||
Get.lazyPut<GalleryImageController>( | ||
() => GalleryImageController(), | ||
); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
lib/app/modules/gallery_image/controllers/gallery_image_controller.dart
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,78 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:akm/app/data/provider/media/save_mediaprovider.dart'; | ||
import 'package:akm/app/models/debitur_model/insight_debitur.model.dart'; | ||
import 'package:dio/dio.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:gallery_saver/gallery_saver.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:path_provider/path_provider.dart'; | ||
import 'package:share_plus/share_plus.dart'; | ||
|
||
class GalleryImageController extends GetxController { | ||
@override | ||
void onInit() { | ||
getImages(debiturId.id); | ||
super.onInit(); | ||
} | ||
|
||
var imageList = List<Upload>.empty(growable: true).obs; | ||
|
||
final isImageLoading = false.obs; | ||
|
||
final isImageListView = false.obs; | ||
|
||
final debiturId = Get.arguments; | ||
|
||
void getImages(int id) { | ||
try { | ||
isImageLoading(true); | ||
MediaProvider().fetchMedia(id).then((resp) { | ||
isImageLoading(false); | ||
imageList.addAll(resp); | ||
}, onError: (e) { | ||
isImageLoading(false); | ||
Get.snackbar('Error', e.toString()); | ||
}); | ||
} catch (e) { | ||
isImageLoading(false); | ||
Get.snackbar('Error', e.toString()); | ||
} | ||
} | ||
|
||
void shareNetworkImage(String url, String filename) async { | ||
Directory tempDir = await getTemporaryDirectory(); | ||
|
||
final path = tempDir.path; | ||
|
||
await Dio().download(url, '$path/$filename.jpg'); | ||
|
||
Share.shareFiles(['$path/$filename.jpg']); | ||
} | ||
|
||
void downloadNetworkImage( | ||
String url, String filename, String albumname) async { | ||
Directory tempDir = await getTemporaryDirectory(); | ||
|
||
final path = tempDir.path; | ||
|
||
await Dio().download( | ||
url, | ||
'$path/$filename.jpg', | ||
); | ||
|
||
GallerySaver.saveImage('$path/$filename.jpg', albumName: albumname); | ||
|
||
Get.snackbar( | ||
'Success', | ||
'Image saved', | ||
snackPosition: SnackPosition.BOTTOM, | ||
colorText: Colors.white, | ||
backgroundColor: Colors.green, | ||
icon: const Icon( | ||
Icons.check_circle, | ||
color: Colors.white, | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.
8b5203d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
infinite-impermanence – ./
infinite-impermanence-git-master-fleetime.vercel.app
infinite-impermanence.vercel.app
infinite-impermanence-fleetime.vercel.app
docs-akm.fleetime.my.id