feat: 增加防丢失页面海报生成

This commit is contained in:
speakeloudest 2026-01-12 18:49:07 -08:00
parent 26f6c10557
commit 2e7658c4fd
9 changed files with 82 additions and 96 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 229 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -24,6 +24,9 @@ PODS:
- flutter_udid (0.0.1): - flutter_udid (0.0.1):
- Flutter - Flutter
- SAMKeychain - SAMKeychain
- gal (1.0.0):
- Flutter
- FlutterMacOS
- in_app_purchase_storekit (0.0.1): - in_app_purchase_storekit (0.0.1):
- Flutter - Flutter
- FlutterMacOS - FlutterMacOS
@ -51,6 +54,7 @@ DEPENDENCIES:
- flutter_inappwebview_ios (from `.symlinks/plugins/flutter_inappwebview_ios/ios`) - flutter_inappwebview_ios (from `.symlinks/plugins/flutter_inappwebview_ios/ios`)
- flutter_keychain (from `.symlinks/plugins/flutter_keychain/ios`) - flutter_keychain (from `.symlinks/plugins/flutter_keychain/ios`)
- flutter_udid (from `.symlinks/plugins/flutter_udid/ios`) - flutter_udid (from `.symlinks/plugins/flutter_udid/ios`)
- gal (from `.symlinks/plugins/gal/darwin`)
- in_app_purchase_storekit (from `.symlinks/plugins/in_app_purchase_storekit/darwin`) - in_app_purchase_storekit (from `.symlinks/plugins/in_app_purchase_storekit/darwin`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`) - package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`) - path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
@ -81,6 +85,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/flutter_keychain/ios" :path: ".symlinks/plugins/flutter_keychain/ios"
flutter_udid: flutter_udid:
:path: ".symlinks/plugins/flutter_udid/ios" :path: ".symlinks/plugins/flutter_udid/ios"
gal:
:path: ".symlinks/plugins/gal/darwin"
in_app_purchase_storekit: in_app_purchase_storekit:
:path: ".symlinks/plugins/in_app_purchase_storekit/darwin" :path: ".symlinks/plugins/in_app_purchase_storekit/darwin"
package_info_plus: package_info_plus:
@ -104,6 +110,7 @@ SPEC CHECKSUMS:
flutter_inappwebview_ios: 6f63631e2c62a7c350263b13fa5427aedefe81d4 flutter_inappwebview_ios: 6f63631e2c62a7c350263b13fa5427aedefe81d4
flutter_keychain: 01aabf894ffe8b01adfda1d9df21c210c1b4b452 flutter_keychain: 01aabf894ffe8b01adfda1d9df21c210c1b4b452
flutter_udid: b2417673f287ee62817a1de3d1643f47b9f508ab flutter_udid: b2417673f287ee62817a1de3d1643f47b9f508ab
gal: 6a522c75909f1244732d4596d11d6a2f86ff37a5
in_app_purchase_storekit: a1ce04056e23eecc666b086040239da7619cd783 in_app_purchase_storekit: a1ce04056e23eecc666b086040239da7619cd783
OrderedSet: e539b66b644ff081c73a262d24ad552a69be3a94 OrderedSet: e539b66b644ff081c73a262d24ad552a69be3a94
package_info_plus: c0502532a26c7662a62a356cebe2692ec5fe4ec4 package_info_plus: c0502532a26c7662a62a356cebe2692ec5fe4ec4

View File

