Update: 2026-06-13 15:43:50
This commit is contained in:
@@ -1,67 +0,0 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:mobile_scanner/mobile_scanner.dart';
|
||||
import 'package:siro_rider/constant/colors.dart';
|
||||
import 'package:siro_rider/controller/home/profile/invites_rewards_controller.dart';
|
||||
|
||||
class QRScannerPage extends StatefulWidget {
|
||||
@override
|
||||
_QRScannerPageState createState() => _QRScannerPageState();
|
||||
}
|
||||
|
||||
class _QRScannerPageState extends State<QRScannerPage> {
|
||||
final InvitesRewardsController controller = Get.find<InvitesRewardsController>();
|
||||
bool _isScanned = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.black,
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.black,
|
||||
iconTheme: const IconThemeData(color: Colors.white),
|
||||
title: Text("Scan QR Code".tr, style: const TextStyle(color: Colors.white)),
|
||||
),
|
||||
body: Stack(
|
||||
children: [
|
||||
MobileScanner(
|
||||
onDetect: (capture) {
|
||||
if (_isScanned) return;
|
||||
final List<Barcode> barcodes = capture.barcodes;
|
||||
for (final barcode in barcodes) {
|
||||
if (barcode.rawValue != null) {
|
||||
setState(() => _isScanned = true);
|
||||
Get.back(); // close scanner page
|
||||
controller.processScannedQRCode(barcode.rawValue!);
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
Center(
|
||||
child: Container(
|
||||
width: 250,
|
||||
height: 250,
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: AppColor.primaryColor, width: 3),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
bottom: 50,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: Center(
|
||||
child: Text(
|
||||
"Align QR Code within the frame".tr,
|
||||
style: const TextStyle(color: Colors.white, fontSize: 16),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,6 @@ import '../../../constant/links.dart';
|
||||
import '../../../constant/style.dart';
|
||||
import '../../../controller/home/profile/invit_controller.dart';
|
||||
import '../../../controller/home/profile/invites_rewards_controller.dart';
|
||||
import 'package:qr_flutter/qr_flutter.dart';
|
||||
import 'qr_scanner_page.dart';
|
||||
import '../../../print.dart';
|
||||
|
||||
class ShareAppPage extends StatelessWidget {
|
||||
@@ -48,12 +46,6 @@ class ShareAppPage extends StatelessWidget {
|
||||
},
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
backgroundColor: AppColor.primaryColor,
|
||||
onPressed: () => Get.to(() => QRScannerPage()),
|
||||
icon: const Icon(CupertinoIcons.qrcode_viewfinder, color: Colors.white),
|
||||
label: Text("Scan QR".tr, style: const TextStyle(color: Colors.white)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -61,8 +53,6 @@ class ShareAppPage extends StatelessWidget {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildQRCodeSection(),
|
||||
const SizedBox(height: 20),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
@@ -603,51 +593,7 @@ class ShareAppPage extends StatelessWidget {
|
||||
// );
|
||||
}
|
||||
|
||||
Widget _buildQRCodeSection() {
|
||||
return GetBuilder<InvitesRewardsController>(
|
||||
builder: (rewardsController) {
|
||||
if (rewardsController.isLoading) {
|
||||
return const Center(child: CupertinoActivityIndicator());
|
||||
}
|
||||
String qrData =
|
||||
'https://${AppLink.appDomain}/?inviteCode=${rewardsController.referralCode ?? ''}';
|
||||
|
||||
return Center(
|
||||
child: Column(
|
||||
children: [
|
||||
Text("Your QR Code".tr,
|
||||
style: const TextStyle(
|
||||
fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 10),
|
||||
if (rewardsController.referralCode != null)
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: QrImageView(
|
||||
data: qrData,
|
||||
version: QrVersions.auto,
|
||||
size: 200.0,
|
||||
backgroundColor: Colors.white,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
if (rewardsController.referralCode != null)
|
||||
Text(
|
||||
rewardsController.referralCode!,
|
||||
style: const TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
letterSpacing: 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildUnifiedRewardsList() {
|
||||
return GetBuilder<InvitesRewardsController>(
|
||||
|
||||
@@ -240,53 +240,65 @@ class _SnackContentState extends State<_SnackContent>
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// Internal dispatcher — single source of truth
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
SnackbarController _show(_SnackVariant variant, String message) {
|
||||
// Dismiss any existing snackbar first (no stacking)
|
||||
if (Get.isSnackbarOpen) Get.closeCurrentSnackbar();
|
||||
|
||||
switch (variant.haptic) {
|
||||
case HapticFeedbackType.light:
|
||||
HapticFeedback.lightImpact();
|
||||
case HapticFeedbackType.medium:
|
||||
HapticFeedback.mediumImpact();
|
||||
case HapticFeedbackType.selection:
|
||||
HapticFeedback.selectionClick();
|
||||
SnackbarController? _show(_SnackVariant variant, String message) {
|
||||
// Prevent crash if Navigator or Overlay context is not yet initialized at early startup
|
||||
if (Get.context == null || Get.overlayContext == null) {
|
||||
debugPrint("⚠️ Cannot show snackbar: Overlay/Navigator is not ready yet. Message: $message");
|
||||
return null;
|
||||
}
|
||||
|
||||
return Get.snackbar(
|
||||
'',
|
||||
'',
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.transparent,
|
||||
margin: EdgeInsets.zero,
|
||||
padding: EdgeInsets.zero,
|
||||
duration: const Duration(seconds: 4),
|
||||
animationDuration: const Duration(milliseconds: 380),
|
||||
barBlur: 0,
|
||||
overlayBlur: 0,
|
||||
overlayColor: Colors.transparent,
|
||||
isDismissible: true,
|
||||
dismissDirection: DismissDirection.up,
|
||||
forwardAnimationCurve: Curves.easeOutCubic,
|
||||
reverseAnimationCurve: Curves.easeInCubic,
|
||||
snackStyle: SnackStyle.FLOATING,
|
||||
userInputForm: Form(
|
||||
child: _SnackContent(message: message, variant: variant),
|
||||
),
|
||||
);
|
||||
try {
|
||||
// Dismiss any existing snackbar first (no stacking)
|
||||
if (Get.isSnackbarOpen) Get.closeCurrentSnackbar();
|
||||
|
||||
switch (variant.haptic) {
|
||||
case HapticFeedbackType.light:
|
||||
HapticFeedback.lightImpact();
|
||||
case HapticFeedbackType.medium:
|
||||
HapticFeedback.mediumImpact();
|
||||
case HapticFeedbackType.selection:
|
||||
HapticFeedback.selectionClick();
|
||||
}
|
||||
|
||||
return Get.snackbar(
|
||||
'',
|
||||
'',
|
||||
snackPosition: SnackPosition.TOP,
|
||||
backgroundColor: Colors.transparent,
|
||||
margin: EdgeInsets.zero,
|
||||
padding: EdgeInsets.zero,
|
||||
duration: const Duration(seconds: 4),
|
||||
animationDuration: const Duration(milliseconds: 380),
|
||||
barBlur: 0,
|
||||
overlayBlur: 0,
|
||||
overlayColor: Colors.transparent,
|
||||
isDismissible: true,
|
||||
dismissDirection: DismissDirection.up,
|
||||
forwardAnimationCurve: Curves.easeOutCubic,
|
||||
reverseAnimationCurve: Curves.easeInCubic,
|
||||
snackStyle: SnackStyle.FLOATING,
|
||||
userInputForm: Form(
|
||||
child: _SnackContent(message: message, variant: variant),
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
debugPrint("⚠️ Exception caught showing snackbar: $e");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// Public API — drop-in replacements for the old functions
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
SnackbarController mySnackbarSuccess(String message) =>
|
||||
SnackbarController? mySnackbarSuccess(String message) =>
|
||||
_show(_SnackVariant.success, message);
|
||||
|
||||
SnackbarController mySnackeBarError(String message) =>
|
||||
SnackbarController? mySnackeBarError(String message) =>
|
||||
_show(_SnackVariant.error, message);
|
||||
|
||||
SnackbarController mySnackbarInfo(String message) =>
|
||||
SnackbarController? mySnackbarInfo(String message) =>
|
||||
_show(_SnackVariant.info, message);
|
||||
|
||||
SnackbarController mySnackbarWarning(String message) =>
|
||||
SnackbarController? mySnackbarWarning(String message) =>
|
||||
_show(_SnackVariant.warning, message);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user