|
1 | 1 | import 'dart:io'; |
| 2 | +import 'dart:math'; |
2 | 3 |
|
| 4 | +import 'package:dipantau_desktop_client/core/util/enum/global_variable.dart'; |
3 | 5 | import 'package:dipantau_desktop_client/core/util/helper.dart'; |
| 6 | +import 'package:dipantau_desktop_client/core/util/shared_preferences_manager.dart'; |
4 | 7 | import 'package:dipantau_desktop_client/feature/presentation/page/splash/splash_page.dart'; |
5 | 8 | import 'package:dipantau_desktop_client/injection_container.dart'; |
6 | 9 | import 'package:easy_localization/easy_localization.dart'; |
7 | 10 | import 'package:flutter/material.dart'; |
| 11 | +import 'package:flutter/services.dart'; |
8 | 12 | import 'package:go_router/go_router.dart'; |
9 | 13 | import 'package:path_provider/path_provider.dart'; |
10 | 14 |
|
@@ -182,4 +186,27 @@ class WidgetHelper { |
182 | 186 | }, |
183 | 187 | ); |
184 | 188 | } |
| 189 | + |
| 190 | + Future<File> getImageFileFromAssets(String path) async { |
| 191 | + final byteData = await rootBundle.load(path); |
| 192 | + |
| 193 | + final directoryPath = await getDirectoryApp('screenshot'); |
| 194 | + var userId = sharedPreferencesManager.getString(SharedPreferencesManager.keyUserId) ?? ''; |
| 195 | + final random = Random(); |
| 196 | + if (userId.isEmpty) { |
| 197 | + userId = random.nextInt(100).toString(); |
| 198 | + } |
| 199 | + final strRandomNumber = random.nextInt(100).toString(); |
| 200 | + |
| 201 | + final now = DateTime.now(); |
| 202 | + final timeInMillis = now.millisecondsSinceEpoch; |
| 203 | + final timeInSeconds = Duration(milliseconds: timeInMillis).inSeconds; |
| 204 | + final pathString = '${timeInSeconds}_${userId}_${strRandomNumber}_1.jpg'; |
| 205 | + final file = File('$directoryPath/$pathString'); |
| 206 | + |
| 207 | + await file.create(recursive: true); |
| 208 | + await file.writeAsBytes(byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes)); |
| 209 | + |
| 210 | + return file; |
| 211 | + } |
185 | 212 | } |
0 commit comments