Skip to content

Commit

Permalink
feat: qr scanner, events fixation and events class updation for Coins…
Browse files Browse the repository at this point in the history
… input
  • Loading branch information
AhsanRns committed May 28, 2024
1 parent 9c088da commit 48e1cb7
Show file tree
Hide file tree
Showing 8 changed files with 296 additions and 190 deletions.
4 changes: 1 addition & 3 deletions evently/lib/models/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ extension CreateRecipe on Events {
description: description.trim(),
version: kVersion,
coinInputs: [
if (isFreeDrop == FreeDrop.yes)
CoinInput()
else
if (isFreeDrop == FreeDrop.no)
CoinInput(
coins: [Coin(amount: price, denom: symbol)],
)
Expand Down
378 changes: 193 additions & 185 deletions evently/lib/screens/host_view_ticket_preview.dart

Large diffs are not rendered by default.

Binary file added wallet/assets/images/qr_overlay.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions wallet/lib/model/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:convert';
import 'package:equatable/equatable.dart';
import 'package:get_it/get_it.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 }
Expand Down Expand Up @@ -81,6 +82,8 @@ class Events extends Equatable {
factory Events.fromRecipe(Recipe recipe) {
final Map<String, String> map = _extractAttributeValues(recipe.entries.itemOutputs[0].strings);

final denom = recipe.coinInputs.isEmpty ? "" : _extractCoinValue(recipe.coinInputs[0].coins)[kDenom];

final List<PerksModel> listOfPerks = [];
jsonDecode(map[kPerks]!).map((jsonMap) {
listOfPerks.add(PerksModel.fromJson(jsonMap as Map<String, dynamic>));
Expand All @@ -101,6 +104,7 @@ class Events extends Equatable {
listOfPerks: listOfPerks,
cookbookID: map[kCookBookId]!,
recipeID: map[kRecipeId]!,
denom: denom!,
);
}

Expand Down Expand Up @@ -133,6 +137,10 @@ class Events extends Equatable {
return attributeValues;
}

static Map<String, String> _extractCoinValue(List<Coin> coins) {
return {kDenom: coins[0].denom, kPrice: coins[0].amount};
}

@override
List<Object?> get props =>
[eventName, hostName, thumbnail, startDate, endDate, startTime, endTime, location, description, numberOfTickets, price, listOfPerks, isFreeDrops, cookbookID, recipeID, step];
Expand Down Expand Up @@ -177,6 +185,7 @@ const transferFeeAmount = '1';
const kEventlyEvent = "Evently_Event";
const kExtraInfo = "extraInfo";
const costPerBlock = '0';
const kDenom = "kDenom";

class PerksModel {
PerksModel({required this.name, required this.description});
Expand Down
92 changes: 90 additions & 2 deletions wallet/lib/pages/events/event_purchase_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:mobile_scanner/mobile_scanner.dart';
import 'package:pylons_wallet/components/space_widgets.dart';
import 'package:pylons_wallet/model/event.dart';
import 'package:pylons_wallet/utils/constants.dart';
Expand Down Expand Up @@ -30,15 +31,25 @@ class _EventPurchaseViewState extends State<EventPurchaseView> {
}

class EventPassViewContent extends StatelessWidget {
const EventPassViewContent({
EventPassViewContent({
super.key,
required this.events,
});

final Events events;

final MobileScannerController controller = MobileScannerController(
formats: const [BarcodeFormat.qrCode],
);

@override
Widget build(BuildContext context) {
final scanWindow = Rect.fromCenter(
center: MediaQuery.sizeOf(context).center(Offset.zero),
width: 100,
height: 100,
);

return ColoredBox(
color: AppColors.kBlack87,
child: SafeArea(
Expand All @@ -65,14 +76,28 @@ class EventPassViewContent extends StatelessWidget {
),
GestureDetector(
onTap: () {},
child: SvgPicture.asset(shareIcon),
child: Container(),
),
],
),
),
),
body: Column(
children: [
Stack(
children: [
Container(
margin: EdgeInsets.symmetric(horizontal: 20.w),
height: 200.h,
child: MobileScanner(
controller: controller,
onDetect: (_) {
print(_);
},
),
),
],
),
Container(
margin: EdgeInsets.symmetric(horizontal: 20.w),
padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 20.h),
Expand Down Expand Up @@ -202,3 +227,66 @@ class EventPassViewContent extends StatelessWidget {
);
}
}

class ScannerOverlay extends CustomPainter {
const ScannerOverlay({
required this.scanWindow,
this.borderRadius = 12.0,
});

final Rect scanWindow;
final double borderRadius;

@override
void paint(Canvas canvas, Size size) {
// TODO: use `Offset.zero & size` instead of Rect.largest
// we need to pass the size to the custom paint widget
final backgroundPath = Path()..addRect(Rect.largest);

final cutoutPath = Path()
..addRRect(
RRect.fromRectAndCorners(
scanWindow,
topLeft: Radius.circular(borderRadius),
topRight: Radius.circular(borderRadius),
bottomLeft: Radius.circular(borderRadius),
bottomRight: Radius.circular(borderRadius),
),
);

final backgroundPaint = Paint()
..color = Colors.black.withOpacity(0.5)
..style = PaintingStyle.fill
..blendMode = BlendMode.dstOut;

final backgroundWithCutout = Path.combine(
PathOperation.difference,
backgroundPath,
cutoutPath,
);

final borderPaint = Paint()
..color = Colors.white
..style = PaintingStyle.stroke
..strokeWidth = 4.0;

final borderRect = RRect.fromRectAndCorners(
scanWindow,
topLeft: Radius.circular(borderRadius),
topRight: Radius.circular(borderRadius),
bottomLeft: Radius.circular(borderRadius),
bottomRight: Radius.circular(borderRadius),
);

// First, draw the background,
// with a cutout area that is a bit larger than the scan window.
// Finally, draw the scan window itself.
canvas.drawPath(backgroundWithCutout, backgroundPaint);
canvas.drawRRect(borderRect, borderPaint);
}

@override
bool shouldRepaint(ScannerOverlay oldDelegate) {
return scanWindow != oldDelegate.scanWindow || borderRadius != oldDelegate.borderRadius;
}
}
1 change: 1 addition & 0 deletions wallet/lib/pages/events/events_owner_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ class EventPassViewContent extends StatelessWidget {
margin: EdgeInsets.symmetric(horizontal: 20.w),
child: CachedNetworkImage(
fit: BoxFit.fill,
width: double.infinity,
imageUrl: viewModel.events.thumbnail,
errorWidget: (a, b, c) => const Center(
child: Icon(
Expand Down
1 change: 1 addition & 0 deletions wallet/lib/utils/image_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ImageUtil {
static String LIKE_FULL = 'assets/images/icons/like_full.png';
static String SPLASH_SCREEN_BG = "assets/images/splash/Splash_Screen.jpg";
static String CLOSE_ICON = 'assets/images/icons/close.png';
static String QR_OVERLAY = "assets/images/qr_overlay.png";

static List<Image> BG_IMAGES = [
Image.asset(
Expand Down
1 change: 1 addition & 0 deletions wallet/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ dependencies:
provider: ^6.0.3
qr_flutter: ^4.0.0

qr_scanner_overlay: ^0.0.2
retry: ^3.1.2
share_plus: ^6.0.0
shared_preferences: ^2.0.12
Expand Down

0 comments on commit 48e1cb7

Please sign in to comment.