Skip to content

Commit

Permalink
optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
leoafarias committed Apr 22, 2024
1 parent 7a51889 commit 8781aee
Show file tree
Hide file tree
Showing 49 changed files with 123 additions and 116 deletions.
2 changes: 1 addition & 1 deletion .flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"file_picker","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/file_picker-8.0.1/","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/path_provider_foundation-2.3.2/","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.3.5/","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"sqflite","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/sqflite-2.3.3/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"file_picker","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/file_picker-8.0.1/","native_build":true,"dependencies":["flutter_plugin_android_lifecycle"]},{"name":"flutter_plugin_android_lifecycle","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/flutter_plugin_android_lifecycle-2.0.19/","native_build":true,"dependencies":[]},{"name":"path_provider_android","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/path_provider_android-2.2.2/","native_build":true,"dependencies":[]},{"name":"shared_preferences_android","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/shared_preferences_android-2.2.1/","native_build":true,"dependencies":[]},{"name":"sqflite","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/sqflite-2.3.3/","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_foundation","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/path_provider_foundation-2.3.2/","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"screen_retriever","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/screen_retriever-0.1.9/","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.3.5/","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"sqflite","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/sqflite-2.3.3/","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"window_manager","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/window_manager-0.3.8/","native_build":true,"dependencies":["screen_retriever"]}],"linux":[{"name":"path_provider_linux","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/path_provider_linux-2.2.1/","native_build":false,"dependencies":[]},{"name":"screen_retriever","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/screen_retriever-0.1.9/","native_build":true,"dependencies":[]},{"name":"shared_preferences_linux","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/shared_preferences_linux-2.3.2/","native_build":false,"dependencies":["path_provider_linux"]},{"name":"window_manager","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/window_manager-0.3.8/","native_build":true,"dependencies":["screen_retriever"]}],"windows":[{"name":"path_provider_windows","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/path_provider_windows-2.2.1/","native_build":false,"dependencies":[]},{"name":"screen_retriever","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/screen_retriever-0.1.9/","native_build":true,"dependencies":[]},{"name":"shared_preferences_windows","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/shared_preferences_windows-2.3.2/","native_build":false,"dependencies":["path_provider_windows"]},{"name":"window_manager","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/window_manager-0.3.8/","native_build":true,"dependencies":["screen_retriever"]}],"web":[{"name":"file_picker","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/file_picker-8.0.1/","dependencies":[]},{"name":"shared_preferences_web","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/shared_preferences_web-2.3.0/","dependencies":[]}]},"dependencyGraph":[{"name":"file_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"screen_retriever","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_foundation","shared_preferences_linux","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_foundation","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]},{"name":"sqflite","dependencies":[]},{"name":"window_manager","dependencies":["screen_retriever"]}],"date_created":"2024-04-20 19:07:49.577497","version":"3.19.5"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"file_picker","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/file_picker-8.0.1/","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/path_provider_foundation-2.3.2/","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.3.5/","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"sqflite","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/sqflite-2.3.3/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"file_picker","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/file_picker-8.0.1/","native_build":true,"dependencies":["flutter_plugin_android_lifecycle"]},{"name":"flutter_plugin_android_lifecycle","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/flutter_plugin_android_lifecycle-2.0.19/","native_build":true,"dependencies":[]},{"name":"path_provider_android","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/path_provider_android-2.2.2/","native_build":true,"dependencies":[]},{"name":"shared_preferences_android","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/shared_preferences_android-2.2.1/","native_build":true,"dependencies":[]},{"name":"sqflite","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/sqflite-2.3.3/","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_foundation","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/path_provider_foundation-2.3.2/","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"screen_retriever","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/screen_retriever-0.1.9/","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.3.5/","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"sqflite","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/sqflite-2.3.3/","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"window_manager","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/window_manager-0.3.8/","native_build":true,"dependencies":["screen_retriever"]}],"linux":[{"name":"path_provider_linux","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/path_provider_linux-2.2.1/","native_build":false,"dependencies":[]},{"name":"screen_retriever","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/screen_retriever-0.1.9/","native_build":true,"dependencies":[]},{"name":"shared_preferences_linux","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/shared_preferences_linux-2.3.2/","native_build":false,"dependencies":["path_provider_linux"]},{"name":"window_manager","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/window_manager-0.3.8/","native_build":true,"dependencies":["screen_retriever"]}],"windows":[{"name":"path_provider_windows","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/path_provider_windows-2.2.1/","native_build":false,"dependencies":[]},{"name":"screen_retriever","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/screen_retriever-0.1.9/","native_build":true,"dependencies":[]},{"name":"shared_preferences_windows","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/shared_preferences_windows-2.3.2/","native_build":false,"dependencies":["path_provider_windows"]},{"name":"window_manager","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/window_manager-0.3.8/","native_build":true,"dependencies":["screen_retriever"]}],"web":[{"name":"file_picker","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/file_picker-8.0.1/","dependencies":[]},{"name":"shared_preferences_web","path":"/Users/leofarias/.pub-cache/hosted/pub.dev/shared_preferences_web-2.3.0/","dependencies":[]}]},"dependencyGraph":[{"name":"file_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"screen_retriever","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_foundation","shared_preferences_linux","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_foundation","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]},{"name":"sqflite","dependencies":[]},{"name":"window_manager","dependencies":["screen_retriever"]}],"date_created":"2024-04-22 16:36:23.854018","version":"3.19.5"}
69 changes: 1 addition & 68 deletions example/assets/assets.json

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/assets/images/thumb_1104088810.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed example/assets/images/thumb_1104088810_low.png
Binary file not shown.
Binary file added example/assets/images/thumb_1233812412.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed example/assets/images/thumb_1233812412_low.png
Binary file not shown.
Binary file added example/assets/images/thumb_1251011791.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed example/assets/images/thumb_1251011791_low.png
Binary file not shown.
Binary file added example/assets/images/thumb_1260043079.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed example/assets/images/thumb_1260043079_low.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added example/assets/images/thumb_1861925145.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed example/assets/images/thumb_1861925145_low.png
Binary file not shown.
Binary file added example/assets/images/thumb_1921368425.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed example/assets/images/thumb_1921368425_low.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed example/assets/images/thumb_2046159536_low.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/assets/images/thumb_37412733.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed example/assets/images/thumb_37412733_low.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/assets/images/thumb_724957034.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/assets/images/thumb_862734536.png
Binary file removed example/assets/images/thumb_862734536_low.png
Diff not rendered.
Binary file added example/assets/images/thumb_973271923.png
Binary file removed example/assets/images/thumb_973271923_low.png
Diff not rendered.
17 changes: 17 additions & 0 deletions example/assets/slides.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
[
{
"background": "https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExbXE3N3hlcXl0OXR3eXJjOGJ3MGtvcmMwMWY4eDZqMHFvd3lxaHA4ZCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/YpwVvng323pw45tYwv/giphy.gif",
"content": {
"flex": 1,
"alignment": "center"
},
"style": "announcement",
"transition": {
"type": "fade_in",
"duration": 0,
"delay": 0,
"curve": "ease"
},
"raw": "\nstyle: announcement\nbackground: https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExbXE3N3hlcXl0OXR3eXJjOGJ3MGtvcmMwMWY4eDZqMHFvd3lxaHA4ZCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/YpwVvng323pw45tYwv/giphy.gif\ncontent:\n alignment: center\n",
"data": "# SUPERDECK \n ## RELEASED! 🎉\n\n ### Create beautiful Flutter\n ### slides with Markdown",
"type": "Slide"
},
{
"background": "https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExc21yZzZhNzQ3bmt4dGk3amE5a2ozaHQxbTdpeGM4bHlmazdibmJjdSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/8L43c9x5Lvl2o/giphy.gif",
"style": "custom",
Expand Down
16 changes: 16 additions & 0 deletions example/lib/src/style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ VariantAttribute get coverStyle {
);
}

VariantAttribute get announcementStyle {
return const SlideVariant('announcement')(
apply(coverStyle.value),
$.innerContainer.color.red(),
$.textStyle.height(0.6),
$.h1.textStyle.fontSize(140),
$.h1.textStyle.bold(),
$.h1.textStyle.color(Colors.yellow),
$.h2.textStyle.fontSize(140),
$.h3.textStyle.fontSize(60),
$.h3.textStyle.color(Colors.white),
$.h3.textStyle.fontWeight(FontWeight.w100),
);
}

VariantAttribute get quoteStyle {
return SlideVariant.quote(
$.blockquote.textStyle.as(GoogleFonts.notoSerif()),
Expand Down Expand Up @@ -143,6 +158,7 @@ Style get style {
quoteStyle,
showSectionsStyle,
coverStyle,
announcementStyle,
radStyle,
);
}
Expand Down
13 changes: 13 additions & 0 deletions example/slides.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
---
style: announcement
background: https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExbXE3N3hlcXl0OXR3eXJjOGJ3MGtvcmMwMWY4eDZqMHFvd3lxaHA4ZCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/YpwVvng323pw45tYwv/giphy.gif
content:
alignment: center
---

# SUPERDECK
## RELEASED! 🎉

### Create beautiful Flutter
### slides with Markdown

---
style: custom
layout: two_column_header
Expand Down
52 changes: 35 additions & 17 deletions lib/components/atoms/slide_thumbnail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ class SlideThumbnail extends StatefulWidget {
final bool selected;
final VoidCallback onTap;
final Slide slide;
final String cacheKey;

const SlideThumbnail({
super.key,
required this.selected,
required this.onTap,
required this.slide,
required this.cacheKey,
});

@override
Expand All @@ -48,6 +50,7 @@ class _SlideThumbnailState extends State<SlideThumbnail> {
late final imageCache = ImageCacheService(
slide: widget.slide,
quality: ExportQuality.low,
cacheKey: widget.cacheKey,
);
late final quality = ExportQuality.low;

Expand All @@ -56,22 +59,44 @@ class _SlideThumbnailState extends State<SlideThumbnail> {
@override
void initState() {
super.initState();
getThumbnail();
_getLocalAsset().then((value) => getThumbnail());
}

@override
void didUpdateWidget(SlideThumbnail oldWidget) {
if (oldWidget.cacheKey != widget.cacheKey) {
getThumbnail();
}
super.didUpdateWidget(oldWidget);
}

Future<void> getThumbnail() async {
if (kCanRunProcess) {
await _generateThumbnail();
} else {
await _getLocalAsset();
}
}

Future<void> _getLocalAsset() async {
try {
asyncState.value = AsyncState.loading();
final asset = await imageCache.get();

if (asset != null) {
asyncState.value = AsyncState.data(asset);
return;
}
} on Exception catch (e) {
asyncState.value = AsyncState.error(e);
}
}

Future<void> _generateThumbnail() async {
try {
final asset = imageCache.getMemory();

if (!kCanRunProcess) {
asyncState.value = AsyncState.error(
Exception('Cannot generate thumbnails on the web'),
);
if (asset != null) {
asyncState.value = AsyncState.data(asset);
return;
}

Expand Down Expand Up @@ -100,16 +125,6 @@ class _SlideThumbnailState extends State<SlideThumbnail> {
}
}

// if widget.slide changes, we need to refresh the widget
@override
void didUpdateWidget(covariant SlideThumbnail oldWidget) {
super.didUpdateWidget(oldWidget);

if (oldWidget.slide != widget.slide) {
getThumbnail();
}
}

@override
Widget build(BuildContext context) {
final selectedColor = widget.selected ? Colors.blue : Colors.transparent;
Expand All @@ -126,7 +141,10 @@ class _SlideThumbnailState extends State<SlideThumbnail> {
child: AspectRatio(
aspectRatio: kAspectRatio,
child: result.map(
data: (data) => Image.memory(data),
data: (data) => Image.memory(
data,
gaplessPlayback: true,
),
loading: () {
return const Center(
child: CircularProgressIndicator(),
Expand Down
1 change: 0 additions & 1 deletion lib/components/atoms/slide_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class SlideView extends StatelessWidget {
child: Pressable(
onPress: () {},
child: MixBuilder(
key: ValueKey(variantStyle),
style: variantStyle.animate(),
builder: (mix) {
final spec = SlideSpec.fromMix(mix);
Expand Down
10 changes: 10 additions & 0 deletions lib/components/molecules/slide_thumbnail_list.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:flutter/material.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
import 'package:signals/signals_flutter.dart';

import '../../helpers/utils.dart';
import '../../models/slide_model.dart';
import '../../superdeck.dart';
import '../atoms/slide_thumbnail.dart';
Expand Down Expand Up @@ -74,6 +76,7 @@ class _SlideThumbnailListState extends State<SlideThumbnailList> {

@override
Widget build(BuildContext context) {
final style = SuperDeckProvider.instance.style.watch(context);
return Container(
color: const Color.fromARGB(108, 0, 0, 0),
child: ScrollablePositionedList.builder(
Expand All @@ -85,7 +88,14 @@ class _SlideThumbnailListState extends State<SlideThumbnailList> {
itemBuilder: (context, idx) {
final slide = widget.slides[idx];

final variant = slide.styleVariant;

final slideStyle = style.applyVariant(variant);
final key = md5Hash(slideStyle.toString() + slide.hashKey);

return SlideThumbnail(
key: Key(key),
cacheKey: key,
selected: idx == widget.currentSlide,
onTap: () => goToPage(idx),
slide: slide,
Expand Down
2 changes: 1 addition & 1 deletion lib/components/organisms/app_shell.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class _ScaffoldWithNavBarState extends State<ScaffoldWithNavBar>
return CallbackShortcuts(
bindings: bindings,
child: Scaffold(
bottomNavigationBar: bottomNavBar,
bottomNavigationBar: null,
key: scaffoldKey,
floatingActionButtonLocation: isSmall
? FloatingActionButtonLocation.miniEndFloat
Expand Down
5 changes: 5 additions & 0 deletions lib/helpers/markdown_processor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ class Pipeline {
if (await assetsDir.exists()) {
await for (final entity in assetsDir.list()) {
if (entity is File) {
// if file name does not contains prefix skip
final fileName = entity.path.split('/').last;
if (!fileName.startsWith(SlideAsset.assetPrefix)) {
continue;
}
final asset = await SlideAsset.load(entity);
assets.add(asset);
}
Expand Down
38 changes: 13 additions & 25 deletions lib/helpers/slide_to_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,16 @@ class ImageCacheService {
const ImageCacheService({
required this.slide,
required this.quality,
required this.cacheKey,
});

String _getCacheKey(Slide slide, ExportQuality quality) {
return 'thumb_${slide.hashKey}_${quality.label.toLowerCase()}';
}

String get _cacheKey => _getCacheKey(slide, quality);

final Slide slide;
final ExportQuality quality;
final String cacheKey;

File _getAssetFile() {
final directory = kConfig.assetsImageDir;
return File('${directory.path}/$_cacheKey.png');
return File('${directory.path}/thumb_${slide.hashKey}.png');
}

Future<Uint8List?> loadAssetFile() async {
Expand All @@ -64,37 +60,29 @@ class ImageCacheService {
}
}

// Future<Uint8List?> loadSupportFile() async {
// try {
// final file = await getSupportFile();
// return await file.exists() ? file.readAsBytes() : null;
// } catch (e) {
// return null;
// }
// }

// Future<File> getSupportFile() async {
// final directory = await getApplicationSupportDirectory();
// return File('${directory.path}/$cacheKey.png');
// }

Future<void> set(Uint8List image) async {
_imageCache[_cacheKey] = image;
_imageCache.removeWhere((key, value) => key.contains(slide.hashKey));

_imageCache[cacheKey] = image;

if (kCanRunProcess) {
final file = _getAssetFile();

await file.writeAsBytes(image);
return;
}

throw Exception('Cannot cache image on the web');
}

Future<Uint8List?> get() async {
if (_imageCache.containsKey(_cacheKey)) {
return _imageCache[_cacheKey];
Uint8List? getMemory() {
if (_imageCache.containsKey(cacheKey)) {
return _imageCache[cacheKey];
}
return null;
}

Future<Uint8List?> get() async {
try {
return await loadAssetFile();
} catch (e) {
Expand Down
7 changes: 7 additions & 0 deletions lib/helpers/utils.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:convert';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:crypto/crypto.dart';
import 'package:flutter/material.dart';
import 'package:mix/mix.dart';
import 'package:yaml/yaml.dart';
Expand Down Expand Up @@ -78,6 +79,12 @@ String hashString(String input) {
return hash.toString();
}

String md5Hash(String input) {
var bytes = utf8.encode(input);
var digest = md5.convert(bytes);
return digest.toString();
}

({List<T> added, List<T> removed}) compareListChanges<T>(
List<T> oldList, List<T> newList) {
final added = <T>[];
Expand Down
Loading

0 comments on commit 8781aee

Please sign in to comment.