feat: 增加防丢失页面

This commit is contained in:
2026-01-12 06:49:03 -08:00
parent 0474f3c9d9
commit 26f6c10557
16 changed files with 390 additions and 0 deletions
@@ -0,0 +1,11 @@
import 'package:get/get.dart';
import '../controllers/hi_anti_lost_controller.dart';
class HIAntiLostBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut<HIAntiLostController>(
() => HIAntiLostController(),
);
}
}
@@ -0,0 +1,85 @@
import 'dart:typed_data';
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:get/get.dart';
import 'package:gal/gal.dart';
import 'package:kaer_with_panels/app/utils/kr_common_util.dart';
import 'package:url_launcher/url_launcher.dart';
class HIAntiLostController extends GetxController {
final GlobalKey repaintKey = GlobalKey();
Future<void> saveImage() async {
KRCommonUtil.kr_showLoading(message: "正在保存...");
try {
// Check permission
final hasAccess = await Gal.hasAccess();
if (!hasAccess) {
await Gal.requestAccess();
}
// Capture image
RenderRepaintBoundary? boundary =
repaintKey.currentContext?.findRenderObject() as RenderRepaintBoundary?;
if (boundary == null) {
throw Exception("Cannot find boundary");
}
// Check if the boundary needs layout (sometimes Offstage needs a frame)
if (boundary.debugNeedsPaint) {
await Future.delayed(const Duration(milliseconds: 20));
boundary = repaintKey.currentContext?.findRenderObject() as RenderRepaintBoundary?;
}
ui.Image image = await boundary!.toImage(pixelRatio: 3.0);
ByteData? byteData =
await image.toByteData(format: ui.ImageByteFormat.png);
if (byteData != null) {
final Uint8List pngBytes = byteData.buffer.asUint8List();
await Gal.putImageBytes(pngBytes);
KRCommonUtil.kr_showToast("保存成功");
} else {
KRCommonUtil.kr_showToast("生成图片失败");
}
} catch (e) {
debugPrint("Save image error: $e");
if (e is GalException) {
KRCommonUtil.kr_showToast("保存失败: No Permission");
} else {
KRCommonUtil.kr_showToast("保存失败");
}
} finally {
KRCommonUtil.kr_hideLoading();
}
}
void openTwitter() async {
// Try Deep Link first
final Uri appUrl = Uri.parse('twitter://user?screen_name=hifasttech');
final Uri webUrl = Uri.parse('https://x.com/hifasttech');
try {
if (await canLaunchUrl(appUrl)) {
await launchUrl(appUrl);
} else {
// Fallback to web
if (!await launchUrl(webUrl, mode: LaunchMode.externalApplication)) {
KRCommonUtil.kr_showToast("无法打开链接");
}
}
} catch (e) {
debugPrint("Open Twitter error: $e");
// Fallback to web if anything goes wrong
try {
if (!await launchUrl(webUrl, mode: LaunchMode.externalApplication)) {
KRCommonUtil.kr_showToast("无法打开链接");
}
} catch (e) {
KRCommonUtil.kr_showToast("无法打开链接");
}
}
}
}
@@ -0,0 +1,152 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:kaer_with_panels/app/widgets/hi_base_scaffold.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:kaer_with_panels/app/widgets/kr_local_image.dart';
import 'package:kaer_with_panels/app/modules/hi_anti_lost/controllers/hi_anti_lost_controller.dart';
import 'package:kaer_with_panels/app/modules/hi_anti_lost/widgets/hi_anti_lost_share_card.dart';
class HIAntiLostView extends GetView<HIAntiLostController> {
const HIAntiLostView({super.key});
@override
Widget build(BuildContext context) {
return HIBaseScaffold(
showBack: true,
title: null,
topContentAreaHeight: 0,
backgroundColor: Colors.black, // Dark background
child: Stack(
fit: StackFit.expand,
children: [
// 1. Visible Content
Column(
children: [
SizedBox(height: 60.h),
// Card Container
Container(
width: double.infinity,
margin: EdgeInsets.symmetric(horizontal: 40.w),
padding: EdgeInsets.symmetric(vertical: 16.w, horizontal: 0.w),
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.circular(25.r),
border: Border.all(
color: Theme.of(context).primaryColor, width: 4),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'保存二维码,防止失联',
style: TextStyle(
color: Theme.of(context).primaryColor,
fontSize: 24.sp,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 25.h),
Text(
'建议保存Hi快VPN防丢二维码到相册\n永久保障您的互联网自由',
textAlign: TextAlign.center,
style: TextStyle(
color: Theme.of(context).primaryColor,
fontSize: 14.sp,
height: 1.5,
),
),
SizedBox(height: 10.h),
// QR Code
LayoutBuilder(builder: (context, constraints) {
// Use a reasonable size for the QR code
return Container(
width: 124.w,
height: 124.w,
child: QrImageView(
data:
'https://github.com/hi-vpn/hi-client', // Replace with real URL
version: QrVersions.auto,
backgroundColor: Colors.transparent,
eyeStyle: QrEyeStyle(
eyeShape: QrEyeShape.square,
color: Theme.of(context).primaryColor,
),
dataModuleStyle: QrDataModuleStyle(
dataModuleShape: QrDataModuleShape.square,
color: Theme.of(context).primaryColor,
),
// center image
embeddedImage:
const AssetImage('assets/images/kr-logo.png'),
embeddedImageStyle: QrEmbeddedImageStyle(
size: Size(36.w, 36.w),
),
),
);
}),
],
),
),
SizedBox(height: 30.h),
// Save Button
GestureDetector(
onTap: controller.saveImage,
child: Container(
width: double.infinity,
margin: EdgeInsets.symmetric(horizontal: 40.w),
height: 44.h,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
borderRadius: BorderRadius.circular(22.h),
),
child: Text(
'保存到本地',
style: TextStyle(
color: Colors.black,
fontSize: 16.sp,
fontWeight: FontWeight.bold,
),
),
),
),
SizedBox(height: 60.h),
],
),
// 2. Bottom Button (Follow us on X)
Positioned(
bottom: 40.h,
left: 0,
right: 0,
child: Center(
child: GestureDetector(
onTap: controller.openTwitter,
child: KrLocalImage(
imageName: 'followX',
width: 140,
height: 30,
imageType: ImageType
.png, // Assuming it is png as user said followX.png
),
),
),
),
// 3. Invisible Share Card for Generation
Positioned(
left: 10000,
child: RepaintBoundary(
key: controller.repaintKey,
child: const HIAntiLostShareCard(),
),
),
],
),
);
}
}
@@ -0,0 +1,89 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:kaer_with_panels/app/widgets/kr_app_text_style.dart';
class HIAntiLostShareCard extends StatelessWidget {
const HIAntiLostShareCard({super.key});
@override
Widget build(BuildContext context) {
// Fixed width for the generated image, independent of screen size
final double cardWidth = 375.0;
final double cardHeight = 600.0; // Approx height
return Container(
width: cardWidth,
// minimal height or let it expand
padding: EdgeInsets.all(20),
color: Colors.black, // Dark background
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(height: 40),
// Title
Text(
'保存二维码,防止失联',
style: TextStyle(
color: const Color(0xFFCCFF00),
fontSize: 24,
fontWeight: FontWeight.bold,
fontFamily: 'AlibabaPuHuiTi-Medium',
),
),
SizedBox(height: 20),
// Description
Text(
'建议保存Hi快VPN防丢二维码到相册\n永久保障您的互联网自由',
textAlign: TextAlign.center,
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),
),
),
),
SizedBox(height: 40),
// Footer branding
Text(
'HiVPN',
style: TextStyle(
color: Colors.white.withOpacity(0.5),
fontSize: 12,
letterSpacing: 2,
),
),
SizedBox(height: 20),
],
),
);
}
}
@@ -51,6 +51,11 @@ class HIMenuView extends GetView<HIMenuController> implements HasSwipeConfig {
title: '邀请好友',
route: Routes.KR_INVITE,
),
// const MenuItem(
// iconName: 'icon-6',
// title: '软件防丢',
// route: Routes.HI_ANTI_LOST,
// ),
MenuItem(
iconName: 'icon-5',
title: '在线客服',