Skip to content

Commit

Permalink
Merge pull request #32 from BU-Spark/passport
Browse files Browse the repository at this point in the history
Passport
  • Loading branch information
jaimeyfrank authored Dec 16, 2024
2 parents 0416cd2 + ebbd454 commit 752cdf8
Show file tree
Hide file tree
Showing 26 changed files with 209 additions and 162 deletions.
Binary file removed bu_passport/assets/images/passport/empty_sticker.png
Binary file not shown.
Binary file removed bu_passport/assets/images/passport/music_sticker.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified bu_passport/assets/images/stickers/art.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bu_passport/assets/images/stickers/crafting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bu_passport/assets/images/stickers/culinary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bu_passport/assets/images/stickers/dance.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed bu_passport/assets/images/stickers/drama.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bu_passport/assets/images/stickers/film.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bu_passport/assets/images/stickers/free.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bu_passport/assets/images/stickers/literature.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed bu_passport/assets/images/stickers/live.png
Binary file not shown.
Binary file modified bu_passport/assets/images/stickers/music.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bu_passport/assets/images/stickers/theater.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 0 additions & 14 deletions bu_passport/ios/Flutter/Generated.xcconfig

This file was deleted.

13 changes: 0 additions & 13 deletions bu_passport/ios/Flutter/flutter_export_environment.sh

This file was deleted.

22 changes: 17 additions & 5 deletions bu_passport/lib/classes/passport.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:math';