@ -1,3 +1,4 @@
import 'dart:io';
import 'dart:typed_data'; import 'dart:typed_data';
import 'dart:ui' as ui; import 'dart:ui' as ui;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -5,6 +6,7 @@ import 'package:flutter/rendering.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:gal/gal.dart'; import 'package:gal/gal.dart';
import 'package:kaer_with_panels/app/utils/kr_common_util.dart'; import 'package:kaer_with_panels/app/utils/kr_common_util.dart';
import 'package:kaer_with_panels/app/widgets/dialogs/hi_dialog.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
class HIAntiLostController extends GetxController { class HIAntiLostController extends GetxController {
@ -20,9 +22,9 @@ class HIAntiLostController extends GetxController {
} }
// Capture image // Capture image
RenderRepaintBoundary? boundary = RenderRepaintBoundary? boundary = repaintKey.currentContext
repaintKey.currentContext?.findRenderObject() as RenderRepaintBoundary?; ?.findRenderObject() as RenderRepaintBoundary?;
if (boundary == null) { if (boundary == null) {
throw Exception("Cannot find boundary"); throw Exception("Cannot find boundary");
} }
@ -30,26 +32,38 @@ class HIAntiLostController extends GetxController {
// Check if the boundary needs layout (sometimes Offstage needs a frame) // Check if the boundary needs layout (sometimes Offstage needs a frame)
if (boundary.debugNeedsPaint) { if (boundary.debugNeedsPaint) {
await Future.delayed(const Duration(milliseconds: 20)); await Future.delayed(const Duration(milliseconds: 20));
boundary = repaintKey.currentContext?.findRenderObject() as RenderRepaintBoundary?; boundary = repaintKey.currentContext?.findRenderObject()
as RenderRepaintBoundary?;
} }
ui.Image image = await boundary!.toImage(pixelRatio: 3.0); ui.Image image = await boundary!.toImage(pixelRatio: 3.0);
ByteData? byteData = ByteData? byteData =
await image.toByteData(format: ui.ImageByteFormat.png); await image.toByteData(format: ui.ImageByteFormat.png);
if (byteData != null) { if (byteData != null) {
final Uint8List pngBytes = byteData.buffer.asUint8List(); final Uint8List pngBytes = byteData.buffer.asUint8List();
await Gal.putImageBytes(pngBytes); await Gal.putImageBytes(pngBytes);
KRCommonUtil.kr_showToast("保存成功"); // KRCommonUtil.kr_showToast("保存成功");
String message = "已保存至系统相册";
if (Platform.isMacOS) {
message = "已保存至系统【照片】应用";
} else if (Platform.isWindows) {
message = "已保存至系统【图片】文件夹";
}
HIDialog.show(
message: message,
);
} else { } else {
KRCommonUtil.kr_showToast("生成图片失败"); KRCommonUtil.kr_showToast("生成图片失败");
} }
} catch (e) { } catch (e) {
debugPrint("Save image error: $e"); debugPrint("Save image error: $e");
if (e is GalException) { if (e is GalException) {
KRCommonUtil.kr_showToast("保存失败: No Permission"); KRCommonUtil.kr_showToast("保存失败: No Permission");
} else { } else {
KRCommonUtil.kr_showToast("保存失败"); KRCommonUtil.kr_showToast("保存失败");
} }
} finally { } finally {
KRCommonUtil.kr_hideLoading(); KRCommonUtil.kr_hideLoading();
@ -67,7 +81,7 @@ class HIAntiLostController extends GetxController {
} else { } else {
// Fallback to web // Fallback to web
if (!await launchUrl(webUrl, mode: LaunchMode.externalApplication)) { if (!await launchUrl(webUrl, mode: LaunchMode.externalApplication)) {
KRCommonUtil.kr_showToast("无法打开链接"); KRCommonUtil.kr_showToast("无法打开链接");
} }
} }
} catch (e) { } catch (e) {
@ -75,7 +89,7 @@ class HIAntiLostController extends GetxController {
// Fallback to web if anything goes wrong // Fallback to web if anything goes wrong
try { try {
if (!await launchUrl(webUrl, mode: LaunchMode.externalApplication)) { if (!await launchUrl(webUrl, mode: LaunchMode.externalApplication)) {
KRCommonUtil.kr_showToast("无法打开链接"); KRCommonUtil.kr_showToast("无法打开链接");
} }
} catch (e) { } catch (e) {
KRCommonUtil.kr_showToast("无法打开链接"); KRCommonUtil.kr_showToast("无法打开链接");

View File

@ -13,18 +13,11 @@ class HIAntiLostView extends GetView<HIAntiLostController> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return HIBaseScaffold( return HIBaseScaffold(
showBack: true,
title: null,
topContentAreaHeight: 0,
backgroundColor: Colors.black, // Dark background
child: Stack( child: Stack(
fit: StackFit.expand, fit: StackFit.expand,
children: [ children: [
// 1. Visible Content
Column( Column(
children: [ children: [
SizedBox(height: 60.h),
// Card Container
Container( Container(
width: double.infinity, width: double.infinity,
margin: EdgeInsets.symmetric(horizontal: 40.w), margin: EdgeInsets.symmetric(horizontal: 40.w),
@ -46,7 +39,7 @@ class HIAntiLostView extends GetView<HIAntiLostController> {
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
SizedBox(height: 25.h), SizedBox(height: 25.w),
Text( Text(
'建议保存Hi快VPN防丢二维码到相册\n永久保障您的互联网自由', '建议保存Hi快VPN防丢二维码到相册\n永久保障您的互联网自由',
textAlign: TextAlign.center, textAlign: TextAlign.center,
@ -56,7 +49,7 @@ class HIAntiLostView extends GetView<HIAntiLostController> {
height: 1.5, height: 1.5,
), ),
), ),
SizedBox(height: 10.h), SizedBox(height: 10.w),
// QR Code // QR Code
LayoutBuilder(builder: (context, constraints) { LayoutBuilder(builder: (context, constraints) {
// Use a reasonable size for the QR code // Use a reasonable size for the QR code
@ -76,9 +69,8 @@ class HIAntiLostView extends GetView<HIAntiLostController> {
dataModuleShape: QrDataModuleShape.square, dataModuleShape: QrDataModuleShape.square,
color: Theme.of(context).primaryColor, color: Theme.of(context).primaryColor,
), ),
// center image embeddedImage: const AssetImage(
embeddedImage: 'assets/images/lost-poster-logo-white.png'),
const AssetImage('assets/images/kr-logo.png'),
embeddedImageStyle: QrEmbeddedImageStyle( embeddedImageStyle: QrEmbeddedImageStyle(
size: Size(36.w, 36.w), size: Size(36.w, 36.w),
), ),
@ -89,7 +81,7 @@ class HIAntiLostView extends GetView<HIAntiLostController> {
), ),
), ),
SizedBox(height: 30.h), SizedBox(height: 10.w),
// Save Button // Save Button
GestureDetector( GestureDetector(
@ -101,7 +93,7 @@ class HIAntiLostView extends GetView<HIAntiLostController> {
alignment: Alignment.center, alignment: Alignment.center,
decoration: BoxDecoration( decoration: BoxDecoration(
color: Theme.of(context).primaryColor, color: Theme.of(context).primaryColor,
borderRadius: BorderRadius.circular(22.h), borderRadius: BorderRadius.circular(22.w),
), ),
child: Text( child: Text(
'保存到本地', '保存到本地',
@ -120,7 +112,7 @@ class HIAntiLostView extends GetView<HIAntiLostController> {
// 2. Bottom Button (Follow us on X) // 2. Bottom Button (Follow us on X)
Positioned( Positioned(
bottom: 40.h, bottom: 40.w,
left: 0, left: 0,
right: 0, right: 0,
child: Center( child: Center(

View File

@ -8,80 +8,50 @@ class HIAntiLostShareCard extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// Fixed width for the generated image, independent of screen size // Fixed dimensions for the generated image
final double cardWidth = 375.0; final double cardWidth = 375.0;
final double cardHeight = 600.0; // Approx height final double cardHeight = 812.0;
return Container( return Container(
width: cardWidth, width: cardWidth,
// minimal height or let it expand height: cardHeight,
padding: EdgeInsets.all(20), decoration: const BoxDecoration(
color: Colors.black, // Dark background image: DecorationImage(
child: Column( image: AssetImage('assets/images/lost-poster-bg.png'),
mainAxisSize: MainAxisSize.min, fit: BoxFit.cover,
),
),
child: Stack(
children: [ children: [
SizedBox(height: 40), Positioned(
// Title top: 32,
Text( right: 30,
'保存二维码,防止失联', child: SizedBox(
style: TextStyle( width: 108,
color: const Color(0xFFCCFF00), height: 108,
fontSize: 24, child: QrImageView(
fontWeight: FontWeight.bold, data:
fontFamily: 'AlibabaPuHuiTi-Medium', 'https://github.com/hi-vpn/hi-client', // Replace with actual URL
), version: QrVersions.auto,
), size: 108,
SizedBox(height: 20), padding: EdgeInsets.zero,
// Description backgroundColor: Colors.transparent,
Text( eyeStyle: const QrEyeStyle(
'建议保存Hi快VPN防丢二维码到相册\n永久保障您的互联网自由', eyeShape: QrEyeShape.square,
textAlign: TextAlign.center, color: Colors.white,
style: TextStyle(
color: const Color(0xFFCCFF00),
fontSize: 14,
height: 1.5,
fontFamily: 'AlibabaPuHuiTi-Regular',
),
),
SizedBox(height: 40),
// QR Code Card
Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.black,
border: Border.all(color: const Color(0xFFCCFF00), width: 3),
borderRadius: BorderRadius.circular(20),
),
child: QrImageView(
data: 'https://github.com/hi-vpn/hi-client', // Replace with actual URL
version: QrVersions.auto,
size: 200,
backgroundColor: Colors.transparent,
eyeStyle: const QrEyeStyle(
eyeShape: QrEyeShape.square,
color: Color(0xFFCCFF00),
),
dataModuleStyle: const QrDataModuleStyle(
dataModuleShape: QrDataModuleShape.square,
color: Color(0xFFCCFF00),
),
embeddedImage: const AssetImage('assets/images/kr-logo.png'),
embeddedImageStyle: const QrEmbeddedImageStyle(
size: Size(50, 50),
), ),
), dataModuleStyle: const QrDataModuleStyle(
), dataModuleShape: QrDataModuleShape.square,
SizedBox(height: 40), color: Colors.white,
// Footer branding ),
Text( embeddedImage: const AssetImage(
'HiVPN', 'assets/images/lost-poster-logo-white.png'),
style: TextStyle( embeddedImageStyle: const QrEmbeddedImageStyle(
color: Colors.white.withOpacity(0.5), size: Size(42, 42),
fontSize: 12, ),
letterSpacing: 2, ),
), ),
), ),
SizedBox(height: 20),
], ],
), ),
); );

View File

@ -43,7 +43,7 @@ class KRInviteView extends GetView<KRInviteController> {
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
SizedBox(height: 20.w), // SizedBox(height: 20.w),
// 🟢 // 🟢
Container( Container(
width: double.infinity, width: double.infinity,

View File

@ -113,7 +113,7 @@ class _HIDialogState extends State<HIDialog> {
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(23.r), borderRadius: BorderRadius.circular(23.r),
), ),
minimumSize: Size(85.w, 40.w), minimumSize: Size(85.w, 40),
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
tapTargetSize: MaterialTapTargetSize.shrinkWrap, tapTargetSize: MaterialTapTargetSize.shrinkWrap,
), ),

View File

@ -34,6 +34,9 @@ class KrLocalImage extends StatelessWidget {
colorFilter: color != null colorFilter: color != null
? ColorFilter.mode(color!, BlendMode.srcIn) ? ColorFilter.mode(color!, BlendMode.srcIn)
: null, : null,
// theme: SvgTheme(
// currentColor: color ?? Colors.transparent,
// ),
); );
case ImageType.png: case ImageType.png:
case ImageType.jpg: case ImageType.jpg: