Skip to content

Commit

Permalink
feat: share dan download done
Browse files Browse the repository at this point in the history
  • Loading branch information
fleetimee committed Nov 30, 2022
1 parent 5f4399c commit 51fb7e6
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 54 deletions.
6 changes: 3 additions & 3 deletions lib/app/common/constant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// const baseUrl = 'http://127.0.0.1:3000/api/v1/';

// For mobile based
const baseUrl = 'http://10.0.2.2:3000/api/v1/';
// const baseUrl = 'http://10.0.2.2:3000/api/v1/';

// check if platform is web

Expand All @@ -16,8 +16,8 @@ const baseUrl = 'http://10.0.2.2:3000/api/v1/';
// const baseUrl =
// 'https://9bf0-2001-448a-4049-68c4-c80c-e641-b21d-cb5c.ap.ngrok.io/api/v1/';

// const baseUrl =
// 'https://number-41-bagooska-the-terribly-tired-tapir-3.fleetimee.repl.co/api/v1/';
const baseUrl =
'https://number-41-bagooska-the-terribly-tired-tapir.fleetimee.repl.co/api/v1/';

// List debitur field string
const field =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
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
Expand Down Expand Up @@ -32,4 +39,40 @@ class GalleryImageController extends GetxController {
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,
),
);
}
}
110 changes: 63 additions & 47 deletions lib/app/modules/gallery_image/views/gallery_image_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';
import 'package:image_downloader/image_downloader.dart';
import 'package:intl/intl.dart';
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
import 'package:photo_view/photo_view.dart';
Expand Down Expand Up @@ -86,40 +85,43 @@ class GalleryImageView extends GetView<GalleryImageController> {
titleText: controller.imageList[index].keterangan,
subTitleText: DateFormat('dd MMMM yyyy')
.format(controller.imageList[index].createdDate!),
icon: GFButton(
onPressed: () async {
try {
var imageId = await ImageDownloader.downloadImage(
controller.imageList[index].file!,
);
if (imageId == null) {
return;
}
var filename =
await ImageDownloader.findName(imageId);
var path =
await ImageDownloader.findPath(imageId);
var size =
await ImageDownloader.findByteSize(imageId);
var mimeType =
await ImageDownloader.findMimeType(imageId);
Get.snackbar(
'Downloaded',
'Image downloaded to $path',
snackPosition: SnackPosition.TOP,
icon: const Icon(Icons.download_done),
colorText: Colors.white,
backgroundColor: Colors.green,
);
} on Exception catch (error) {
Get.snackbar('Error', error.toString());
}
},
text: 'Download',
color: GFColors.SUCCESS,
type: GFButtonType.solid,
size: GFSize.LARGE,
shape: GFButtonShape.pills,
icon: Row(
children: [
GFButton(
onPressed: () {
controller.shareNetworkImage(
controller.imageList[index].file!,
controller.imageList[index].keterangan!,
);
},
text: 'Share',
color: GFColors.INFO,
type: GFButtonType.solid,
size: GFSize.LARGE,
shape: GFButtonShape.pills,
),
const SizedBox(
width: 5,
),
GFButton(
onPressed: () async {
try {
controller.downloadNetworkImage(
controller.imageList[index].file!,
controller.imageList[index].keterangan!,
'AKM-${data.peminjam1}',
);
} on Exception catch (error) {
Get.snackbar('Error', error.toString());
}
},
text: 'Download',
color: GFColors.SUCCESS,
type: GFButtonType.solid,
size: GFSize.LARGE,
shape: GFButtonShape.pills,
),
],
),
),
);
Expand All @@ -143,8 +145,19 @@ class GalleryImageView extends GetView<GalleryImageController> {
return GestureDetector(
onTap: () {
showMaterialModalBottomSheet(
backgroundColor: Colors.transparent,
context: context,
builder: (context) => PhotoViewGallery.builder(
backgroundDecoration: const BoxDecoration(
color: Colors.black,
),
allowImplicitScrolling: true,
enableRotation: true,
loadingBuilder: (context, event) => const Center(
child: CircularProgressIndicator(
color: Colors.red,
),
),
pageController: PageController(
initialPage: index,
),
Expand All @@ -163,18 +176,21 @@ class GalleryImageView extends GetView<GalleryImageController> {
),
);
},
loadingBuilder: (context, event) => Center(
child: SizedBox(
width: 20.0,
height: 20.0,
child: CircularProgressIndicator(
value: event == null
? 0
: event.cumulativeBytesLoaded /
event.expectedTotalBytes!,
),
),
),
// loadingBuilder: (context, event) => Container(
// color: Colors.grey[200],
// child: Center(
// child: SizedBox(
// width: 20.0,
// height: 20.0,
// child: CircularProgressIndicator(
// value: event == null
// ? 0
// : event.cumulativeBytesLoaded /
// event.expectedTotalBytes!,
// ),
// ),
// ),
// ),
),
);
},
Expand Down
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import device_info_plus
import geolocator_apple
import path_provider_macos
import printing
import share_plus
import sqflite
import url_launcher_macos

