Skip to content

Commit

Permalink
## 0.7.10+50
Browse files Browse the repository at this point in the history
fix image load
  • Loading branch information
ChenDoXiu committed Dec 22, 2024
1 parent 3824ba0 commit 623c28a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 76 deletions.
5 changes: 4 additions & 1 deletion lib/pages/users/user_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:moekey/widgets/mk_scaffold.dart';
import 'package:moekey/widgets/mk_tabbar_list.dart';

import '../../generated/l10n.dart';
import '../../status/server.dart';
import '../../status/themes.dart';

class UserPage extends HookConsumerWidget {
Expand All @@ -33,6 +34,8 @@ class UserPage extends HookConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
var userProvider =
userInfoProvider(username: username, host: host, userId: this.userId);

var loginUser = ref.watch(currentLoginUserProvider);
var user = ref.watch(userProvider);
if (user.isLoading) {
return MkScaffold(
Expand Down Expand Up @@ -102,7 +105,7 @@ class UserPage extends HookConsumerWidget {
),
child: UserNotesPage(userId: userId),
),
if (userData.publicReactions)
if (userData.publicReactions || userData.id == loginUser?.id)
MkTabBarItem(
label: Tab(
child: Row(
Expand Down
123 changes: 50 additions & 73 deletions lib/widgets/mk_image.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:math';

import 'package:blurhash_shader/blurhash_shader.dart';
import 'package:extended_image/extended_image.dart';
import 'package:flutter/material.dart';
Expand All @@ -8,7 +10,7 @@ ExtendedResizeImage getExtendedResizeImage(String url) {
maxBytes: 500 << 10);
}

class MkImage extends StatefulWidget {
class MkImage extends StatelessWidget {
final String url;
final double? width;
final double? height;
Expand All @@ -28,94 +30,69 @@ class MkImage extends StatefulWidget {
this.heroKey,
});

@override
State<MkImage> createState() => _MkImageState();
}

class _MkImageState extends State<MkImage> with SingleTickerProviderStateMixin {
late AnimationController _controller;

@override
void initState() {
_controller = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 300),
lowerBound: 0.0,
upperBound: 1.0);
super.initState();
}

@override
void dispose() {
_controller.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
// 额外判断svg
if (widget.url.endsWith(".svg")) {
if (url.endsWith(".svg")) {
return DecoratedBox(
decoration: BoxDecoration(
shape: widget.shape ?? BoxShape.rectangle,
shape: shape ?? BoxShape.rectangle,
),
child: SvgPicture.network(widget.url,
width: widget.width, height: widget.height, fit: widget.fit),
child: SvgPicture.network(url,
width: width, height: height, fit: fit),
);
}
Widget image = ExtendedImage(
image: getExtendedResizeImage(widget.url),
shape: widget.shape,
image: getExtendedResizeImage(url),
shape: shape,
loadStateChanged: (state) {
switch (state.extendedImageLoadState) {
case LoadState.completed:
_controller.forward();
var image = FadeTransition(
opacity: _controller,
child: ExtendedRawImage(
image: state.extendedImageInfo?.image,
height: widget.height,
width: widget.width,
fit: widget.fit,
filterQuality: FilterQuality.medium,
),
);
if (widget.blurHash == null || widget.blurHash!.isEmpty) {
return image;
Widget child = LayoutBuilder(
builder: (context, constraints) {
var constraintsHeight = constraints.maxHeight;
var constraintsWidth = constraints.maxWidth;
if (constraints.maxHeight == double.infinity) {
constraintsHeight = constraints.minHeight;
}
return BlurHash(
widget.blurHash!,
child: image,
);
case LoadState.loading:
case LoadState.failed:
return LayoutBuilder(
builder: (context, constraints) {
var constraintsHeight = constraints.maxHeight;
var constraintsWidth = constraints.maxWidth;
if (constraints.maxHeight == double.infinity) {
constraintsHeight = constraints.minHeight;
}
if (constraints.maxWidth == double.infinity) {
constraintsWidth = constraints.minWidth;
}
return Container(
width: widget.width ?? widget.height ?? constraintsWidth,
height: widget.height ?? constraintsHeight,
color: const Color.fromARGB(10, 0, 0, 0),
child:
(widget.blurHash != null && widget.blurHash!.isNotEmpty)
? BlurHash(widget.blurHash!)
: null,
);
},
if (constraints.maxWidth == double.infinity) {
constraintsWidth = constraints.minWidth;
}
return Container(
width: width ?? height ?? constraintsWidth,
height: height ?? constraintsHeight,
color: const Color.fromARGB(10, 0, 0, 0),
);
},
);

if(state.extendedImageLoadState == LoadState.completed) {
child = ExtendedRawImage(
image: state.extendedImageInfo?.image,
height: height,
width: width,
fit: fit,
filterQuality: FilterQuality.medium,
);
}

child = AnimatedOpacity(
duration: const Duration(milliseconds: 200),
opacity: state.extendedImageLoadState == LoadState.completed ? 1.0 : 0.0,
child: child,
);

if(blurHash == null || blurHash!.isEmpty) {
return child;
}

return BlurHash(
blurHash!,
child: child,
);
},
);

if (widget.heroKey != null) {
image = Hero(tag: widget.heroKey ?? UniqueKey(), child: image);
if (heroKey != null) {
image = Hero(tag: heroKey!, child: image);
}
return RepaintBoundary(
child: image,
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/notes/note_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ class _TimeLineImageState extends State<TimeLineImage> {
void initState() {
super.initState();
for (var value in widget.files) {
if (value.type.startsWith("image")) {
if (value.type.startsWith("image") || value.type.startsWith("video")) {
heroKeys.add(UniqueKey());
}
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 0.7.9+49
version: 0.7.10+50

environment:
sdk: '>=3.5.0 <4.0.0'
Expand Down

0 comments on commit 623c28a

Please sign in to comment.