Skip to content

Commit

Permalink
ui and scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
Raviramnani1 committed Aug 22, 2024
1 parent 9a81fee commit 19753a6
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 56 deletions.
3 changes: 2 additions & 1 deletion wallet/lib/model/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:pylons_wallet/pages/home/currency_screen/model/ibc_coins.dart';
import 'package:pylons_wallet/stores/wallet_store.dart';
import '../modules/Pylonstech.pylons.pylons/module/client/cosmos/base/v1beta1/coin.pb.dart';
import '../modules/Pylonstech.pylons.pylons/module/client/pylons/recipe.pb.dart';

enum FreeDrop { yes, no, unselected }

class Events extends Equatable {
Expand All @@ -29,6 +28,7 @@ class Events extends Equatable {
final IBCCoins denom;
String ownerAddress = "";
String owner = "";
bool isStamped = false;

Events({
this.id,
Expand Down Expand Up @@ -65,6 +65,7 @@ class Events extends Equatable {
///*
this.ownerAddress = "",
this.owner = '',
this.isStamped = false,
});

Map<String, dynamic> toJson() {
Expand Down
16 changes: 16 additions & 0 deletions wallet/lib/pages/detailed_asset_view/owner_view_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ class OwnerViewViewModel extends ChangeNotifier {
notifyListeners();
}


Future<void> cancelTrade({required String tradeId, required String address}) async {
final tradeResponse = await repository.cancelTrade(
tradeId: TradeId(Int64(int.parse(tradeId))),
Expand All @@ -517,6 +518,21 @@ class OwnerViewViewModel extends ChangeNotifier {
}
}

Future<void> stampTicket({required bool enabled}) async {
final response = await repository.stampTicket(
cookBookId: CookbookId(events.cookbookID),
recipeId: RecipeId(events.recipeID),
creatorAddress: Address(events.ownerAddress),
);

if (response.isLeft()) {
throw response.getLeft();
}

events.isStamped = true;
notifyListeners();
}

void logEvent() {
repository.logUserJourney(screenName: AnalyticsScreenEvents.ownerView);
}
Expand Down
136 changes: 83 additions & 53 deletions wallet/lib/pages/events/event_qr_code_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:provider/provider.dart';
import 'package:pylons_wallet/components/buttons/custom_paint_button.dart';
import 'package:pylons_wallet/gen/assets.gen.dart';
import 'package:pylons_wallet/generated/locale_keys.g.dart';
import 'package:pylons_wallet/model/event.dart';
import 'package:pylons_wallet/pages/detailed_asset_view/widgets/nft_image_asset.dart';
import 'package:pylons_wallet/utils/constants.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:pylons_wallet/utils/extension.dart';

import '../../providers/account_provider.dart';

class EventQrCodeScreen extends StatefulWidget {
const EventQrCodeScreen({
Expand All @@ -25,67 +29,93 @@ class EventQrCodeScreen extends StatefulWidget {
}

class _EventQrCodeScreenState extends State<EventQrCodeScreen> {
String link = "";
GlobalKey renderObjectKey = GlobalKey();


@override
Widget build(BuildContext context) {
return Material(
color: AppColors.kBlack,
child: Stack(
children: [
NftImageWidget(
url: widget.events.thumbnail,
opacity: 0.5,
),
Padding(
padding: EdgeInsets.only(left: 23.w, top: MediaQuery.of(context).viewPadding.top + 13.h),
child: GestureDetector(
onTap: () async {
Navigator.pop(context);
},
child: SvgPicture.asset(
Assets.images.icons.back,
height: 25.h,
),
void initState() {
super.initState();

createLink();
}

void createLink() {
final wallet = context
.read<AccountProvider>()
.accountPublicInfo;

if (wallet == null) {
return;
}
link = widget.events.recipeID;
}

@override
Widget build(BuildContext context) {
return Material(
color: AppColors.kBlack,
child: Stack(
children: [
NftImageWidget(
url: widget.events.thumbnail,
opacity: 0.5,
),
),
ColoredBox(
color: AppColors.kBlack.withOpacity(0.5),
child: Align(
child: RepaintBoundary(
key: renderObjectKey,
child: QrImageView(
padding: EdgeInsets.zero,
data: jsonEncode(widget.events.toJson()),
size: 200,
dataModuleStyle: const QrDataModuleStyle(color: AppColors.kWhite),
eyeStyle: const QrEyeStyle(eyeShape: QrEyeShape.square, color: AppColors.kWhite),
Padding(
padding: EdgeInsets.only(left: 23.w, top: MediaQuery
.of(context)
.viewPadding
.top + 13.h),
child: GestureDetector(
onTap: () async {
Navigator.pop(context);
},
child: SvgPicture.asset(
Assets.images.icons.back,
height: 25.h,
),
),
),
),
Align(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 20.w),
child: SvgPicture.asset(Assets.images.svg.qrSideBorder),
ColoredBox(
color: AppColors.kBlack.withOpacity(0.5),
child: Align(
child: RepaintBoundary(
key: renderObjectKey,
child: QrImageView(
padding: EdgeInsets.zero,
data: link,
size: 200,
dataModuleStyle: const QrDataModuleStyle(
color: AppColors.kWhite),
eyeStyle: const QrEyeStyle(
eyeShape: QrEyeShape.square, color: AppColors.kWhite),
),
),
),
),
),
Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: EdgeInsets.only(bottom: 30.h),
child: CustomPaintButton(
title: LocaleKeys.done.tr(),
bgColor: AppColors.kWhite.withOpacity(0.3),
width: 280.w,
onPressed: () {
Navigator.pop(context);
},
Align(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 20.w),
child: SvgPicture.asset(Assets.images.svg.qrSideBorder),
),
),
)
],
),
);
Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: EdgeInsets.only(bottom: 30.h),
child: CustomPaintButton(
title: LocaleKeys.done.tr(),
bgColor: AppColors.kWhite.withOpacity(0.3),
width: 280.w,
onPressed: () {
Navigator.pop(context);
},
),
),
)
],
),
);
}
}
}

32 changes: 30 additions & 2 deletions wallet/lib/pages/events/mobile_scanner.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:mobile_scanner/mobile_scanner.dart';

import '../detailed_asset_view/owner_view_view_model.dart';

class MobileQrScanner extends StatefulWidget {
const MobileQrScanner({super.key});

Expand All @@ -9,16 +12,19 @@ class MobileQrScanner extends StatefulWidget {
}

class _MobileQrScannerState extends State<MobileQrScanner> {
OwnerViewViewModel ownerViewViewModel = GetIt.I.get();
Barcode? _barcode;


Widget _buildBarcode(Barcode? value) {
if (value == null) {
return const Text(
'Scan something!',
'Scan Ticket!',
overflow: TextOverflow.fade,
style: TextStyle(color: Colors.white),
);
}
print('QR Code Data: ${value.displayValue}');

return Text(
value.displayValue ?? 'No display value.',
Expand All @@ -31,14 +37,36 @@ class _MobileQrScannerState extends State<MobileQrScanner> {
if (mounted) {
setState(() {
_barcode = barcodes.barcodes.firstOrNull;

if (_barcode != null) {

final String eventId = _barcode!.displayValue ?? '';

// Use the QR code data to stamp the ticket
_stampTicket(eventId);
}
});
}
}

Future<void> stampTicket(String eventId) async {
try {

await ownerViewViewModel.stampTicket(enabled: true);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Ticket $eventId stamped successfully!')),
);
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Failed to stamp ticket: $e')),
);
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Simple scanner')),
appBar: AppBar(title: const Text('Ticket scanner')),
backgroundColor: Colors.black,
body: Stack(
children: [
Expand Down

0 comments on commit 19753a6

Please sign in to comment.