class Passport {
static const int maxStickersPerPage = 6;
static const int maxStickersPerPage = 9;
List<List<Sticker>> pages = [[]];

void addSticker(Sticker sticker) {
Expand All @@ -25,10 +25,16 @@ class Sticker {
String _getImagePathById(int id) {
// Map of id to image paths
const Map<int, String> imagePaths = {
0: 'assets/images/passport/empty_sticker.png',
1: 'assets/images/passport/music_sticker.png',
2: 'assets/images/passport/paintbrush_sticker.png',
3: 'assets/images/passport/theater_sticker.png',
0: 'assets/images/stickers/empty_sticker.png',
1: 'assets/images/stickers/music.png',
2: 'assets/images/stickers/art.png',
3: 'assets/images/stickers/theater.png',
4: 'assets/images/stickers/free.png',
5: 'assets/images/stickers/dance.png',
6: 'assets/images/stickers/crafting.png',
7: 'assets/images/stickers/culinary.png',
8: 'assets/images/stickers/film.png',
9: 'assets/images/stickers/literature.png',
// Add more mappings as needed
};

Expand All @@ -38,10 +44,16 @@ class Sticker {

class StickerRepository {
final List<Sticker> allStickers = [
Sticker(id: 0),
Sticker(id: 1),
Sticker(id: 2),
Sticker(id: 3),
Sticker(id: 4),
Sticker(id: 5),
Sticker(id: 6),
Sticker(id: 7),
Sticker(id: 8),
Sticker(id: 9),
];

Sticker getRandomSticker() {
Expand Down
23 changes: 16 additions & 7 deletions bu_passport/lib/classes/passport_model.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import 'package:flutter/material.dart';
import 'package:bu_passport/classes/passport.dart';

class PassportModel with ChangeNotifier {
Passport passport = Passport();
StickerRepository stickerRepository = StickerRepository();
class PassportModel extends ChangeNotifier {
Passport passport;

void addStickerFromCheckIn() {
Sticker newSticker = stickerRepository.getRandomSticker();
passport.addSticker(newSticker);
notifyListeners();
PassportModel(this.passport);

void addSticker(Sticker sticker, int pageIndex, int position) {
// Check if the sticker is already in the passport
bool stickerExists = passport.pages.any((page) => page.contains(sticker));
if (!stickerExists && pageIndex < passport.pages.length) {
// Add the sticker to the specified page and position
if (passport.pages[pageIndex].length <= position) {
passport.pages[pageIndex].add(sticker);
} else {
passport.pages[pageIndex].insert(position, sticker);
}
notifyListeners();
}
}
}
74 changes: 53 additions & 21 deletions bu_passport/lib/components/passport_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ class PassportBookWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
final passportModel = Provider.of<PassportModel>(context);
final borderColor = Color(0x59F4E2AF).withOpacity(0.8); // Darker version of the color

return Center(
child: Container(
padding: const EdgeInsets.all(8.0),
width: MediaQuery.of(context).size.width * 0.9,
height: MediaQuery.of(context).size.height * 0.5,
height: MediaQuery.of(context).size.height * 0.5, // Increased height
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
Expand All @@ -28,28 +30,50 @@ class PassportBookWidget extends StatelessWidget {
children: [
// Left Page
Expanded(
child: Container(
decoration: ShapeDecoration(
color: Color(0x59F4E2AF),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(9.21),
side: BorderSide(color: Color.fromARGB(88, 165, 151, 111), width: 2.0),
),
),
child: buildPageContent(passportModel.passport.pages.length > 0 ? passportModel.passport.pages[0] : []),
child: DragTarget<Map<String, dynamic>>(
onWillAccept: (data) {
// Check if the sticker is already in the passport
return !passportModel.passport.pages.any((page) => page.contains(data?['sticker']));
},
onAccept: (data) {
passportModel.addSticker(data['sticker'], 0, data['position']);
},
builder: (context, candidateData, rejectedData) {
return Container(
decoration: ShapeDecoration(
color: Color(0x59F4E2AF),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(9.21),
side: BorderSide(color: borderColor, width: 1),
),
),
child: buildPageContent(passportModel.passport.pages.length > 0 ? passportModel.passport.pages[0] : [], 0),
);
},
),
),
// Right Page
Expanded(
child: Container(
decoration: ShapeDecoration(
color: Color(0x59F4E2AF),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(9.21),
side: BorderSide(color: Color.fromARGB(88, 165, 151, 111), width: 2.0),
),
),
child: buildPageContent(passportModel.passport.pages.length > 1 ? passportModel.passport.pages[1] : []),
child: DragTarget<Map<String, dynamic>>(
onWillAccept: (data) {
// Check if the sticker is already in the passport
return !passportModel.passport.pages.any((page) => page.contains(data?['sticker']));
},
onAccept: (data) {
passportModel.addSticker(data['sticker'], 1, data['position']);
},
builder: (context, candidateData, rejectedData) {
return Container(
decoration: ShapeDecoration(
color: Color(0x59F4E2AF),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(9.21),
side: BorderSide(color: borderColor, width: 1),
),
),
child: buildPageContent(passportModel.passport.pages.length > 1 ? passportModel.passport.pages[1] : [], 1),
);
},
),
),
],
Expand All @@ -58,7 +82,7 @@ class PassportBookWidget extends StatelessWidget {
);
}

Widget buildPageContent(List<Sticker> stickers) {
Widget buildPageContent(List<Sticker> stickers, int pageIndex) {
return GridView.builder(
padding: EdgeInsets.all(16),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
Expand All @@ -68,7 +92,15 @@ class PassportBookWidget extends StatelessWidget {
),
itemCount: stickers.length,
itemBuilder: (context, index) {
return Image.asset(stickers[index].imagePath, fit: BoxFit.cover);
return Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(stickers[index].imagePath),
fit: BoxFit.contain,
),
border: Border.all(color: Colors.transparent, width: 0),
),
);
},
);
}
Expand Down
101 changes: 49 additions & 52 deletions bu_passport/lib/components/sticker_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,64 @@ import 'package:flutter/material.dart';
import 'package:bu_passport/classes/passport.dart';

class StickerWidget extends StatelessWidget {
final List<Sticker> stickers;
final List<int> stickerIds;

StickerWidget({required this.stickers});
StickerWidget({required this.stickerIds});

@override
Widget build(BuildContext context) {
return Container(
color: Colors.white,
child: GridView.builder(
padding: EdgeInsets.all(8),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3, // 3x3 grid
crossAxisSpacing: 4,
mainAxisSpacing: 4,
childAspectRatio: 1, // Ensure the grid cells are square
),
itemCount: 9, // Always show 9 items
itemBuilder: (context, index) {
if (index < stickers.length) {
return Draggable<Sticker>(
data: stickers[index],
feedback: Container(
width: 60,
height: 60,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(stickers[index].imagePath),
fit: BoxFit.cover,
),
border: Border.all(color: Colors.transparent, width: 0),
),
),
childWhenDragging: Container(
width: 60,
height: 60,
color: Colors.white,
),
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(stickers[index].imagePath),
fit: BoxFit.cover,
),
border: Border.all(color: Colors.transparent, width: 0),
return GridView.builder(
padding: EdgeInsets.all(8), // Increase padding around the grid
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3, // 3x3 grid
crossAxisSpacing: 16, // Increase space between columns
mainAxisSpacing: 16, // Increase space between rows
childAspectRatio: 1, // Ensure the grid cells are square
),
itemCount: 9, // Always show 9 items
itemBuilder: (context, index) {
if (index < stickerIds.length) {
Sticker sticker = Sticker(id: stickerIds[index]);
return Draggable<Map<String, dynamic>>(
data: {'sticker': sticker, 'position': index},
feedback: Container(
width: 60,
height: 60,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(sticker.imagePath),
fit: BoxFit.contain, // Ensure the entire sticker is visible
),
border: Border.all(color: Colors.transparent, width: 0),
),
);
} else {
return Container(
margin: EdgeInsets.all(16),
),
childWhenDragging: Container(
width: 60,
height: 60,
color: Colors.transparent,
),
child: Container(
decoration: BoxDecoration(
image: const DecorationImage(
image: AssetImage('assets/images/passport/empty_sticker.png'),
fit: BoxFit.cover,
image: DecorationImage(
image: AssetImage(sticker.imagePath),
fit: BoxFit.contain, // Ensure the entire sticker is visible
),
border: Border.all(color: Colors.transparent, width: 0), // Remove grid lines
border: Border.all(color: Colors.transparent, width: 0),
),
),
);
} else {
return Container(
decoration: BoxDecoration(
image: const DecorationImage(
image: AssetImage('assets/images/stickers/empty_sticker.png'),
fit: BoxFit.contain, // Ensure the entire sticker is visible
),
);
}
},
)
border: Border.all(color: Colors.transparent, width: 0),
),
);
}
},
);
}
}
3 changes: 2 additions & 1 deletion bu_passport/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:bu_passport/pages/signup_page.dart';
import 'package:bu_passport/pages/onboarding_page.dart';
import 'package:bu_passport/pages/passport_page.dart';
import 'package:bu_passport/classes/passport_model.dart';
import 'package:bu_passport/classes/passport.dart';

import 'package:timezone/timezone.dart' as tz;
import 'package:timezone/data/latest.dart' as tz;
Expand Down Expand Up @@ -36,7 +37,7 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (_) => PassportModel(),
create: (_) => PassportModel(Passport()),
child: MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
Expand Down
Loading

0 comments on commit 752cdf8

Please sign in to comment.