Skip to content

Commit

Permalink
bugfix:image save
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenDoxiu committed Jul 8, 2024
1 parent b547366 commit 5568d22
Show file tree
Hide file tree
Showing 13 changed files with 407 additions and 282 deletions.
2 changes: 1 addition & 1 deletion lib/apis/models/drive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class DriveFileModel extends DriveModel {
isSensitive: map['isSensitive'] ?? false,
thumbnailUrl: map['thumbnailUrl'],
comment: map['comment'],
hero: null,
hero: UniqueKey(),
);
}

Expand Down
4 changes: 3 additions & 1 deletion lib/pages/image_preview/image_preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ class ImagePreviewPage extends HookConsumerWidget {
var res = await saveImage(
http: http.valueOrNull!,
url: galleryItems[currentIndex.value].url,
album: meta.valueOrNull?.name ?? "MoeKey");
album: meta.valueOrNull?.name ?? "MoeKey",
name:
galleryItems[currentIndex.value].name);
if (context.mounted) {
var snackBar = SnackBar(
content: Text(res ? "保存成功" : "保存失败"),
Expand Down
1 change: 1 addition & 0 deletions lib/pages/users/user_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ class UserPage extends HookConsumerWidget {
),
],
showBack: true,
tabAlignment: TabAlignment.start,
leading: Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
Expand Down
14 changes: 12 additions & 2 deletions lib/utils/save_image.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
import 'dart:ui' as ui;
import 'dart:ui';

import 'package:crypto/crypto.dart';
import 'package:dio/dio.dart';
import 'package:extended_image/extended_image.dart';
import 'package:file_picker/file_picker.dart';
Expand All @@ -14,6 +16,7 @@ import 'package:shared_preferences/shared_preferences.dart';

const Map<String, String> defaultExtensionMap = {
'image/png': 'png',
'image/jpeg': 'jpg',
'image/webp': 'webp',
'image/gif': 'gif',
'image/heif': 'heif',
Expand All @@ -24,18 +27,25 @@ const Map<String, String> defaultExtensionMap = {
Future<bool> saveImage({
required Dio http,
required String url,
String? name,
String album = "moekey",
}) async {
var name = basename(url);
var ext = extension(name);
name =
name != null ? basename(name) : md5.convert(utf8.encode(url)).toString();

var ext = extension(name).substring(1);
var fileBasename = basenameWithoutExtension(name);

var data = await getNetworkImageData(url, useCache: true);
if (data == null) {
return false;
}
var type = lookupMimeType(url, headerBytes: data);

ext = defaultExtensionMap[type] ?? ext;

name = "$fileBasename.$ext";

var codec = await ui.instantiateImageCodec(data);

if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) {
Expand Down
29 changes: 17 additions & 12 deletions lib/widgets/mfm_text/mfm_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,26 @@ class MFMText extends HookConsumerWidget {
currentServerHost: currentServerHost,
systemEmojis: emoji.valueOrNull ?? {},
);

var textSpan = useMemoized(
() {
return [
for (var item in mfmParse.value)
if (parse[item.type] != null)
parse[item.type](
item,
textStyle,
)
else
TextSpan(text: item.toString()),
];
},
);

Widget rich = RepaintBoundary(
child: Text.rich(
TextSpan(
children: [
...?before,
for (var item in mfmParse.value)
if (parse[item.type] != null)
parse[item.type](
item,
textStyle,
)
else
TextSpan(text: item.toString()),
...?after
],
children: [...?before, ...textSpan, ...?after],
style: Theme.of(context).textTheme.bodyMedium,
),
maxLines: maxLines,
Expand Down
67 changes: 35 additions & 32 deletions lib/widgets/mk_refresh_load.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,47 +24,50 @@ class MkRefreshLoadList<T> extends StatelessWidget {
@override
Widget build(BuildContext context) {
var mediaPadding = MediaQuery.paddingOf(context);
print("MkRefreshLoadList build");
return MkRefreshIndicator(
onRefresh: () => onRefresh(),
child: CustomScrollView(
primary: true,
cacheExtent: (Platform.isAndroid || Platform.isIOS) ? 1000 : 4000,
slivers: [
SliverPadding(
padding: mediaPadding.add(padding),
sliver: SliverMainAxisGroup(
slivers: [
...slivers,
SliverLayoutBuilder(
builder: (context, constraints) {
if (constraints.remainingPaintExtent > 0 &&
(hasMore ?? true)) {
onLoad();
}
if (!(hasMore ?? true)) {
child: RepaintBoundary(
child: CustomScrollView(
primary: true,
cacheExtent: (Platform.isAndroid || Platform.isIOS) ? null : 4000,
slivers: [
SliverPadding(
padding: mediaPadding.add(padding),
sliver: SliverMainAxisGroup(
slivers: [
...slivers,
SliverLayoutBuilder(
builder: (context, constraints) {
if (constraints.remainingPaintExtent > 0 &&
(hasMore ?? true)) {
onLoad();
}
if (!(hasMore ?? true)) {
return const SliverToBoxAdapter(
child: Padding(
padding: EdgeInsets.all(16.0),
child: Center(
child: Text("暂无更多"),
),
),
);
}
return const SliverToBoxAdapter(
child: Padding(
padding: EdgeInsets.all(16.0),
child: Center(
child: Text("暂无更多"),
child: LoadingCircularProgress(),
),
),
);
}
return const SliverToBoxAdapter(
child: Padding(
padding: EdgeInsets.all(16.0),
child: Center(
child: LoadingCircularProgress(),
),
),
);
},
)
],
),
)
],
},
)
],
),
)
],
),
),
);
}
Expand Down
7 changes: 5 additions & 2 deletions lib/widgets/mk_tabbar_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class MkTabBarRefreshScroll extends StatefulWidget {
this.showBack = false,
this.onIndexUpdate,
this.initIndex = 0,
this.padding = EdgeInsets.zero});
this.padding = EdgeInsets.zero,
this.tabAlignment = TabAlignment.center});

final List<MkTabBarItem> items;
final Widget? leading;
Expand All @@ -44,6 +45,8 @@ class MkTabBarRefreshScroll extends StatefulWidget {
final EdgeInsetsGeometry padding;
final void Function(int)? onIndexUpdate;

final TabAlignment tabAlignment;

@override
State<MkTabBarRefreshScroll> createState() => MkTabBarRefreshScrollState();
}
Expand Down Expand Up @@ -112,7 +115,7 @@ class MkTabBarRefreshScrollState extends State<MkTabBarRefreshScroll>
: false,
bottom: MkTabBar(
controller: tabController,
tabAlignment: TabAlignment.center,
tabAlignment: widget.tabAlignment,
onTap: (value) {
if (lastIndex == value) {
refresh();
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/note_create_dialog/note_create_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class NoteCreateDialog extends HookConsumerWidget {
.notifier)
.send();
if (res != null) {
contentController.text = "";
contentController.text = initText ?? "";
if (context.mounted) {
Navigator.of(context).pop(res);
}
Expand Down
5 changes: 4 additions & 1 deletion lib/widgets/note_create_dialog/note_create_dialog_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ class NoteCreateDialogState extends _$NoteCreateDialogState {
ref.invalidate(driverSelectDialogStateProvider);
ref.invalidate(noteCreateDialogStateProvider);
ref.notifyListeners();
sendLoading = false;
return res.data;
} on DioException catch (e) {
logger.d(e.response);
Expand All @@ -288,8 +289,10 @@ class NoteCreateDialogState extends _$NoteCreateDialogState {
isError: true);
} catch (e) {
MkInfoDialog.show(info: "$e", isError: true);
} finally {
sendLoading = false;
}
sendLoading = false;

return null;
}
}
Loading

0 comments on commit 5568d22

Please sign in to comment.