Expand All @@ -17,6 +18,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
GeolocatorPlugin.register(with: registry.registrar(forPlugin: "GeolocatorPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
PrintingPlugin.register(with: registry.registrar(forPlugin: "PrintingPlugin"))
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
}
41 changes: 38 additions & 3 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ packages:
name: cross_file
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.3+1"
version: "0.3.3+2"
crypto:
dependency: transitive
description:
Expand Down Expand Up @@ -255,6 +255,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "7.0.0"
dio:
dependency: "direct main"
description:
name: dio
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.6"
double_back_to_close_app:
dependency: "direct main"
description:
Expand Down Expand Up @@ -605,6 +612,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "8.4.0"
gallery_saver:
dependency: "direct main"
description:
name: gallery_saver
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.2"
geocoding:
dependency: "direct main"
description:
Expand Down Expand Up @@ -878,6 +892,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
mime:
dependency: transitive
description:
name: mime
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3"
modal_bottom_sheet:
dependency: "direct main"
description:
Expand Down Expand Up @@ -963,7 +984,7 @@ packages:
source: hosted
version: "1.0.1"
path_provider:
dependency: transitive
dependency: "direct main"
description:
name: path_provider
url: "https://pub.dartlang.org"
Expand Down Expand Up @@ -1195,6 +1216,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3+1"
share_plus:
dependency: "direct main"
description:
name: share_plus
url: "https://pub.dartlang.org"
source: hosted
version: "6.3.0"
share_plus_platform_interface:
dependency: transitive
description:
name: share_plus_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.0"
shimmer:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1353,7 +1388,7 @@ packages:
name: url_launcher_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.1.1"
url_launcher_web:
dependency: transitive
description:
Expand Down
6 changes: 5 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: akm
version: 1.0.6+14
version: 1.0.7+15
publish_to: none
description: Mobile app untuk Analisis Kredit Mikro built with Flutter and NodeJS.
environment:
Expand All @@ -16,6 +16,7 @@ dependencies:
ref: master
data_table_2: ^2.3.8
device_info_plus: ^8.0.0
dio: ^4.0.6
double_back_to_close_app: ^2.1.0
empty_widget: ^0.0.5
extended_masked_text: ^2.3.1
Expand Down Expand Up @@ -54,6 +55,7 @@ dependencies:
ref: main
form_builder_image_picker: ^3.1.0
form_builder_validators: ^8.4.0
gallery_saver: ^2.3.2
geocoding: ^2.0.5
geolocator: ^9.0.2
get: 4.6.5
Expand All @@ -72,6 +74,7 @@ dependencies:
numerus: ^2.0.0
open_filex: ^4.3.1
open_street_map_search_and_pick: ^0.0.15
path_provider: ^2.0.11
pdf: ^3.8.4
photo_view: ^0.14.0
printing: ^5.9.3
Expand All @@ -80,6 +83,7 @@ dependencies:
url: https://github.com/Codelessly/ResponsiveFramework
ref: master
scaffold_gradient_background: ^1.0.3+1
share_plus: ^6.3.0
shimmer: ^2.0.0
terbilang_id: ^0.1.0
url_launcher: ^6.1.7
Expand Down
3 changes: 3 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <geolocator_windows/geolocator_windows.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <printing/printing_plugin.h>
#include <share_plus/share_plus_windows_plugin_c_api.h>
#include <url_launcher_windows/url_launcher_windows.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
Expand All @@ -18,6 +19,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
PrintingPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PrintingPlugin"));
SharePlusWindowsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("SharePlusWindowsPluginCApi"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}
1 change: 1 addition & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
geolocator_windows
permission_handler_windows
printing
share_plus
url_launcher_windows
)

Expand Down

0 comments on commit 51fb7e6

Please sign in to comment.