-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from BU-Spark/passport
Passport -- in progress
- Loading branch information
Showing
18 changed files
with
575 additions
and
102 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import 'dart:math'; | ||
|
||
class Passport { | ||
static const int maxStickersPerPage = 6; | ||
List<List<Sticker>> pages = [[]]; | ||
|
||
void addSticker(Sticker sticker) { | ||
List<Sticker> currentPage = pages.last; | ||
if (currentPage.length >= maxStickersPerPage) { | ||
currentPage = []; | ||
pages.add(currentPage); | ||
} | ||
currentPage.add(sticker); | ||
} | ||
} | ||
|
||
class Sticker { | ||
final int id; | ||
late final String imagePath; | ||
|
||
Sticker({required this.id}) { | ||
imagePath = _getImagePathById(id); | ||
} | ||
|
||
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', | ||
// Add more mappings as needed | ||
}; | ||
|
||
return imagePaths[id] ?? 'assets/images/passport/empty_sticker.png'; | ||
} | ||
} | ||
|
||
class StickerRepository { | ||
final List<Sticker> allStickers = [ | ||
Sticker(id: 1), | ||
Sticker(id: 2), | ||
Sticker(id: 3), | ||
Sticker(id: 4), | ||
]; | ||
|
||
Sticker getRandomSticker() { | ||
if (allStickers.isEmpty) { | ||
throw Exception('No stickers available'); | ||
} | ||
final randomIndex = Random().nextInt(allStickers.length); | ||
return allStickers[randomIndex]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:bu_passport/classes/passport.dart'; | ||
|
||
class PassportModel with ChangeNotifier { | ||
Passport passport = Passport(); | ||
StickerRepository stickerRepository = StickerRepository(); | ||
|
||
void addStickerFromCheckIn() { | ||
Sticker newSticker = stickerRepository.getRandomSticker(); | ||
passport.addSticker(newSticker); | ||
notifyListeners(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:provider/provider.dart'; | ||
import 'package:bu_passport/classes/passport_model.dart'; | ||
import 'package:bu_passport/classes/passport.dart'; | ||
|
||
class PassportBookWidget extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
final passportModel = Provider.of<PassportModel>(context); | ||
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, | ||
decoration: BoxDecoration( | ||
color: Colors.white, | ||
boxShadow: [ | ||
BoxShadow( | ||
color: Color(0xFFF2EFE7).withOpacity(0.2), | ||
spreadRadius: 5, | ||
blurRadius: 7, | ||
offset: Offset(0, 3), | ||
), | ||
], | ||
borderRadius: BorderRadius.circular(10), | ||
), | ||
child: Row( | ||
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] : []), | ||
), | ||
), | ||
// 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] : []), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
|
||
Widget buildPageContent(List<Sticker> stickers) { | ||
return GridView.builder( | ||
padding: EdgeInsets.all(16), | ||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( | ||
crossAxisCount: 3, | ||
crossAxisSpacing: 10, | ||
mainAxisSpacing: 10, | ||
), | ||
itemCount: stickers.length, | ||
itemBuilder: (context, index) { | ||
return Image.asset(stickers[index].imagePath, fit: BoxFit.cover); | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:bu_passport/classes/passport.dart'; | ||
|
||
class StickerWidget extends StatelessWidget { | ||
final List<Sticker> stickers; | ||
|
||
StickerWidget({required this.stickers}); | ||
|
||
@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), | ||
), | ||
), | ||
); | ||
} else { | ||
return Container( | ||
margin: EdgeInsets.all(16), | ||
decoration: BoxDecoration( | ||
image: const DecorationImage( | ||
image: AssetImage('assets/images/passport/empty_sticker.png'), | ||
fit: BoxFit.cover, | ||
), | ||
border: Border.all(color: Colors.transparent, width: 0), // Remove grid lines | ||
), | ||
); | ||
} | ||
}, | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.