mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
fix #73
This commit is contained in:
@@ -163,7 +163,7 @@ class ComicTile extends StatelessWidget {
|
||||
Widget buildImage(BuildContext context) {
|
||||
ImageProvider image;
|
||||
if (comic is LocalComic) {
|
||||
image = FileImage((comic as LocalComic).coverFile);
|
||||
image = LocalComicImageProvider(comic as LocalComic);
|
||||
} else if (comic.sourceKey == 'local') {
|
||||
var localComic = LocalManager().find(comic.id, ComicType.local);
|
||||
if (localComic == null) {
|
||||
|
@@ -19,6 +19,7 @@ import 'package:venera/foundation/consts.dart';
|
||||
import 'package:venera/foundation/favorites.dart';
|
||||
import 'package:venera/foundation/history.dart';
|
||||
import 'package:venera/foundation/image_provider/cached_image.dart';
|
||||
import 'package:venera/foundation/image_provider/local_comic_image.dart';
|
||||
import 'package:venera/foundation/local.dart';
|
||||
import 'package:venera/foundation/res.dart';
|
||||
import 'package:venera/network/cloudflare.dart';
|
||||
|
63
lib/foundation/image_provider/local_comic_image.dart
Normal file
63
lib/foundation/image_provider/local_comic_image.dart
Normal file
@@ -0,0 +1,63 @@
|
||||
import 'dart:async' show Future, StreamController;
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:venera/foundation/local.dart';
|
||||
import 'package:venera/network/images.dart';
|
||||
import 'package:venera/utils/io.dart';
|
||||
import 'base_image_provider.dart';
|
||||
import 'local_comic_image.dart' as image_provider;
|
||||
|
||||
class LocalComicImageProvider
|
||||
extends BaseImageProvider<image_provider.LocalComicImageProvider> {
|
||||
/// Image provider for normal image.
|
||||
///
|
||||
/// [url] is the url of the image. Local file path is also supported.
|
||||
const LocalComicImageProvider(this.comic);
|
||||
|
||||
final LocalComic comic;
|
||||
|
||||
@override
|
||||
Future<Uint8List> load(StreamController<ImageChunkEvent> chunkEvents) async {
|
||||
File? file = comic.coverFile;
|
||||
if(! await file.exists()) {
|
||||
file = null;
|
||||
var dir = Directory(comic.directory);
|
||||
if (! await dir.exists()) {
|
||||
throw "Error: Comic not found.";
|
||||
}
|
||||
Directory? firstDir;
|
||||
await for (var entity in dir.list()) {
|
||||
if(entity is File) {
|
||||
if(["jpg", "jpeg", "png", "webp", "gif", "jpe", "jpeg"].contains(entity.extension)) {
|
||||
file = entity;
|
||||
break;
|
||||
}
|
||||
} else if(entity is Directory) {
|
||||
firstDir ??= entity;
|
||||
}
|
||||
}
|
||||
if(file == null && firstDir != null) {
|
||||
await for (var entity in firstDir.list()) {
|
||||
if(entity is File) {
|
||||
if(["jpg", "jpeg", "png", "webp", "gif", "jpe", "jpeg"].contains(entity.extension)) {
|
||||
file = entity;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(file == null) {
|
||||
throw "Error: Cover not found.";
|
||||
}
|
||||
return file.readAsBytes();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LocalComicImageProvider> obtainKey(ImageConfiguration configuration) {
|
||||
return SynchronousFuture(this);
|
||||
}
|
||||
|
||||
@override
|
||||
String get key => "local${comic.id}${comic.comicType.value}";
|
||||
}
|
@@ -7,6 +7,7 @@ import 'package:venera/foundation/consts.dart';
|
||||
import 'package:venera/foundation/favorites.dart';
|
||||
import 'package:venera/foundation/history.dart';
|
||||
import 'package:venera/foundation/image_provider/cached_image.dart';
|
||||
import 'package:venera/foundation/image_provider/local_comic_image.dart';
|
||||
import 'package:venera/foundation/local.dart';
|
||||
import 'package:venera/pages/accounts_page.dart';
|
||||
import 'package:venera/pages/comic_page.dart';
|
||||
@@ -418,8 +419,8 @@ class _LocalState extends State<_Local> {
|
||||
),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: AnimatedImage(
|
||||
image: FileImage(
|
||||
local[index].coverFile,
|
||||
image: LocalComicImageProvider(
|
||||
local[index],
|
||||
),
|
||||
width: 96,
|
||||
height: 128,
|
||||
|
Reference in New Issue
Block a user