mirror of
https://github.com/ZhuJHua/moodiary.git
synced 2026-04-05 16:39:01 +08:00
fix(share): fix capture and share methods
This commit is contained in:
@@ -20,18 +20,20 @@ class ShareLogic extends GetxController {
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
Future<Uint8List> captureWidget() async {
|
||||
Future<Uint8List> _captureWidget(BuildContext context) async {
|
||||
final boundary =
|
||||
state.key.currentContext?.findRenderObject() as RenderRepaintBoundary;
|
||||
final pixelRatio = MediaQuery.devicePixelRatioOf(Get.context!);
|
||||
final pixelRatio = MediaQuery.devicePixelRatioOf(context);
|
||||
final image = await boundary.toImage(pixelRatio: pixelRatio);
|
||||
final data = await image.toByteData(format: ImageByteFormat.png);
|
||||
return data!.buffer.asUint8List();
|
||||
}
|
||||
|
||||
Future<void> share() async {
|
||||
Future<void> share(BuildContext context) async {
|
||||
final name = 'screenshot-${const Uuid().v7()}.png';
|
||||
File(FileUtil.getCachePath(name)).writeAsBytes(await captureWidget());
|
||||
await File(
|
||||
FileUtil.getCachePath(name),
|
||||
).writeAsBytes(await _captureWidget(context));
|
||||
await Share.shareXFiles([XFile(FileUtil.getCachePath(name))]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ class SharePage extends StatelessWidget {
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () {
|
||||
logic.share();
|
||||
logic.share(context);
|
||||
},
|
||||
child: const Icon(Icons.share),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user