⚡ Optimize image cache size
This commit is contained in:
parent
a673beb87c
commit
5364aecf74
@ -1,6 +1,7 @@
|
|||||||
import 'package:croppy/croppy.dart';
|
import 'package:croppy/croppy.dart';
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:easy_localization_loader/easy_localization_loader.dart';
|
import 'package:easy_localization_loader/easy_localization_loader.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:relative_time/relative_time.dart';
|
import 'package:relative_time/relative_time.dart';
|
||||||
@ -15,6 +16,10 @@ void main() async {
|
|||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
await EasyLocalization.ensureInitialized();
|
await EasyLocalization.ensureInitialized();
|
||||||
|
|
||||||
|
if (!kReleaseMode) {
|
||||||
|
debugInvertOversizedImages = true;
|
||||||
|
}
|
||||||
|
|
||||||
runApp(const SolianApp());
|
runApp(const SolianApp());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,10 +23,14 @@ class AttachmentItem extends StatelessWidget {
|
|||||||
case 'image':
|
case 'image':
|
||||||
return Hero(
|
return Hero(
|
||||||
tag: 'attachment-${data.rid}-$heroTag',
|
tag: 'attachment-${data.rid}-$heroTag',
|
||||||
child: UniversalImage(
|
child: LayoutBuilder(builder: (context, constraints) {
|
||||||
|
return UniversalImage(
|
||||||
sn.getAttachmentUrl(data.rid),
|
sn.getAttachmentUrl(data.rid),
|
||||||
fit: BoxFit.cover,
|
fit: BoxFit.cover,
|
||||||
),
|
cacheHeight: constraints.maxHeight,
|
||||||
|
cacheWidth: constraints.maxWidth,
|
||||||
|
);
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
return const Placeholder();
|
return const Placeholder();
|
||||||
|
@ -10,6 +10,8 @@ class AppBackground extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final devicePixelRatio = MediaQuery.of(context).devicePixelRatio;
|
||||||
|
|
||||||
return ScaffoldMessenger(
|
return ScaffoldMessenger(
|
||||||
child: FutureBuilder(
|
child: FutureBuilder(
|
||||||
future:
|
future:
|
||||||
@ -21,17 +23,28 @@ class AppBackground extends StatelessWidget {
|
|||||||
if (file.existsSync()) {
|
if (file.existsSync()) {
|
||||||
return Container(
|
return Container(
|
||||||
color: Theme.of(context).colorScheme.surface,
|
color: Theme.of(context).colorScheme.surface,
|
||||||
child: Container(
|
child: LayoutBuilder(
|
||||||
|
builder: (context, constraints) {
|
||||||
|
return Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
backgroundBlendMode: BlendMode.darken,
|
backgroundBlendMode: BlendMode.darken,
|
||||||
color: Theme.of(context).colorScheme.surface,
|
color: Theme.of(context).colorScheme.surface,
|
||||||
image: DecorationImage(
|
image: DecorationImage(
|
||||||
opacity: 0.2,
|
opacity: 0.2,
|
||||||
image: FileImage(file),
|
image: ResizeImage(
|
||||||
|
FileImage(file),
|
||||||
|
width: (constraints.maxWidth * devicePixelRatio)
|
||||||
|
.round(),
|
||||||
|
height: (constraints.maxHeight * devicePixelRatio)
|
||||||
|
.round(),
|
||||||
|
policy: ResizeImagePolicy.fit,
|
||||||
|
),
|
||||||
fit: BoxFit.cover,
|
fit: BoxFit.cover,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: child,
|
child: child,
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user